Skip to content

Commit

Permalink
Merge pull request #529 from NekohimeMusou/polyglot-fix
Browse files Browse the repository at this point in the history
Fix: Monster tokens throw Polyglot errors
  • Loading branch information
Rughalt authored Sep 9, 2024
2 parents 8fbbad6 + 9eb4310 commit c1a81bb
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
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

0 comments on commit c1a81bb

Please sign in to comment.