Added a clowncar HUD button for companions (#1574)

This commit is contained in:
WBHarry 2026-01-24 20:23:03 +01:00 committed by GitHub
parent d43a4994ad
commit 2757a97244
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 42 additions and 14 deletions

View file

@ -488,7 +488,9 @@
"tokenHUD": { "tokenHUD": {
"genericEffects": "Foundry Effects", "genericEffects": "Foundry Effects",
"depositPartyTokens": "Deposit Party Tokens", "depositPartyTokens": "Deposit Party Tokens",
"retrievePartyTokens": "Retrieve Party Tokens" "retrievePartyTokens": "Retrieve Party Tokens",
"depositCompanionTokens": "Deposit Companion Token",
"retrieveCompanionTokens": "Retrieve Companion Token"
} }
}, },
"ImageSelect": { "ImageSelect": {

View file

@ -5,7 +5,8 @@ export default class DHTokenHUD extends foundry.applications.hud.TokenHUD {
classes: ['daggerheart'], classes: ['daggerheart'],
actions: { actions: {
combat: DHTokenHUD.#onToggleCombat, combat: DHTokenHUD.#onToggleCombat,
togglePartyTokens: DHTokenHUD.#togglePartyTokens togglePartyTokens: DHTokenHUD.#togglePartyTokens,
toggleCompanions: DHTokenHUD.#toggleCompanions
} }
}; };
@ -26,7 +27,7 @@ export default class DHTokenHUD extends foundry.applications.hud.TokenHUD {
context.partyOnCanvas = context.partyOnCanvas =
this.actor.type === 'party' && this.actor.type === 'party' &&
this.actor.system.partyMembers.some(member => member.getActiveTokens().length > 0); this.actor.system.partyMembers.some(member => member.getActiveTokens().length > 0);
context.icons.toggleParty = 'systems/daggerheart/assets/icons/arrow-dunk.png'; context.icons.toggleClowncar = 'systems/daggerheart/assets/icons/arrow-dunk.png';
context.actorType = this.actor.type; context.actorType = this.actor.type;
context.usesEffects = this.actor.type !== 'party'; context.usesEffects = this.actor.type !== 'party';
context.canToggleCombat = DHTokenHUD.#nonCombatTypes.includes(this.actor.type) context.canToggleCombat = DHTokenHUD.#nonCombatTypes.includes(this.actor.type)
@ -56,6 +57,9 @@ export default class DHTokenHUD extends foundry.applications.hud.TokenHUD {
}, {}) }, {})
: null; : null;
context.hasCompanion = this.actor.system.companion;
context.companionOnCanvas = context.hasCompanion && this.actor.system.companion.getActiveTokens().length > 0;
return context; return context;
} }
@ -101,8 +105,24 @@ export default class DHTokenHUD extends foundry.applications.hud.TokenHUD {
: 'DAGGERHEART.APPLICATIONS.HUD.tokenHUD.depositPartyTokens' : 'DAGGERHEART.APPLICATIONS.HUD.tokenHUD.depositPartyTokens'
); );
await this.toggleClowncar(this.actor.system.partyMembers);
}
static async #toggleCompanions(_, button) {
const icon = button.querySelector('img');
icon.classList.toggle('flipped');
button.dataset.tooltip = game.i18n.localize(
icon.classList.contains('flipped')
? 'DAGGERHEART.APPLICATIONS.HUD.tokenHUD.retrieveCompanionTokens'
: 'DAGGERHEART.APPLICATIONS.HUD.tokenHUD.depositCompanionTokens'
);
await this.toggleClowncar([this.actor.system.companion]);
}
async toggleClowncar(actors) {
const animationDuration = 500; const animationDuration = 500;
const activeTokens = this.actor.system.partyMembers.flatMap(member => member.getActiveTokens()); const activeTokens = actors.flatMap(member => member.getActiveTokens());
const { x: actorX, y: actorY } = this.document; const { x: actorX, y: actorY } = this.document;
if (activeTokens.length > 0) { if (activeTokens.length > 0) {
for (let token of activeTokens) { for (let token of activeTokens) {
@ -114,14 +134,15 @@ export default class DHTokenHUD extends foundry.applications.hud.TokenHUD {
} }
} else { } else {
const activeScene = game.scenes.find(x => x.id === game.user.viewedScene); const activeScene = game.scenes.find(x => x.id === game.user.viewedScene);
const partyTokenData = []; const tokenData = [];
for (let member of this.actor.system.partyMembers) { for (let member of actors) {
const data = await member.getTokenDocument(); const data = await member.getTokenDocument();
partyTokenData.push(data.toObject()); tokenData.push(data.toObject());
} }
const newTokens = await activeScene.createEmbeddedDocuments( const newTokens = await activeScene.createEmbeddedDocuments(
'Token', 'Token',
partyTokenData.map(tokenData => ({ tokenData.map(tokenData => ({
...tokenData, ...tokenData,
alpha: 0, alpha: 0,
x: actorX, x: actorX,

View file

@ -24,13 +24,13 @@
font-weight: bold; font-weight: bold;
} }
} }
}
.clown-car img { .clown-car img {
transition: 0.5s; transition: 0.5s;
&.flipped { &.flipped {
transform: scaleX(-1); transform: scaleX(-1);
}
} }
} }

View file

@ -11,6 +11,11 @@
<button type="button" class="control-icon" data-action="sort" data-direction="down" data-tooltip="HUD.ToBack"> <button type="button" class="control-icon" data-action="sort" data-direction="down" data-tooltip="HUD.ToBack">
<img src="{{icons.down}}"> <img src="{{icons.down}}">
</button> </button>
{{#if hasCompanion}}
<button type="button" class="control-icon clown-car" data-action="toggleCompanions" data-tooltip="{{#if companionOnCanvas}}{{localize "DAGGERHEART.APPLICATIONS.HUD.tokenHUD.retrieveCompanionTokens"}}{{else}}{{localize "DAGGERHEART.APPLICATIONS.HUD.tokenHUD.depositCompanionTokens"}}{{/if}}">
<img {{#if companionOnCanvas}}class="flipped"{{/if}} src="{{icons.toggleClowncar}}">
</button>
{{/if}}
{{#if canConfigure}} {{#if canConfigure}}
<button type="button" class="control-icon" data-action="config" data-tooltip="HUD.OpenConfig"> <button type="button" class="control-icon" data-action="config" data-tooltip="HUD.OpenConfig">
@ -76,7 +81,7 @@
{{#if (eq actorType 'party')}} {{#if (eq actorType 'party')}}
<button type="button" class="control-icon clown-car" data-action="togglePartyTokens" data-tooltip="{{#if partyOnCanvas}}{{localize "DAGGERHEART.APPLICATIONS.HUD.tokenHUD.retrievePartyTokens"}}{{else}}{{localize "DAGGERHEART.APPLICATIONS.HUD.tokenHUD.depositPartyTokens"}}{{/if}}"> <button type="button" class="control-icon clown-car" data-action="togglePartyTokens" data-tooltip="{{#if partyOnCanvas}}{{localize "DAGGERHEART.APPLICATIONS.HUD.tokenHUD.retrievePartyTokens"}}{{else}}{{localize "DAGGERHEART.APPLICATIONS.HUD.tokenHUD.depositPartyTokens"}}{{/if}}">
<img {{#if partyOnCanvas}}class="flipped"{{/if}} src="{{icons.toggleParty}}"> <img {{#if partyOnCanvas}}class="flipped"{{/if}} src="{{icons.toggleClowncar}}">
</button> </button>
{{/if}} {{/if}}