Skip to content

Commit 2ad2f46

Browse files
Move declarations from datamaps.mjs to their logical places.
1 parent 098573f commit 2ad2f46

File tree

4 files changed

+65
-82
lines changed

4 files changed

+65
-82
lines changed

extensions/datamaps.mjs

Lines changed: 0 additions & 38 deletions
This file was deleted.

extensions/includes/format.mjs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -273,14 +273,14 @@ function generateWrite(multiple) {
273273
};
274274
}
275275

276-
export const DATAMAPS_SINGLE /** @type {ScriptedMapFormat} */ = {
277-
extension: 'mw-datamaps',
278-
name: 'DataMaps (single wiki)',
279-
write: generateWrite(false)
280-
};
281-
282-
export const DATAMAPS_MULTIPLE /** @type {ScriptedMapFormat} */ = {
276+
tiled.registerMapFormat('dataMaps', {
283277
extension: 'mw-datamaps',
284278
name: 'DataMaps (all wikis)',
285279
write: generateWrite(true)
286-
};
280+
});
281+
282+
tiled.registerMapFormat('dataMap', {
283+
extension: 'mw-datamaps',
284+
name: 'DataMaps (single wiki)',
285+
write: generateWrite(false)
286+
});

extensions/includes/popup.mjs

Lines changed: 46 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -179,38 +179,53 @@ const /** @type {Record<MapObjectShape, MarkerPopupHandler|undefined>} */ handle
179179
[MapObject.Text]: undefined,
180180
};
181181

182-
/**
183-
* Called when the currently selected objects on the map change.
184-
* @param {MapObject[]} objects Currently selected map objects
185-
*/
186-
export default function selectedObjectsChanged(objects) {
187-
if (objects.length !== 1) {
188-
return;
182+
const enablePopup = tiled.registerAction('WikiMarkerPopup', () => {});
183+
enablePopup.checkable = true;
184+
enablePopup.checked = true;
185+
enablePopup.iconVisibleInMenu = false;
186+
enablePopup.text = 'Enable marker popup';
187+
enablePopup.shortcut = 'Ctrl+Shift+M';
188+
189+
tiled.extendMenu('Edit', [
190+
{
191+
action: 'WikiMarkerPopup'
189192
}
190-
const object = objects[0];
191-
const handlerFunc = handlers[object.shape];
192-
tiled.log(JSON.stringify(handlerFunc));
193-
if (typeof handlerFunc !== 'function') {
194-
tiled.alert('This object cannot be converted to DataMaps on the wiki!');
193+
]);
194+
195+
tiled.assetOpened.connect(asset => {
196+
if (!asset.isTileMap) {
195197
return;
196198
}
197-
const dialog = new Dialog('Editing map marker');
198-
dialog.minimumWidth = 600;
199-
const languageNames = getLanguageNames();
200-
const languageSelect = dialog.addComboBox('Wiki language:', languageNames);
201-
languageSelect.visible = languageNames.length > 1;
202-
dialog.addNewRow();
203-
const handler = handlerFunc(object, dialog);
204-
languageSelect.currentIndexChanged.connect(index => {
205-
handler.updateLanguage(selectLanguage(index));
206-
});
207-
dialog.addButton('OK').clicked.connect(() => {
208-
handler.performChanges(selectLanguage(languageSelect.currentIndex));
209-
dialog.done(Dialog.Accepted);
199+
const tileMap = /** @type {TileMap} */ (asset);
200+
tileMap.selectedObjectsChanged.connect(() => {
201+
if (!enablePopup.checked || tileMap.selectedObjects.length !== 1) {
202+
return;
203+
}
204+
const object = tileMap.selectedObjects[0];
205+
const handlerFunc = handlers[object.shape];
206+
tiled.log(JSON.stringify(handlerFunc));
207+
if (typeof handlerFunc !== 'function') {
208+
tiled.alert('This object cannot be converted to DataMaps on the wiki!');
209+
return;
210+
}
211+
const dialog = new Dialog('Editing map marker');
212+
dialog.minimumWidth = 600;
213+
const languageNames = getLanguageNames();
214+
const languageSelect = dialog.addComboBox('Wiki language:', languageNames);
215+
languageSelect.visible = languageNames.length > 1;
216+
dialog.addNewRow();
217+
const handler = handlerFunc(object, dialog);
218+
languageSelect.currentIndexChanged.connect(index => {
219+
handler.updateLanguage(selectLanguage(index));
220+
});
221+
dialog.addButton('OK').clicked.connect(() => {
222+
handler.performChanges(selectLanguage(languageSelect.currentIndex));
223+
dialog.done(Dialog.Accepted);
224+
});
225+
dialog.addButton('Cancel').clicked.connect(() => {
226+
dialog.done(Dialog.Rejected);
227+
});
228+
handler.updateLanguage(selectLanguage(languageSelect.currentIndex));
229+
dialog.show();
210230
});
211-
dialog.addButton('Cancel').clicked.connect(() => {
212-
dialog.done(Dialog.Rejected);
213-
});
214-
handler.updateLanguage(selectLanguage(languageSelect.currentIndex));
215-
dialog.show();
216-
}
231+
});

extensions/includes/publish.mjs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -189,10 +189,7 @@ function handlePublishError(error) {
189189
tiled.log(`Error details: ${error.message || error}`);
190190
}
191191

192-
/**
193-
* Publishes the current map to the wiki.
194-
*/
195-
export default function run() {
192+
const publishAction = tiled.registerAction('PublishToWiki', () => {
196193
if (!tiled.activeAsset || !tiled.activeAsset.isTileMap) {
197194
tiled.alert('Please open the map you want to publish first.');
198195
return;
@@ -205,4 +202,13 @@ export default function run() {
205202
addToPromise(publishMap(token, summary, map, language), language))
206203
.then(([response, language]) => handlePublishSuccess(response, language))
207204
.catch(handlePublishError);
208-
}
205+
});
206+
publishAction.text = 'Publish to wiki';
207+
publishAction.icon = 'wiki.svg';
208+
publishAction.shortcut = 'Ctrl+Shift+U';
209+
210+
tiled.extendMenu('File', [
211+
{
212+
action: 'PublishToWiki'
213+
}
214+
]);

0 commit comments

Comments
 (0)