Added ability to transform linked actors

This commit is contained in:
WBHarry 2026-06-29 22:32:00 +02:00
parent 8c6a470d84
commit 7dec34f835
2 changed files with 29 additions and 13 deletions

View file

@ -84,6 +84,7 @@
"transformActorMissing": "The assigned actor to transform into does not exist. It was probably deleted or moved in/out of a compendium", "transformActorMissing": "The assigned actor to transform into does not exist. It was probably deleted or moved in/out of a compendium",
"canvasError": "There is no active scene.", "canvasError": "There is no active scene.",
"prototypeError": "You can only use a transform action from a Token", "prototypeError": "You can only use a transform action from a Token",
"linkedSelectedError": "To transform a linked actor there either needs to be only a single token of it on the canvas, or you need to left-click select only one of them.",
"actorLinkError": "You cannot transform a token with Actor Link set to true" "actorLinkError": "You cannot transform a token with Actor Link set to true"
} }
}, },

View file

@ -37,12 +37,21 @@ export default class DHSummonField extends fields.SchemaField {
return false; return false;
} }
if (this.actor.prototypeToken.actorLink) { const activeTokens = this.actor.getActiveTokens().map(x => x.document);
ui.notifications.warn(game.i18n.localize('DAGGERHEART.ACTIONS.TYPES.transform.actorLinkError')); const controlledMatchingTokens = canvas.tokens.controlled
return false; .filter(x => x.actor && x.actor.uuid === this.actor.uuid)
} .map(x => x.document);
const token = this.actor.token ?? (
activeTokens.length === 1 ? activeTokens[0] :
(controlledMatchingTokens.length === 1 ? controlledMatchingTokens[0] : null)
);
if (!this.actor.token) { if (!this.actor.token && !token) {
ui.notifications.warn(game.i18n.localize('DAGGERHEART.ACTIONS.TYPES.transform.linkedSelectedError'));
return false;
}
if (!token) {
ui.notifications.warn(game.i18n.localize('DAGGERHEART.ACTIONS.TYPES.transform.prototypeError')); ui.notifications.warn(game.i18n.localize('DAGGERHEART.ACTIONS.TYPES.transform.prototypeError'));
return false; return false;
} }
@ -51,30 +60,36 @@ export default class DHSummonField extends fields.SchemaField {
const tokenSizes = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Homebrew).tokenSizes; const tokenSizes = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Homebrew).tokenSizes;
const tokenSize = actor?.system.metadata.usesSize ? tokenSizes[actor.system.size] : actor.prototypeToken.width; const tokenSize = actor?.system.metadata.usesSize ? tokenSizes[actor.system.size] : actor.prototypeToken.width;
await this.actor.token.update( await token.update(
{ ...actor.prototypeToken.toJSON(), actorId: actor.id, width: tokenSize, height: tokenSize }, {
...actor.prototypeToken.toJSON(),
actorLink: false,
actorId: actor.id,
width: tokenSize,
height: tokenSize
},
{ diff: false, recursive: false, noHook: true } { diff: false, recursive: false, noHook: true }
); );
if (this.actor.token.combatant) { if (token.combatant) {
this.actor.token.combatant.update({ actorId: actor.id, img: actor.prototypeToken.texture.src }); token.combatant.update({ actorId: actor.id, img: actor.prototypeToken.texture.src });
} }
const marks = { hitPoints: 0, stress: 0 }; const marks = { hitPoints: 0, stress: 0 };
if (!this.transform.resourceRefresh.hitPoints) { if (!this.transform.resourceRefresh.hitPoints) {
marks.hitPoints = Math.min( marks.hitPoints = Math.min(
this.actor.system.resources.hitPoints.value, this.actor.system.resources.hitPoints.value,
this.actor.token.actor.system.resources.hitPoints.max - 1 token.actor.system.resources.hitPoints.max - 1
); );
} }
if (!this.transform.resourceRefresh.stress) { if (!this.transform.resourceRefresh.stress) {
marks.stress = Math.min( marks.stress = Math.min(
this.actor.system.resources.stress.value, this.actor.system.resources.stress.value,
this.actor.token.actor.system.resources.stress.max - 1 token.actor.system.resources.stress.max - 1
); );
} }
if (marks.hitPoints || marks.stress) { if (marks.hitPoints || marks.stress) {
this.actor.token.actor.update({ token.actor.update({
'system.resources': { 'system.resources': {
hitPoints: { value: marks.hitPoints }, hitPoints: { value: marks.hitPoints },
stress: { value: marks.stress } stress: { value: marks.stress }
@ -84,7 +99,7 @@ export default class DHSummonField extends fields.SchemaField {
const prevPosition = { ...this.actor.sheet.position }; const prevPosition = { ...this.actor.sheet.position };
this.actor.sheet.close(); this.actor.sheet.close();
this.actor.token.actor.sheet.render({ force: true, position: prevPosition }); token.actor.sheet.render({ force: true, position: prevPosition });
} }
/* Check for any available instances of the actor present in the world, or create a world actor based on compendium */ /* Check for any available instances of the actor present in the world, or create a world actor based on compendium */