From 8f993adb4773940e24cfe76d35f67f84fc15d7ad Mon Sep 17 00:00:00 2001 From: Oliver-Akins Date: Mon, 2 Jun 2025 19:26:43 -0600 Subject: [PATCH 1/3] Finish removing the Range bucket type that was accidentally still able to be created --- module/Apps/TableCreator.mjs | 2 +- module/hooks/init.mjs | 6 +-- module/hooks/ready.mjs | 4 +- module/utils/buckets.mjs | 1 - module/utils/databases/Database.mjs | 31 ++++++++++++-- .../Apps/TableManager/buckets/range.hbs | 42 ------------------- 6 files changed, 34 insertions(+), 52 deletions(-) delete mode 100644 public/templates/Apps/TableManager/buckets/range.hbs diff --git a/module/Apps/TableCreator.mjs b/module/Apps/TableCreator.mjs index 9619af2..1422fbf 100644 --- a/module/Apps/TableCreator.mjs +++ b/module/Apps/TableCreator.mjs @@ -75,7 +75,7 @@ export class TableCreator extends HandlebarsApplicationMixin(ApplicationV2) { if (this._name.startsWith(`Dice`)) { ctx.createButtonDisabled = !this._name.match(diceNamespacePattern); ctx.typeDisabled = true; - ctx.type = BucketTypes.RANGE; + ctx.type = BucketTypes.NUMBER; this.#diceNamespaceAlert ??= ui.notifications.info( `Tables in the "Dice" namespace must be formatted as "Dice/dX" where X is the number of sides on the die and are restricted to be ranges 1 to X.`, { permanent: true }, diff --git a/module/hooks/init.mjs b/module/hooks/init.mjs index e7e1d2d..ef5bd74 100644 --- a/module/hooks/init.mjs +++ b/module/hooks/init.mjs @@ -47,9 +47,9 @@ Hooks.on(`init`, () => { manager: TableManager, }; - if (import.meta.env.DEV) { - CONFIG.stats.db = MemoryDatabase; - }; + // if (import.meta.env.DEV) { + // CONFIG.stats.db = MemoryDatabase; + // }; game.modules.get(__ID__).api = api; if (game.settings.get(__ID__, `globalAPI`)) { diff --git a/module/hooks/ready.mjs b/module/hooks/ready.mjs index 33fe483..025ed1b 100644 --- a/module/hooks/ready.mjs +++ b/module/hooks/ready.mjs @@ -29,10 +29,10 @@ Hooks.on(`ready`, () => { ); // Fire and forget - CONFIG.stats.db.migrateData(notif) + CONFIG.stats.db.migrateData(lastVersion, notif) .then(() => { game.settings.set(__ID__, `lastVersion`, __VERSION__); - setTimeout(() => ui.notifications.remove(notif), 500); + setTimeout(() => ui.notifications.remove(notif), 5_000); }); } else { ui.notifications.error( diff --git a/module/utils/buckets.mjs b/module/utils/buckets.mjs index 7082df1..53c78f6 100644 --- a/module/utils/buckets.mjs +++ b/module/utils/buckets.mjs @@ -6,7 +6,6 @@ const { StringField, NumberField } = foundry.data.fields; export const BucketTypes = { STRING: `string`, NUMBER: `number`, - RANGE: `range`, }; /** diff --git a/module/utils/databases/Database.mjs b/module/utils/databases/Database.mjs index acca180..92aa108 100644 --- a/module/utils/databases/Database.mjs +++ b/module/utils/databases/Database.mjs @@ -28,7 +28,7 @@ Default Subtables: tables that are parents to other tables. */ -const { deleteProperty, diffObject, expandObject, mergeObject } = foundry.utils; +const { deleteProperty, diffObject, expandObject, isNewerVersion, mergeObject } = foundry.utils; /** * The generic Database implementation, any subclasses should implement all of @@ -275,7 +275,11 @@ export class Database { * @returns {boolean} */ static requiresMigrationFrom(lastVersion) { - return foundry.utils.isNewerVersion(__VERSION__, lastVersion); + Logger.table({ + lastVersion, + newer: isNewerVersion(__VERSION__, lastVersion), + }); + return isNewerVersion(__VERSION__, lastVersion); }; /** @@ -289,7 +293,28 @@ export class Database { * @param {Notification} notif The progress bar notification used for * user feedback while performing migrations. */ - static async migrateData(lastVersion, notif) {}; + static async migrateData(lastVersion, notif) { + const totalSteps = 1; + Logger.debug(lastVersion); + + /* + This migration is for going up to 1.0.3, getting rid of any tables that have + a bucket type of range, since those were not supported within the initial + release, but could still accidentally be created by users. + */ + if (isNewerVersion(`1.0.3`, lastVersion)) { + Logger.log(`Migrating up to the v1.0.3 data structure`); + const tables = game.settings.get(__ID__, `tables`); + for (const table of Object.values(tables)) { + if (table.buckets.type !== `range`) { continue }; + table.buckets.type = BucketTypes.NUMBER; + table.buckets.showEmptyBuckets = true; + }; + await game.settings.set(__ID__, `tables`, tables); + notif.update({ pct: notif.pct + (1 / totalSteps) }); + }; + + }; }; /* eslint-enable no-unused-vars */ diff --git a/public/templates/Apps/TableManager/buckets/range.hbs b/public/templates/Apps/TableManager/buckets/range.hbs deleted file mode 100644 index 0462a0e..0000000 --- a/public/templates/Apps/TableManager/buckets/range.hbs +++ /dev/null @@ -1,42 +0,0 @@ -
- - -
-
- - -
-
- - -

- The size of the step between values within the range. -

-
From 4b11d12f8137e75889a26c1a6f0ce8bdd1ca40dc Mon Sep 17 00:00:00 2001 From: Oliver-Akins Date: Wed, 4 Jun 2025 21:18:10 -0600 Subject: [PATCH 2/3] Undo code that got commented out --- module/hooks/init.mjs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/module/hooks/init.mjs b/module/hooks/init.mjs index ef5bd74..e7e1d2d 100644 --- a/module/hooks/init.mjs +++ b/module/hooks/init.mjs @@ -47,9 +47,9 @@ Hooks.on(`init`, () => { manager: TableManager, }; - // if (import.meta.env.DEV) { - // CONFIG.stats.db = MemoryDatabase; - // }; + if (import.meta.env.DEV) { + CONFIG.stats.db = MemoryDatabase; + }; game.modules.get(__ID__).api = api; if (game.settings.get(__ID__, `globalAPI`)) { From 00d63d42d1f702895702a453255b4bfc7f36fa89 Mon Sep 17 00:00:00 2001 From: Oliver-Akins Date: Wed, 4 Jun 2025 21:20:54 -0600 Subject: [PATCH 3/3] Remove stray logs --- module/utils/databases/Database.mjs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/module/utils/databases/Database.mjs b/module/utils/databases/Database.mjs index 92aa108..9cd4be1 100644 --- a/module/utils/databases/Database.mjs +++ b/module/utils/databases/Database.mjs @@ -275,10 +275,6 @@ export class Database { * @returns {boolean} */ static requiresMigrationFrom(lastVersion) { - Logger.table({ - lastVersion, - newer: isNewerVersion(__VERSION__, lastVersion), - }); return isNewerVersion(__VERSION__, lastVersion); }; @@ -295,7 +291,6 @@ export class Database { */ static async migrateData(lastVersion, notif) { const totalSteps = 1; - Logger.debug(lastVersion); /* This migration is for going up to 1.0.3, getting rid of any tables that have