Merge pull request #35 from Oliver-Akins/fix/bucket-type-list

Prevent erroneous range bucket types from existing
This commit is contained in:
Oliver 2025-06-04 21:21:20 -06:00 committed by GitHub
commit c90ee7a6d3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 26 additions and 49 deletions

View file

@ -75,7 +75,7 @@ export class TableCreator extends HandlebarsApplicationMixin(ApplicationV2) {
if (this._name.startsWith(`Dice`)) { if (this._name.startsWith(`Dice`)) {
ctx.createButtonDisabled = !this._name.match(diceNamespacePattern); ctx.createButtonDisabled = !this._name.match(diceNamespacePattern);
ctx.typeDisabled = true; ctx.typeDisabled = true;
ctx.type = BucketTypes.RANGE; ctx.type = BucketTypes.NUMBER;
this.#diceNamespaceAlert ??= ui.notifications.info( 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.`, `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 }, { permanent: true },

View file

@ -29,10 +29,10 @@ Hooks.on(`ready`, () => {
); );
// Fire and forget // Fire and forget
CONFIG.stats.db.migrateData(notif) CONFIG.stats.db.migrateData(lastVersion, notif)
.then(() => { .then(() => {
game.settings.set(__ID__, `lastVersion`, __VERSION__); game.settings.set(__ID__, `lastVersion`, __VERSION__);
setTimeout(() => ui.notifications.remove(notif), 500); setTimeout(() => ui.notifications.remove(notif), 5_000);
}); });
} else { } else {
ui.notifications.error( ui.notifications.error(

View file

@ -6,7 +6,6 @@ const { StringField, NumberField } = foundry.data.fields;
export const BucketTypes = { export const BucketTypes = {
STRING: `string`, STRING: `string`,
NUMBER: `number`, NUMBER: `number`,
RANGE: `range`,
}; };
/** /**

View file

@ -28,7 +28,7 @@ Default Subtables:
tables that are parents to other tables. 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 * The generic Database implementation, any subclasses should implement all of
@ -275,7 +275,7 @@ export class Database {
* @returns {boolean} * @returns {boolean}
*/ */
static requiresMigrationFrom(lastVersion) { 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 * @param {Notification} notif The progress bar notification used for
* user feedback while performing migrations. * 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 */ /* eslint-enable no-unused-vars */

View file

@ -1,42 +0,0 @@
<div class="input-group">
<label for="{{meta.idp}}-min">
Minimum
</label>
<input
id="{{meta.idp}}-min"
type="number"
name="buckets.min"
value="{{ buckets.min }}"
required
{{disabled buckets.locked}}
>
</div>
<div class="input-group">
<label for="{{meta.idp}}-max">
Maximum
</label>
<input
id="{{meta.idp}}-max"
type="number"
name="buckets.max"
value="{{ buckets.max }}"
required
{{disabled buckets.locked}}
>
</div>
<div class="input-group">
<label for="{{meta.idp}}-step">
Step
</label>
<input
id="{{meta.idp}}-step"
type="number"
name="buckets.step"
value="{{ buckets.step }}"
required
{{disabled buckets.locked}}
>
<p class="hint">
The size of the step between values within the range.
</p>
</div>