mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-07-22 10:29:54 +02:00
Changed from updatig the existing token to deleting it and making a new one
This commit is contained in:
parent
a96809f9de
commit
47ac1ec094
2 changed files with 50 additions and 12 deletions
|
|
@ -62,21 +62,58 @@ export default class DHSummonField extends fields.SchemaField {
|
|||
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;
|
||||
|
||||
await token.update(
|
||||
{
|
||||
...actor.prototypeToken.toJSON(),
|
||||
actorLink: false,
|
||||
actorId: actor.id,
|
||||
const createdTokens = await canvas.scene.createEmbeddedDocuments(
|
||||
'Token', [{
|
||||
...actor.prototypeToken.toObject(),
|
||||
actorId: actor.id,
|
||||
x: token.x,
|
||||
y: token.y,
|
||||
width: tokenSize,
|
||||
height: tokenSize
|
||||
},
|
||||
{ diff: false, recursive: false, noHook: true }
|
||||
height: tokenSize,
|
||||
level: game.user.viewedLevel,
|
||||
elevation: token.elevation
|
||||
}],
|
||||
{ controlObject: true, parent: canvas.scene }
|
||||
);
|
||||
const createdToken = createdTokens[0];
|
||||
|
||||
/* Swap out previous combatant for a new one if applicable */
|
||||
if (token.combatant) {
|
||||
token.combatant.update({ actorId: actor.id, img: actor.prototypeToken.texture.src });
|
||||
const combatantWasSpotlighted =
|
||||
game.combat.turn === game.combat.combatants.contents
|
||||
.sort(game.combat._sortCombatants)
|
||||
.map(x => x.id)
|
||||
.indexOf(token.combatant.id);
|
||||
|
||||
/* Batching combatants update to avoid jumpy UI with multiple rerenders */
|
||||
const batch = [
|
||||
{
|
||||
action: 'create',
|
||||
documentName: 'Combatant',
|
||||
data: [{
|
||||
tokenId: createdToken.id,
|
||||
sceneId: createdToken.parent.id,
|
||||
actorId: createdToken.actorId,
|
||||
hidden: createdToken.hidden
|
||||
}],
|
||||
parent: game.combat
|
||||
},
|
||||
{
|
||||
action: 'delete',
|
||||
documentName: 'Combatant',
|
||||
ids: [token.combatant.id],
|
||||
parent: game.combat
|
||||
}
|
||||
];
|
||||
await foundry.documents.modifyBatch(batch);
|
||||
|
||||
if (combatantWasSpotlighted) {
|
||||
ui.combat.setCombatantSpotlight(createdToken.combatant.id);
|
||||
}
|
||||
}
|
||||
|
||||
await token.delete();
|
||||
|
||||
const marks = { hitPoints: 0, stress: 0 };
|
||||
if (!this.transform.resourceRefresh.hitPoints) {
|
||||
marks.hitPoints = Math.min(
|
||||
|
|
@ -91,7 +128,7 @@ export default class DHSummonField extends fields.SchemaField {
|
|||
);
|
||||
}
|
||||
if (marks.hitPoints || marks.stress) {
|
||||
token.actor.update({
|
||||
createdToken.actor.update({
|
||||
'system.resources': {
|
||||
hitPoints: { value: marks.hitPoints },
|
||||
stress: { value: marks.stress }
|
||||
|
|
@ -101,6 +138,6 @@ export default class DHSummonField extends fields.SchemaField {
|
|||
|
||||
const prevPosition = { ...this.actor.sheet.position };
|
||||
this.actor.sheet.close();
|
||||
token.actor.sheet.render({ force: true, position: prevPosition });
|
||||
createdToken.actor.sheet.render({ force: true, position: prevPosition });
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue