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/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..9cd4be1 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,7 @@ export class Database { * @returns {boolean} */ static requiresMigrationFrom(lastVersion) { - return foundry.utils.isNewerVersion(__VERSION__, lastVersion); + return isNewerVersion(__VERSION__, lastVersion); }; /** @@ -289,7 +289,27 @@ 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; + + /* + 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. -

-