Better demeanor autocomplete handling

This commit is contained in:
Vlyan
2022-03-27 11:52:38 +02:00
parent dbbb2d4f00
commit d9ba4569c7
3 changed files with 38 additions and 1 deletions

View File

@@ -70,7 +70,7 @@ export class NpcSheetL5r5e extends BaseCharacterSheetL5r5e {
html,
"data.attitude",
CONFIG.l5r5e.demeanors.map((e) => {
let modifiers = [];
const modifiers = [];
Object.entries(e.mod).forEach(([k, v]) => {
modifiers.push(`${game.i18n.localize(`l5r5e.rings.${k}`)} ${v}`);
});
@@ -78,4 +78,27 @@ export class NpcSheetL5r5e extends BaseCharacterSheetL5r5e {
})
);
}
/**
* Update the actor.
* @param event
* @param formData
*/
_updateObject(event, formData) {
// Redo the demeanor to set the rings data
if (formData["autoCompleteListName"] === "data.attitude" && formData["autoCompleteListSelectedIndex"] >= 0) {
const demeanor = CONFIG.l5r5e.demeanors[formData["autoCompleteListSelectedIndex"]] || null;
if (demeanor) {
formData["data.attitude"] = game.i18n.localize(`l5r5e.demeanor.${demeanor.id}`);
CONFIG.l5r5e.stances.forEach((ring) => {
formData[`data.rings_affinities.${ring}`] = 0;
});
Object.entries(demeanor.mod).forEach(([k, v]) => {
formData[`data.rings_affinities.${k}`] = v;
});
}
}
return super._updateObject(event, formData);
}
}