Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Monster tokens throw Polyglot errors #529

Merged
merged 2 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/module/actor/data-model-monster.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,30 @@ export default class OseDataModelMonster extends foundry.abstract.TypeDataModel
);
}

/**
* @inheritdoc
*/
static migrateData(source) {
this.#migrateMonsterLanguages(source);

return super.migrateData(source);
}

/**
* Use an empty array for system.languages.value
* in order to suppress Polyglot errors.
*
* @param {OseDataModelMonster} source - Source data to migrate
*/
static #migrateMonsterLanguages(source) {
const languages = source.languages ?? {};

// If languages.value isn't an iterable, use an empty array
if (typeof languages?.value?.[Symbol.iterator] !== "function") {
languages.value = [];
}
}

// @todo define schema options; stuff like min/max values and so on.
static defineSchema() {
const { StringField, NumberField, BooleanField, ObjectField, SchemaField } =
Expand Down
6 changes: 3 additions & 3 deletions template.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@
"initiative": {
"value": 0,
"mod": 0
},
"languages": {
"value": []
}
},
"spellcaster": {
Expand Down Expand Up @@ -131,9 +134,6 @@
},
"encumbrance": {
"max": 1600
},
"languages": {
"value": []
}
},
"monster": {
Expand Down