From e18419575cc756f7df64a098c31a4f254e4635ba Mon Sep 17 00:00:00 2001 From: Mike Bloy Date: Tue, 27 May 2025 23:08:01 -0500 Subject: [PATCH] add settings registration --- src/lang/en.json | 9 ++++++++- src/module.json | 23 +++++++++-------------- src/module/api.js | 2 +- src/module/globals.js | 18 ++++++++++++++++++ src/module/powers/basePowers.js | 30 ++++++++++++++++++++++++++++++ src/module/settings.js | 32 +++++++++++++++++++++++++++----- 6 files changed, 93 insertions(+), 21 deletions(-) diff --git a/src/lang/en.json b/src/lang/en.json index 9e26dfe..883bccb 100644 --- a/src/lang/en.json +++ b/src/lang/en.json @@ -1 +1,8 @@ -{} \ No newline at end of file +{ + "mbhelpers.settings.morphablesCompendiumName": "Morphables Compendium", + "mbhelpers.settings.morphablesCompendiumHint": "UUID of a Compendium that holds all the morphables.", + "mbhelpers.settings.summonablesCompendiumName": "Summonables Compendium", + "mbhelpers.settings.summonablesCompendiumHint": "UUID of a Compendium that holds all the summonables.", + "mbhelpers.settings.summonablesJournalName": "Summonables Journal Entry", + "mbhelpers.settings.summonablesJournalHint": "UUID of a journal entry that lists the costs of all summonables. There should be a page named identically to every available spell name" +} diff --git a/src/module.json b/src/module.json index e68dcf1..45bffac 100644 --- a/src/module.json +++ b/src/module.json @@ -9,10 +9,10 @@ } ], "url": "https://git.bloy.org/foundryvtt/swade-mb-helpers", - "version": "3.1.5", + "version": "4.0.0", "compatibility": { - "minimum": "12", - "verified": "12" + "minimum": "13", + "verified": "13" }, "esmodules": [ "module/swade-mb-helpers.js" @@ -110,17 +110,17 @@ "compatibility": {} }, { - "id": "portal-lib", + "id": "tcal", + "type": "module", + "compatibility": {} + }, + { + "id": "sequencer", "type": "module", "compatibility": {} } ], "recommends": [ - { - "id": "token-variants", - "type": "module", - "compatibility": {} - }, { "id": "torch", "type": "module", @@ -135,11 +135,6 @@ "id": "visual-active-effects", "type": "module", "compatibility": {} - }, - { - "id": "sequencer", - "type": "module", - "compatibility": {} } ] }, diff --git a/src/module/api.js b/src/module/api.js index 3cff21f..73a9dde 100644 --- a/src/module/api.js +++ b/src/module/api.js @@ -1,4 +1,4 @@ -import { log, moduleHelpers } from './globals.js'; +import { log, moduleHelpers, settingKeys } from './globals.js'; import { requestFearRollFromTokens, requestRollFromTokens } from './helpers.js'; import { powers, powerEffectsMenu } from './powers/powers.js'; import { setSummonCosts } from './powers/summonSupport.js'; diff --git a/src/module/globals.js b/src/module/globals.js index 928b5c5..44dce9e 100644 --- a/src/module/globals.js +++ b/src/module/globals.js @@ -1,5 +1,11 @@ export const moduleName = 'swade-mb-helpers'; +export const settingKeys = { + summonablesCompendium: 'summonablesCompendium', + summonablesJournal: 'summonablesJournal', + morphablesCompendium: 'morphablesCompendium', +}; + export function log(...args) { console.log('SWADE MB HELPERS |', ...args); } @@ -11,6 +17,18 @@ export class moduleHelpers { return moduleHelpers._socket; } + static getSetting(key) { + return game.settings.get(moduleName, key); + } + + static async setSetting(key, value) { + return game.settings.get(moduleName, key, value); + } + + static async registerSetting(key, metadata) { + return game.settings.register(moduleName, key, metadata); + } + static get rulesVersion() { if (game.modules.get('swpf-core-rules')?.active) { return 'swpf'; diff --git a/src/module/powers/basePowers.js b/src/module/powers/basePowers.js index 0b9e7e7..9a9cae7 100644 --- a/src/module/powers/basePowers.js +++ b/src/module/powers/basePowers.js @@ -25,6 +25,8 @@ const MAINTAIN_ICONS = [ 'icons/magic/symbols/triangle-glowing-green.webp', ]; +const { ApplicationV2, HandlebarsApplicationMixin } = foundry.applications.api; + function _hashCode(str) { let hash = 0; if (str.length === 0) { @@ -38,6 +40,34 @@ function _hashCode(str) { return Math.abs(hash); } +export class PowerFormApplicationV2 extends HandlebarsApplicationMixin(ApplicationV2) { + constructor(powerEffect) { + super(); + const name = powerEffect.name.replaceAll(/[^a-zA-Z]/g, ''); + this.options.id = `${this.options.id}${name}`; + this.powerEffect = powerEffect; + } + + static DEFAULT_OPTIONS = { + id: ['mbSwadePowerEffectsApplicationV2'], + form: { + handler: PowerFormApplicationV2.#onSubmit, + closeOnSubmit: true, + }, + tag: 'form', + position: { + width: 400, + height: 'auto', + }, + window: { + icon: 'fas fa-gear', + title: 'mbSwade.powerEffectsForm.title', + }, + }; + + static #onSubmit(event, form, formData) {} +} + export class PowerFormApplication extends FormApplication { constructor(powerEffect) { super(); diff --git a/src/module/settings.js b/src/module/settings.js index 3c3b590..2a0d007 100644 --- a/src/module/settings.js +++ b/src/module/settings.js @@ -1,7 +1,29 @@ -// SPDX-FileCopyrightText: 2022 Johannes Loher -// -// SPDX-License-Identifier: MIT - +import { moduleName, moduleHelpers, settingKeys } from './globals.js'; export function registerSettings() { - // Register any custom module settings here + moduleHelpers.registerSetting(settingKeys.summonablesJournal, { + name: 'mbhelpers.settings.summonablesJournalName', + hint: 'mbhelpers.settings.summonablesJournalHint', + scope: 'world', + config: true, + requiresReload: false, + type: String, + }); + + moduleHelpers.registerSetting(settingKeys.summonablesCompendium, { + name: 'mbhelpers.settings.summonablesCompendiumName', + hint: 'mbhelpers.settings.summonablesCompendiumHint', + scope: 'world', + config: true, + requiresReload: false, + type: String, + }); + + moduleHelpers.registerSetting(settingKeys.morphablesCompendium, { + name: 'mbhelpers.settings.morphablesCompendiumName', + hint: 'mbhelpers.settings.morphablesCompendiumHint', + scope: 'world', + config: true, + requiresReload: false, + type: String, + }); }