Fixed setActor in DP introduced in last commit
This commit is contained in:
@@ -6,22 +6,22 @@ export class ActorL5r5e extends Actor {
|
|||||||
* Create a new entity using provided input data
|
* Create a new entity using provided input data
|
||||||
* @override
|
* @override
|
||||||
*/
|
*/
|
||||||
static async create(data, options = {}) {
|
static async create(docData, options = {}) {
|
||||||
// if (!Object.keys(data).includes("type")) {
|
// if (!Object.keys(docData).includes("type")) {
|
||||||
// data.type = "character";
|
// data.type = "character";
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// Replace default image
|
// Replace default image
|
||||||
if (data.img === undefined) {
|
if (docData.img === undefined) {
|
||||||
data.img = `${CONFIG.l5r5e.paths.assets}icons/actors/${data.type}.svg`;
|
docData.img = `${CONFIG.l5r5e.paths.assets}icons/actors/${docData.type}.svg`;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Some tweak on actors prototypeToken
|
// Some tweak on actors prototypeToken
|
||||||
data.prototypeToken = data.prototypeToken || {};
|
docData.prototypeToken = docData.prototypeToken || {};
|
||||||
switch (data.type) {
|
switch (docData.type) {
|
||||||
case "character":
|
case "character":
|
||||||
foundry.utils.mergeObject(
|
foundry.utils.mergeObject(
|
||||||
data.prototypeToken,
|
docData.prototypeToken,
|
||||||
{
|
{
|
||||||
// vision: true,
|
// vision: true,
|
||||||
// dimSight: 30,
|
// dimSight: 30,
|
||||||
@@ -41,7 +41,7 @@ export class ActorL5r5e extends Actor {
|
|||||||
|
|
||||||
case "npc":
|
case "npc":
|
||||||
foundry.utils.mergeObject(
|
foundry.utils.mergeObject(
|
||||||
data.prototypeToken,
|
docData.prototypeToken,
|
||||||
{
|
{
|
||||||
actorLink: true,
|
actorLink: true,
|
||||||
disposition: 0, // neutral
|
disposition: 0, // neutral
|
||||||
@@ -58,7 +58,7 @@ export class ActorL5r5e extends Actor {
|
|||||||
|
|
||||||
case "army":
|
case "army":
|
||||||
foundry.utils.mergeObject(
|
foundry.utils.mergeObject(
|
||||||
data.prototypeToken,
|
docData.prototypeToken,
|
||||||
{
|
{
|
||||||
actorLink: true,
|
actorLink: true,
|
||||||
disposition: 0, // neutral
|
disposition: 0, // neutral
|
||||||
@@ -73,20 +73,20 @@ export class ActorL5r5e extends Actor {
|
|||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
await super.create(data, options);
|
await super.create(docData, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Entity-specific actions that should occur when the Entity is updated
|
* Entity-specific actions that should occur when the Entity is updated
|
||||||
* @override
|
* @override
|
||||||
*/
|
*/
|
||||||
async update(data = {}, context = {}) {
|
async update(docData = {}, context = {}) {
|
||||||
// fix foundry v0.8.8 (config token=object, update=flat array)
|
// fix foundry v0.8.8 (config token=object, update=flat array)
|
||||||
data = foundry.utils.flattenObject(data);
|
docData = foundry.utils.flattenObject(docData);
|
||||||
|
|
||||||
// Need a _id
|
// Need a _id
|
||||||
if (!data["_id"]) {
|
if (!docData["_id"]) {
|
||||||
data["_id"] = this.id;
|
docData["_id"] = this.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Context informations (needed for unlinked token update)
|
// Context informations (needed for unlinked token update)
|
||||||
@@ -94,31 +94,31 @@ export class ActorL5r5e extends Actor {
|
|||||||
context.pack = this.pack;
|
context.pack = this.pack;
|
||||||
|
|
||||||
// NPC switch between types : Linked actor for Adversary, unlinked for Minion
|
// NPC switch between types : Linked actor for Adversary, unlinked for Minion
|
||||||
if (!!data["system.type"] && this.type === "npc" && data["system.type"] !== this.system.type) {
|
if (!!docData["system.type"] && this.type === "npc" && docData["system.type"] !== this.system.type) {
|
||||||
data["prototypeToken.actorLink"] = data["system.type"] === "adversary";
|
docData["prototypeToken.actorLink"] = docData["system.type"] === "adversary";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only on linked Actor
|
// Only on linked Actor
|
||||||
if (
|
if (
|
||||||
!!data["prototypeToken.actorLink"] ||
|
!!docData["prototypeToken.actorLink"] ||
|
||||||
(data["prototypeToken.actorLink"] === undefined && this.prototypeToken?.actorLink)
|
(docData["prototypeToken.actorLink"] === undefined && this.prototypeToken?.actorLink)
|
||||||
) {
|
) {
|
||||||
// Update the token name/image if the sheet name/image changed, but only if
|
// Update the token name/image if the sheet name/image changed, but only if
|
||||||
// they was previously the same, and token img was not set in same time
|
// they was previously the same, and token img was not set in same time
|
||||||
Object.entries({ name: "name", img: "texture.src" }).forEach(([dataProp, TknProp]) => {
|
Object.entries({ name: "name", img: "texture.src" }).forEach(([dataProp, TknProp]) => {
|
||||||
if (
|
if (
|
||||||
data[dataProp] &&
|
docData[dataProp] &&
|
||||||
!data["prototypeToken." + TknProp] &&
|
!docData["prototypeToken." + TknProp] &&
|
||||||
this[dataProp] === foundry.utils.getProperty(this.prototypeToken, TknProp) &&
|
this[dataProp] === foundry.utils.getProperty(this.prototypeToken, TknProp) &&
|
||||||
this[dataProp] !== data[dataProp]
|
this[dataProp] !== docData[dataProp]
|
||||||
) {
|
) {
|
||||||
data["prototypeToken." + TknProp] = data[dataProp];
|
docData["prototypeToken." + TknProp] = docData[dataProp];
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now using updateDocuments
|
// Now using updateDocuments
|
||||||
return Actor.updateDocuments([data], context).then(() => {
|
return Actor.updateDocuments([docData], context).then(() => {
|
||||||
// Notify the "Gm Monitor" if this actor is watched
|
// Notify the "Gm Monitor" if this actor is watched
|
||||||
if (game.settings.get("l5r5e", "gm-monitor-actors").find((e) => e === this.id)) {
|
if (game.settings.get("l5r5e", "gm-monitor-actors").find((e) => e === this.id)) {
|
||||||
game.l5r5e.HelpersL5r5e.refreshLocalAndSocket("l5r5e-gm-monitor");
|
game.l5r5e.HelpersL5r5e.refreshLocalAndSocket("l5r5e-gm-monitor");
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ export class DicePickerDialog extends FormApplication {
|
|||||||
* Options :
|
* Options :
|
||||||
* actor A instance of actor (game.user.character, canvas.tokens.controlled[0].actor, ...)
|
* actor A instance of actor (game.user.character, canvas.tokens.controlled[0].actor, ...)
|
||||||
* actorId string (AbYgKrNwWeAxa9jT)
|
* actorId string (AbYgKrNwWeAxa9jT)
|
||||||
* actorName string (Isawa Aki) Careful this is case sensitive
|
* actorName string (Isawa Aki) Careful this is case-sensitive
|
||||||
* ringId string (fire)
|
* ringId string (fire)
|
||||||
* skillId string (design)
|
* skillId string (design)
|
||||||
* skillCatId string (artisan)
|
* skillCatId string (artisan)
|
||||||
@@ -193,7 +193,7 @@ export class DicePickerDialog extends FormApplication {
|
|||||||
if (!actor) {
|
if (!actor) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (actor instanceof Actor || !actor.isOwner) {
|
if (!(actor instanceof Actor) || !actor.isOwner) {
|
||||||
console.warn("L5R5E | DP | Actor rejected : Not a valid Actor instance or permission was denied", actor);
|
console.warn("L5R5E | DP | Actor rejected : Not a valid Actor instance or permission was denied", actor);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user