mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-07-24 03:19:55 +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,20 +62,57 @@ 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 token.update(
|
const createdTokens = await canvas.scene.createEmbeddedDocuments(
|
||||||
{
|
'Token', [{
|
||||||
...actor.prototypeToken.toJSON(),
|
...actor.prototypeToken.toObject(),
|
||||||
actorLink: false,
|
|
||||||
actorId: actor.id,
|
actorId: actor.id,
|
||||||
|
x: token.x,
|
||||||
|
y: token.y,
|
||||||
width: tokenSize,
|
width: tokenSize,
|
||||||
height: tokenSize
|
height: tokenSize,
|
||||||
},
|
level: game.user.viewedLevel,
|
||||||
{ diff: false, recursive: false, noHook: true }
|
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) {
|
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 };
|
const marks = { hitPoints: 0, stress: 0 };
|
||||||
if (!this.transform.resourceRefresh.hitPoints) {
|
if (!this.transform.resourceRefresh.hitPoints) {
|
||||||
|
|
@ -91,7 +128,7 @@ export default class DHSummonField extends fields.SchemaField {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (marks.hitPoints || marks.stress) {
|
if (marks.hitPoints || marks.stress) {
|
||||||
token.actor.update({
|
createdToken.actor.update({
|
||||||
'system.resources': {
|
'system.resources': {
|
||||||
hitPoints: { value: marks.hitPoints },
|
hitPoints: { value: marks.hitPoints },
|
||||||
stress: { value: marks.stress }
|
stress: { value: marks.stress }
|
||||||
|
|
@ -101,6 +138,6 @@ 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();
|
||||||
token.actor.sheet.render({ force: true, position: prevPosition });
|
createdToken.actor.sheet.render({ force: true, position: prevPosition });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,8 @@ export default class DHToken extends CONFIG.Token.documentClass {
|
||||||
tokens.filter(x => x.actor).map(x => x.actor)
|
tokens.filter(x => x.actor).map(x => x.actor)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
super.createCombatants(tokens, combat ?? {});
|
|
||||||
|
await super.createCombatants(tokens, combat ?? {});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**@inheritdoc */
|
/**@inheritdoc */
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue