Fixed the way an actor is lightweight and re-construct from chat message.

This commit is contained in:
Vlyan
2022-03-29 19:47:30 +02:00
parent 5aed5629bf
commit 36997c099e
4 changed files with 90 additions and 45 deletions

View File

@@ -29,6 +29,7 @@ module.exports = {
},
globals: {
foundry: "readonly",
TokenDocument: "readonly",
AudioHelper: "readonly",
Collection: "readonly",
Hooks: "readonly",

View File

@@ -4,6 +4,8 @@ Date format : day/month/year
## 1.7.1 - ??/04/2022 - Spring fixes
- PC/NPC sheet :
- Fixed technique with a skill set, in a title, now open the DicePicker as intended.
- Roll/DP/RnK :
- Fixed the way an actor is lightweight and re-construct from chat message. This fix minions npc sync with multiple token (missing context).
## 1.7.0 - 28/03/2022 - Strife, DiceRoller for Techniques & Npc Generator
- NPC Sheet :

View File

@@ -370,13 +370,25 @@ export class RollL5r5e extends Roll {
roll.data = foundry.utils.duplicate(data.data);
roll.l5r5e = foundry.utils.duplicate(data.l5r5e);
// get real Actor object
// Get real Actor object
if (data.l5r5e.actor) {
if (data.l5r5e.actor instanceof game.l5r5e.ActorL5r5e) {
// duplicate break the object, relink it
// Duplicate break the object, relink it
roll.l5r5e.actor = data.l5r5e.actor;
} else {
// only id, get the object
} else if (data.l5r5e.actor.uuid) {
// Only uuid, get the object
let actor;
let tmpItem = game.l5r5e.HelpersL5r5e.fromUuidNoPack(data.l5r5e.actor.uuid);
if (tmpItem instanceof Actor) {
actor = tmpItem;
} else if (tmpItem instanceof TokenDocument) {
actor = tmpItem.actor;
}
if (actor) {
roll.l5r5e.actor = actor;
}
} else if (data.l5r5e.actor.id) {
// Compat old chat message : only id
const actor = game.actors.get(data.l5r5e.actor.id);
if (actor) {
roll.l5r5e.actor = actor;
@@ -398,9 +410,9 @@ export class RollL5r5e extends Roll {
json.l5r5e = foundry.utils.duplicate(this.l5r5e);
// lightweight the Actor
if (json.l5r5e.actor) {
if (json.l5r5e.actor && this.l5r5e.actor?.uuid) {
json.l5r5e.actor = {
id: json.l5r5e.actor._id, // method "id" not exist in json, need to use "_id" here
uuid: this.l5r5e.actor.uuid,
};
}

View File

@@ -109,6 +109,36 @@ export class HelpersL5r5e {
return CONFIG.l5r5e.roles.map((e) => game.i18n.localize(`l5r5e.roles.${e}`));
}
/**
* Retrieve a Document by its Universally Unique Identifier (uuid).
* Exactly the same as fromUuid but without Compendium as it need async.
* @param {string} uuid The uuid of the Document to retrieve
* @return {Document|null}
*/
static fromUuidNoPack(uuid) {
let parts = uuid.split(".");
let doc;
if (parts[0] === "Compendium") {
// Compendium Documents need asynchronous
return null;
} else {
// World Documents
const [docName, docId] = parts.slice(0, 2);
parts = parts.slice(2);
const collection = CONFIG[docName].collection.instance;
doc = collection.get(docId);
}
// Embedded Documents
while (doc && parts.length > 1) {
const [embeddedName, embeddedId] = parts.slice(0, 2);
doc = doc.getEmbeddedDocument(embeddedName, embeddedId);
parts = parts.slice(2);
}
return doc || null;
}
/**
* Return the target object on a drag n drop event, or null if not found
* @param {DragEvent} event