add a damage application button to Trefferpunkte chat messages
This commit is contained in:
parent
43459113d5
commit
a3b6271bf3
11
src/Chat/TrefferpunkteTargets.hbs
Normal file
11
src/Chat/TrefferpunkteTargets.hbs
Normal file
@ -0,0 +1,11 @@
|
||||
<div class="DSA41 chat-targets">
|
||||
<div class="center">{{localize "DSA41.chat.targets"}}</div>
|
||||
|
||||
{{#each this}}
|
||||
<div class="target" data-actor-id="{{uuid}}">
|
||||
<img src="{{img}}" alt="{{name}}">
|
||||
<span>{{name}}</span>
|
||||
<button data-action="apply_damage">{{localize "DSA41.chat.trefferpunkte_apply"}}</button>
|
||||
</div>
|
||||
{{/each}}
|
||||
</div>
|
||||
@ -35,7 +35,10 @@
|
||||
"value": "Wert",
|
||||
"roll": "Wurf",
|
||||
|
||||
"talentwert_short": "TaW"
|
||||
"talentwert_short": "TaW",
|
||||
|
||||
"targets": "Ziele",
|
||||
"trefferpunkte_apply": "Zuweisen"
|
||||
},
|
||||
|
||||
"basiswerte": {
|
||||
|
||||
19
src/main.css
19
src/main.css
@ -158,6 +158,25 @@ html {
|
||||
}
|
||||
}
|
||||
|
||||
&.chat-targets {
|
||||
& img {
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
}
|
||||
|
||||
& .target {
|
||||
display: grid;
|
||||
grid-template-columns: max-content minmax(0, max-content) auto minmax(min-content, max-content);
|
||||
gap: 0.5em;
|
||||
|
||||
& button {
|
||||
grid-column: 3;
|
||||
line-height: normal;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
& .die {
|
||||
display: inline-grid;
|
||||
|
||||
|
||||
84
src/main.mjs
84
src/main.mjs
@ -83,10 +83,32 @@ Hooks.once("init", async function() {
|
||||
"fernkampf_trefferpunkte_tooltip": "systems/dsa-4th-edition/src/Tooltips/FernkampfTrefferpunkte.hbs",
|
||||
|
||||
"CHAT_HEADER": "systems/dsa-4th-edition/src/Chat/Header.hbs",
|
||||
"TrefferpunkteTargets": "systems/dsa-4th-edition/src/Chat/TrefferpunkteTargets.hbs",
|
||||
"talent_chat": "systems/dsa-4th-edition/src/Chat/Talent.hbs",
|
||||
});
|
||||
});
|
||||
|
||||
function get_targeted_actors() {
|
||||
const targets = [];
|
||||
|
||||
for (const token of game.user.targets) {
|
||||
if (token.actor) {
|
||||
targets.push(token.actor.uuid);
|
||||
}
|
||||
}
|
||||
|
||||
return targets;
|
||||
}
|
||||
|
||||
async function instantiateTemplate(template, context) {
|
||||
const html = await renderTemplate(template, context);
|
||||
|
||||
const template_element = document.createElement("template");
|
||||
template_element.innerHTML = html;
|
||||
|
||||
return template_element.content.firstChild;
|
||||
}
|
||||
|
||||
class DSA41_ChatMessage extends ChatMessage {
|
||||
get actor() {
|
||||
if (this.speaker.scene && this.speaker.token) {
|
||||
@ -100,17 +122,39 @@ class DSA41_ChatMessage extends ChatMessage {
|
||||
|
||||
async getHTML() {
|
||||
const html = (await super.getHTML())[0];
|
||||
if (!html) return;
|
||||
|
||||
const img = this.actor?.img ?? this.author.avatar;
|
||||
const name = this.alias;
|
||||
const header = await instantiateTemplate("CHAT_HEADER", { img: img, name: name, author: this.author?.name ?? "" });
|
||||
|
||||
const header_html = await renderTemplate("CHAT_HEADER", { img: img, name: name, author: this.author?.name ?? "" });
|
||||
const header_template = document.createElement("template");
|
||||
header_template.innerHTML = header_html;
|
||||
const header = header_template.content.children;
|
||||
const sender = html.querySelector(".message-sender");
|
||||
sender?.replaceChildren(header);
|
||||
|
||||
const sender = html?.querySelector(".message-sender");
|
||||
sender?.replaceChildren(...header);
|
||||
if (this.flags.type === "trefferpunkte" && this.flags.targets.length != 0) {
|
||||
const targets = this.flags.targets.map(x => fromUuidSync(x, { strict: false })).filter(x => x !== null);
|
||||
const targets_list = await instantiateTemplate("TrefferpunkteTargets", targets);
|
||||
|
||||
html.querySelector(".message-content")?.appendChild(targets_list);
|
||||
}
|
||||
|
||||
for (const element of html.querySelectorAll("[data-action]")) {
|
||||
element.addEventListener("click", event => {
|
||||
const target = event.target;
|
||||
const action = target.dataset.action;
|
||||
if (action === null) return;
|
||||
|
||||
if (action === "apply_damage") {
|
||||
const target_actor_id = target.closest("[data-actor-id]")?.dataset.actorId;
|
||||
if (!target_actor_id) return;
|
||||
|
||||
const target_actor = fromUuidSync(target_actor_id);
|
||||
if (!target_actor) return;
|
||||
|
||||
target_actor.update({ "system.lebenspunkte.aktuell": target_actor.system.lebenspunkte.aktuell - this.rolls[0].total });
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return html;
|
||||
}
|
||||
@ -794,6 +838,10 @@ class DSA41_ActorSheet extends DSA41_ApplicationMixin(ActorSheetV2) {
|
||||
roll.toMessage({
|
||||
speaker: ChatMessage.getSpeaker({ actor: this.document }),
|
||||
flavor: flavor,
|
||||
flags: {
|
||||
type: roll_type,
|
||||
targets: get_targeted_actors(),
|
||||
},
|
||||
});
|
||||
|
||||
return;
|
||||
@ -862,6 +910,10 @@ class DSA41_ActorSheet extends DSA41_ApplicationMixin(ActorSheetV2) {
|
||||
roll.toMessage({
|
||||
speaker: ChatMessage.getSpeaker({ actor: this.document }),
|
||||
flavor: flavor,
|
||||
flags: {
|
||||
type: roll_type,
|
||||
targets: get_targeted_actors(),
|
||||
},
|
||||
});
|
||||
|
||||
return;
|
||||
@ -885,6 +937,10 @@ class DSA41_ActorSheet extends DSA41_ApplicationMixin(ActorSheetV2) {
|
||||
roll.toMessage({
|
||||
speaker: ChatMessage.getSpeaker({ actor: this.document }),
|
||||
flavor: flavor,
|
||||
flags: {
|
||||
type: roll_type,
|
||||
targets: get_targeted_actors(),
|
||||
},
|
||||
});
|
||||
|
||||
return;
|
||||
@ -903,6 +959,10 @@ class DSA41_ActorSheet extends DSA41_ApplicationMixin(ActorSheetV2) {
|
||||
roll.toMessage({
|
||||
speaker: ChatMessage.getSpeaker({ actor: this.document }),
|
||||
flavor: flavor,
|
||||
flags: {
|
||||
type: roll_type,
|
||||
targets: get_targeted_actors(),
|
||||
},
|
||||
});
|
||||
|
||||
return;
|
||||
@ -921,6 +981,10 @@ class DSA41_ActorSheet extends DSA41_ApplicationMixin(ActorSheetV2) {
|
||||
roll.toMessage({
|
||||
speaker: ChatMessage.getSpeaker({ actor: this.document }),
|
||||
flavor: game.i18n.localize("DSA41.roll_types." + roll_type),
|
||||
flags: {
|
||||
type: roll_type,
|
||||
targets: get_targeted_actors(),
|
||||
},
|
||||
});
|
||||
|
||||
return;
|
||||
@ -939,6 +1003,10 @@ class DSA41_ActorSheet extends DSA41_ApplicationMixin(ActorSheetV2) {
|
||||
roll.toMessage({
|
||||
speaker: ChatMessage.getSpeaker({ actor: this.document }),
|
||||
flavor: game.i18n.localize("DSA41.roll_types." + roll_type),
|
||||
flags: {
|
||||
type: roll_type,
|
||||
targets: get_targeted_actors(),
|
||||
},
|
||||
});
|
||||
|
||||
return;
|
||||
@ -948,6 +1016,10 @@ class DSA41_ActorSheet extends DSA41_ApplicationMixin(ActorSheetV2) {
|
||||
roll.toMessage({
|
||||
speaker: ChatMessage.getSpeaker({ actor: this.document }),
|
||||
flavor: flavor,
|
||||
flags: {
|
||||
type: roll_type,
|
||||
targets: get_targeted_actors(),
|
||||
},
|
||||
});
|
||||
},
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user