From b7720522228c7809921aa0702cbb50262f9b5547 Mon Sep 17 00:00:00 2001 From: Blair Date: Fri, 11 Oct 2024 08:49:07 +1000 Subject: [PATCH] v2.7.15 - Added a button in the settings to more easily re-prompt for a module's automatic importer. - This functionality always existed via a macro. This button just makes it easier to find. --- CHANGELOG.md | 4 ++ languages/en.json | 8 ++++ languages/fr.json | 8 ++++ module.json | 2 +- scripts/constants.js | 5 +++ scripts/reset-import-prompts.js | 59 ++++++++++++++++++++++++++++++ scripts/scene-packer.js | 10 +++++ templates/reset-import-prompts.hbs | 33 +++++++++++++++++ 8 files changed, 128 insertions(+), 1 deletion(-) create mode 100644 scripts/reset-import-prompts.js create mode 100644 templates/reset-import-prompts.hbs diff --git a/CHANGELOG.md b/CHANGELOG.md index 4a7fc49..2cf1a45 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## v2.7.15 +- Added a button in the settings to more easily re-prompt for a module's automatic importer. + - This functionality always existed via a macro. This button just makes it easier to find. + ## v2.7.14 - Allow the Moulinette importer tool to correctly handle zip files manually created on Windows. - Updated [fflate](https://101arrowz.github.io/fflate/) to v0.8.2. diff --git a/languages/en.json b/languages/en.json index 8e7de34..09c67e4 100644 --- a/languages/en.json +++ b/languages/en.json @@ -552,6 +552,14 @@ "all-lowercase": "All assets are already lowercase.", "list-assets": "The following assets will be converted to lowercase:", "confirm": "Are you sure you want to convert these assets to lowercase?" + }, + "reset-prompts": { + "name": "Reset import prompts", + "label": "Choose module", + "hint": "Use this to reset the prompt you received when you first installed a supported module. Handy if you accidentally closed it the first time.", + "nothing": "There are no modules installed that are registered with Scene Packer, so there are no welcome prompts that can be reset. Make sure the module is enabled.", + "refresh-text": "Resetting the prompt will automatically reload your world.", + "select-module-label": "Select module:" } } } diff --git a/languages/fr.json b/languages/fr.json index 3c60790..1e0fa7f 100644 --- a/languages/fr.json +++ b/languages/fr.json @@ -552,6 +552,14 @@ "title": "Vérifier que des assets existent et les convertir en minuscules", "description": "Cet outil vérifiera que tous les assets de votre monde existent et convertira leurs références en minuscules. Il énumérera d'abord toutes les références des assets qu'il convertira, puis vous demandera de confirmer.", "nothing": "Aucun asset n'a été trouvé dans votre monde." + }, + "reset-prompts": { + "name": "Réinitialiser les invites d'importation", + "label": "Choisir le module", + "hint": "Utilisez ceci pour réinitialiser l'invite que vous avez reçue lors de la première installation d'un module pris en charge. Pratique si vous l'avez accidentellement fermée la première fois.", + "nothing": "Il n'y a aucun module installé qui soit enregistré avec Scene Packer, donc il n'y a pas d'invites de bienvenue à réinitialiser. Assurez-vous que le module est activé.", + "refresh-text": "La réinitialisation de l'invite rechargera automatiquement votre monde.", + "select-module-label": "Sélectionner le module:" } } } diff --git a/module.json b/module.json index 4f61276..662196a 100644 --- a/module.json +++ b/module.json @@ -3,7 +3,7 @@ "name": "scene-packer", "title": "Library: Scene Packer", "description": "A module to assist with Scene and Adventure packing and unpacking.", - "version": "2.7.14", + "version": "2.7.15", "library": "true", "manifestPlusVersion": "1.2.0", "minimumCoreVersion": "0.8.6", diff --git a/scripts/constants.js b/scripts/constants.js index 8075a94..68c0006 100644 --- a/scripts/constants.js +++ b/scripts/constants.js @@ -189,6 +189,11 @@ export const CONSTANTS = Object.freeze({ */ SETTING_IMPORTED_VERSION: 'imported', + /** + * The setting key for triggering the ResetImportPrompt class. + */ + SETTING_RESET_IMPORT_PROMPT: 'resetImportPrompt', + /** * The setting key for the version of the system that last had a Scene Packer migration run against it. */ diff --git a/scripts/reset-import-prompts.js b/scripts/reset-import-prompts.js new file mode 100644 index 0000000..391f402 --- /dev/null +++ b/scripts/reset-import-prompts.js @@ -0,0 +1,59 @@ +import { CONSTANTS } from './constants.js'; + +export default class ResetImportPrompts extends FormApplication { + + /** @inheritDoc */ + static get defaultOptions() { + return foundry.utils.mergeObject(super.defaultOptions, { + title: game.i18n.localize('SCENE-PACKER.reset-prompts.name'), + id: 'scene-packer-reset-import-prompts', + template: 'modules/scene-packer/templates/reset-import-prompts.hbs', + classes: ['scene-packer'], + }); + } + + /** + * @returns {Object|Promise} + */ + getData(options = {}) { + const instances = Object.values(ScenePacker.instances).map(m => { + const module = game.modules.get(m.moduleName); + return { + id: module?.id || m.moduleName, + name: (module?.title ?? module?.data?.title) || m.adventureName, + } + }); + return { + instances, + }; + } + + /** @inheritdoc */ + async _updateObject(event, formData) { + const moduleName = formData['module-name']; + if (!moduleName) { + return; + } + + await Promise.allSettled([ + game.settings.set(moduleName, CONSTANTS.SETTING_IMPORTED_VERSION, '0.0.0'), + game.settings.set(moduleName, CONSTANTS.SETTING_PROMPTED, '0.0.0'), + game.settings.set(moduleName, CONSTANTS.SETTING_SHOW_WELCOME_PROMPTS, true), + game.settings.set(moduleName, CONSTANTS.SETTING_SYSTEM_MIGRATION_VERSION, '0.0.0'), + ]); + + if (canvas?.scene?.getFlag(moduleName, CONSTANTS.SETTING_IMPORTED_VERSION)) { + await canvas.scene.setFlag(moduleName, CONSTANTS.SETTING_IMPORTED_VERSION, '0.0.0') + } + + setTimeout(() => { + window.location.reload(); + }, 200); + } + + /** @inheritdoc */ + activateListeners(html) { + super.activateListeners(html); + html.find('button[name="close"]').click(this.close.bind(this)); + } +} diff --git a/scripts/scene-packer.js b/scripts/scene-packer.js index faecaf1..d0ece87 100644 --- a/scripts/scene-packer.js +++ b/scripts/scene-packer.js @@ -10,6 +10,7 @@ import MoulinetteImporter from './export-import/moulinette-importer.js'; import Report from './report.js'; import WelcomeJournal from './welcome-journal.js'; import ZipImporter from './export-import/zip-importer.js'; +import ResetImportPrompts from './reset-import-prompts.js'; /** * Tracks the initialised instances of Scene Packer and also exposes some methods to globalThis. @@ -5861,6 +5862,15 @@ Hooks.once('setup', () => { await instance.ProcessScene(readyCanvas.scene); }); + game.settings.registerMenu(CONSTANTS.MODULE_NAME, CONSTANTS.SETTING_RESET_IMPORT_PROMPT, { + name: game.i18n.localize('SCENE-PACKER.reset-prompts.name'), + label: game.i18n.localize('SCENE-PACKER.reset-prompts.label'), + hint: game.i18n.localize('SCENE-PACKER.reset-prompts.hint'), + icon: "fas fa-arrows-rotate", + type: ResetImportPrompts, + restricted: true, + }) + game.settings.register(CONSTANTS.MODULE_NAME, CONSTANTS.SETTING_ENABLE_CONTEXT_MENU, { name: game.i18n.localize('SCENE-PACKER.settings.context-menu.name'), hint: game.i18n.localize('SCENE-PACKER.settings.context-menu.hint'), diff --git a/templates/reset-import-prompts.hbs b/templates/reset-import-prompts.hbs new file mode 100644 index 0000000..36fabce --- /dev/null +++ b/templates/reset-import-prompts.hbs @@ -0,0 +1,33 @@ +
+
+

{{localize 'SCENE-PACKER.reset-prompts.name'}}

+

{{localize 'SCENE-PACKER.reset-prompts.hint'}}

+
+ {{#if instances.length}} +
+ +
+

{{localize 'SCENE-PACKER.reset-prompts.refresh-text'}}

+ {{else}} +

{{localize 'SCENE-PACKER.reset-prompts.nothing'}}

+ {{/if}} +
+ + +