From e77d1358d5f02157f9f849ba1630be63d4604b66 Mon Sep 17 00:00:00 2001 From: Vlyan Date: Tue, 8 Jun 2021 12:59:06 +0200 Subject: [PATCH] Change token name too ;) --- CHANGELOG.md | 5 +++-- system/scripts/actor.js | 20 ++++++++++++-------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2965b31..cb5d48d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,9 +2,10 @@ ## 1.3.1 - Scholar helper - Added a Journal Compendium for School Curriculums. -- Fix for the "bought_at_rank" value when an Item was on dropped on a sheet. -- Fix for issue #23 "Token image does not save". +- Added Curriculums in description for Titles. - Added English Compendiums for Field of Victory (thanks to mdosantos !). +- Fix for the "bought_at_rank" does not change according to the PC rank value when an Item is drop on a sheet. +- Fix for issue #23 "Token image does not save". Now we reflect the change on the token name/image only if it's a linked actor and if the token/sheet have the same values. ## 1.3.0 - Foundry 0.8 Compatibility __! Be certain to carefully back up any critical user data before installing this update !__ diff --git a/system/scripts/actor.js b/system/scripts/actor.js index 1ced2b4..a385c7c 100644 --- a/system/scripts/actor.js +++ b/system/scripts/actor.js @@ -69,14 +69,18 @@ export class ActorL5r5e extends Actor { data["_id"] = this.id; } - // Update the token image if the sheet image changed, but only if they are the same and linked to actor - if ( - data.img && - this.data.img === this.data.token.img && - this.data.img !== data.img && - (data.token?.actorLink || (data.token?.actorLink === undefined && this.data.token.actorLink)) - ) { - data["token.img"] = data.img; + // Only on linked Actor + if (data.token?.actorLink || (data.token?.actorLink === undefined && this.data.token.actorLink)) { + // Update the token name/image if the sheet name/image changed, but only if they was previously the same + ["name", "img"].forEach((fieldName) => { + if ( + data[fieldName] && + this.data[fieldName] === this.data.token[fieldName] && + this.data[fieldName] !== data[fieldName] + ) { + data["token." + fieldName] = data[fieldName]; + } + }); } // Now using updateDocuments