Fix js error when Advancement is not in a actor

This commit is contained in:
Vlyan
2021-01-22 15:08:26 +01:00
parent 2cdce21407
commit a958e17278

View File

@@ -95,12 +95,22 @@ export class AdvancementSheetL5r5e extends ItemSheetL5r5e {
* @private * @private
*/ */
async _updateChoice(oldChoice, newChoice) { async _updateChoice(oldChoice, newChoice) {
let skillCatId = null;
const actor = duplicate(this.actor.data.data);
let xp_used = this.object.data.data.xp_used; let xp_used = this.object.data.data.xp_used;
let name = this.object.data.name; let name = this.object.data.name;
let img = this.object.data.img; let img = this.object.data.img;
// Modify image to reflect choice
if (newChoice.ring) {
img = `systems/l5r5e/assets/icons/rings/${newChoice.ring}.svg`;
} else if (newChoice.skill) {
img = `systems/l5r5e/assets/dices/default/skill_blank.svg`;
}
// Object embed in actor ?
if (this.actor) {
const actor = duplicate(this.actor.data.data);
let skillCatId = null;
// Old choices // Old choices
if (oldChoice.ring) { if (oldChoice.ring) {
actor.rings[oldChoice.ring] = Math.max(1, actor.rings[oldChoice.ring] - 1); actor.rings[oldChoice.ring] = Math.max(1, actor.rings[oldChoice.ring] - 1);
@@ -117,7 +127,6 @@ export class AdvancementSheetL5r5e extends ItemSheetL5r5e {
name = name =
game.i18n.localize(`l5r5e.rings.${newChoice.ring}`) + game.i18n.localize(`l5r5e.rings.${newChoice.ring}`) +
` +1 (${actor.rings[newChoice.ring] - 1} -> ${actor.rings[newChoice.ring]})`; ` +1 (${actor.rings[newChoice.ring] - 1} -> ${actor.rings[newChoice.ring]})`;
img = `systems/l5r5e/assets/icons/rings/${newChoice.ring}.svg`;
} }
if (newChoice.skill) { if (newChoice.skill) {
skillCatId = CONFIG.l5r5e.skills.get(newChoice.skill); skillCatId = CONFIG.l5r5e.skills.get(newChoice.skill);
@@ -128,13 +137,13 @@ export class AdvancementSheetL5r5e extends ItemSheetL5r5e {
` +1 (${actor.skills[skillCatId][newChoice.skill] - 1} -> ${ ` +1 (${actor.skills[skillCatId][newChoice.skill] - 1} -> ${
actor.skills[skillCatId][newChoice.skill] actor.skills[skillCatId][newChoice.skill]
})`; })`;
img = `systems/l5r5e/assets/dices/default/skill_blank.svg`;
} }
// Update Actor // Update Actor
await this.actor.update({ await this.actor.update({
data: diffObject(this.actor.data.data, actor), data: diffObject(this.actor.data.data, actor),
}); });
}
// Update object // Update object
await this.object.update({ await this.object.update({