Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(minion): kill minion button #1787

Merged
merged 1 commit into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* Item qualities, upgrades, etc now use tooltips instead of a fake item window when sent to chat
* You can now adjust token wounds above the threshold ([#1769](/~https://github.com/StarWarsFoundryVTT/StarWarsFFG/issues/1769))
* Token bars now display wounds above threshold and most colors are configurable ([#1769](/~https://github.com/StarWarsFoundryVTT/StarWarsFFG/issues/1769))
* You can now kill a minion or minion group directly from their sheet with a single click! ([#1744](/~https://github.com/StarWarsFoundryVTT/StarWarsFFG/issues/1744))
* Fixes:
* Remove usage of deprecated `math.clamped` in favor of `math.clamp`
* Fix skill roll sometimes showing a pool of only 2 difficulty when clicked ([#1763](/~https://github.com/StarWarsFoundryVTT/StarWarsFFG/issues/1763))
Expand Down
3 changes: 3 additions & 0 deletions lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,9 @@
"SWFFG.Actors.Sheets.Purchase.Tooltip.ForcePower": "Purchase a new Force Power",
"SWFFG.Actors.Sheets.Purchase.Tooltip.SignatureAbility": "Purchase a new Signature Ability",
"SWFFG.Actors.Sheets.Purchase.Tooltip.SkilLRank": "Purchase a Skill Rank",
"SWFFG.Actors.Sheets.Token.KillMinion.Label": "Kill",
"SWFFG.Actors.Sheets.Token.KillMinion.KillMinion": "Minion",
"SWFFG.Actors.Sheets.Token.KillMinion.KillGroup": "Group",
"SWFFG.Items.Popout.Title": "Editing {currentItem} on {parentItem}",
"SWFFG.Items.Popout.Tabs.Basics": "Basics",
"SWFFG.Items.Popout.Tabs.BaseMods": "Base Mods",
Expand Down
23 changes: 23 additions & 0 deletions modules/actors/actor-sheet-ffg.js
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,10 @@ export class ActorSheetFFG extends ActorSheet {
await this._buySkillRank(target);
});

html.find(".minion-control").click(async (ev) => {
await this._handleKillMinion(ev);
});

new ContextMenu(html, "div.skillsHeader", [
{
name: game.i18n.localize("SWFFG.SkillAddContextItem"),
Expand Down Expand Up @@ -2181,6 +2185,25 @@ export class ActorSheetFFG extends ActorSheet {
}
).render(true);
}

/**
* Handle clicking the kill minion button
* @param event
* @returns {Promise<void>}
* @private
*/
async _handleKillMinion(event) {
event.stopPropagation();
const target = $(event.currentTarget);
const minionHealth = this.actor.system.unit_wounds.value;
const currentHealth = this.actor.system.stats.wounds.value;
if (target.hasClass("kill-minion")) {
let damageAmount = minionHealth - (currentHealth % minionHealth) + 1;
await this.actor.update({'system.stats.wounds.value': currentHealth + damageAmount});
} else if (target.hasClass("kill-group")) {
await this.actor.update({'system.stats.wounds.value': this.actor.system.stats.wounds.max + 1});
}
}
}

/**
Expand Down
5 changes: 4 additions & 1 deletion templates/actors/ffg-minion-sheet.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ <h1><input name="name" type="text" value="{{actor.name}}" placeholder="{{localiz
{{#if limited}}{{else}}
<div class="container">
<div class="grid grid-3col minion-stats">
{{!-- Wounds Box --}} {{> "systems/starwarsffg/templates/parts/shared/ffg-block.html" (object blocktype="split" title="SWFFG.Wounds" fields=(array (object name="data.stats.wounds.max" value=data.stats.wounds.max type="Number" label="SWFFG.Threshold") (object name="data.stats.wounds.value" value=data.stats.wounds.value type="Number" label="SWFFG.Current") ))}} {{> "systems/starwarsffg/templates/parts/shared/ffg-block.html" (object blocktype="single" title="SWFFG.MinionUnitWounds" type="Number" name="data.unit_wounds.value" value=data.unit_wounds.value )}}
{{!-- Wounds Box --}}
{{> "systems/starwarsffg/templates/parts/shared/ffg-block.html" (object blocktype="split" title="SWFFG.Wounds" fields=(array (object name="data.stats.wounds.max" value=data.stats.wounds.max type="Number" label="SWFFG.Threshold") (object name="data.stats.wounds.value" value=data.stats.wounds.value type="Number" label="SWFFG.Current") ))}}
{{> "systems/starwarsffg/templates/parts/shared/ffg-block.html" (object blocktype="single" title="SWFFG.MinionUnitWounds" type="Number" name="data.unit_wounds.value" value=data.unit_wounds.value )}}
{{> "systems/starwarsffg/templates/parts/shared/ffg-block.html" (object blocktype="split" title="SWFFG.Actors.Sheets.Token.KillMinion.Label" fields=(array (object name="minion-control kill-minion" type="Button" icon='<a class="fa-solid fa-skull-crossbones"></a>' label="SWFFG.Actors.Sheets.Token.KillMinion.KillMinion") (object name="minion-control kill-group" type="Button" icon='<a><i class="fa-solid fa-skull-crossbones"></i><i class="fa-solid fa-person"></i><i class="fa-solid fa-skull-crossbones"></i></a>' label="SWFFG.Actors.Sheets.Token.KillMinion.KillGroup") ))}}
</div>
</div>
{{/if}}
Expand Down
12 changes: 10 additions & 2 deletions templates/parts/shared/ffg-block.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
</div>
{{/each}}
</div>
{{/if}} {{#if (eq type "PopoutEditor")}}
{{/if}} {{#if (eq type "PopoutEditor")}}
<div class="block-value block-single">
<div class="popout-editor" data-target="{{name}}" data-value="{{value}}" data-label="{{localize title}}">
<div class="popout-editor-button">{{#if readonly}}{{ else }}<i class="fas fa-edit"></i>{{/if}}</div>
Expand All @@ -51,7 +51,15 @@
{{/if}} {{#if (and (ne type "Boolean") (ne type "Dropdown") (ne type "Multicheckbox") (ne type "PopoutEditor"))}}
<div class="block-value block-single">{{#if prefix}}{{{prefix}}}{{/if}}<input type="text" name="{{name}}" value="{{value}}" data-dtype="{{type}}" {{#if disabled}}disabled{{/if}} /></div>
{{/if}} {{/if}} {{#if (eq blocktype "split")}} {{#each fields as |t|}}
<div class="block-value"><input type="text" name="{{name}}" value="{{value}}" data-dtype="{{type}}" {{#if disabled}}disabled{{/if}} /></div>
<div class="block-value">
{{#if (eq type "Button") }}
<div class="btn {{ t.name }}">
{{{ t.icon }}}
</div>
{{ else }}
<input type="text" name="{{name}}" value="{{value}}" data-dtype="{{type}}" {{#if disabled}}disabled{{/if}} />
{{/if}}
</div>
{{/each}} {{/if}} {{#with (lookup options [value])~}} {{#if (ne label ../adjusted)}}
<div class="adjustedvalue">{{localize ../adjusted}}</div>
{{/if}} {{/with}}
Expand Down