add settings registration

This commit is contained in:
Mike Bloy 2025-05-27 23:08:01 -05:00
parent ec4f3e6c63
commit e18419575c
6 changed files with 93 additions and 21 deletions

View File

@ -1 +1,8 @@
{}
{
"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"
}

View File

@ -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": {}
}
]
},

View File

@ -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';

View File

@ -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';

View File

@ -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();

View File

@ -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,
});
}