add tooltips for attributes and combat rolls

This commit is contained in:
Sven Balzer 2024-10-30 17:57:25 +01:00
parent a6ae10beba
commit 307307d271
7 changed files with 219 additions and 60 deletions

View File

@ -39,9 +39,9 @@
{{#*inline "die-value"}} {{#*inline "die-value"}}
<div class="col noflex"> <div class="col noflex">
{{#if header}}<div class="center">{{header}}</div>{{/if}} {{#if header}}<div class="center">{{header}}</div>{{/if}}
<div class="die die-{{type}} roll" data-roll-type="{{type}}" {{#if value}}data-success-value="{{value}}"{{/if}} {{#if data-roll}}data-roll="{{data-roll}}"{{/if}}> <div class="die die-{{type}} roll" data-roll-type="{{type}}" {{#if value}}data-success-value="{{value}}"{{/if}} {{#if data-roll}}data-roll="{{data-roll}}"{{/if}} {{#if data-tooltip}}data-tooltip="{{data-tooltip}}"{{/if}}>
<div><svg viewbox="0 0 64 64"><use href="/systems/dsa-4th-edition/src/Assets/d20.svg#d20"></use></svg></div> <div><svg viewbox="0 0 64 64"><use href="/systems/dsa-4th-edition/src/Assets/d20.svg#d20"></use></svg></div>
<div>{{value}}</div> <div>{{{value}}}</div>
</div> </div>
</div> </div>
{{/inline}} {{/inline}}
@ -57,7 +57,7 @@
<div class="row"> <div class="row">
<img class="character-image" src="{{ actor.img }}" title="{{ actor.name }}" {{#if editable}}data-edit="img"{{/if}}> <img class="character-image" src="{{ actor.img }}" title="{{ actor.name }}" {{#if editable}}data-edit="img"{{/if}}>
{{#each actor.system.attributes}} {{#each actor.system.attributes}}
{{>die-value type=@key header=(localize (concat "DSA41.attributes.short." @key)) value=(lookup @root.actor.system.computed.attributes.with_modifiers @key) data-roll="1d20"}} {{>die-value type=@key header=(localize (concat "DSA41.attributes.short." @key)) value=(lookup @root.actor.system.computed.attributes @key)data-roll="1d20" data-tooltip=(lookup @root.tooltips.attributes @key)}}
{{/each}} {{/each}}
</div> </div>
@ -270,9 +270,9 @@
</div> </div>
</div> </div>
<div class="row"></div> <div class="row"></div>
<div class="center">{{>die-value type="attacke" data-roll="1d20" value=attacke}}</div> <div class="center">{{>die-value type="attacke" data-roll="1d20" value=attacke data-tooltip=(lookup @root.tooltips.kampf.attacke item._id)}}</div>
<div class="center">{{>die-value type="parade" data-roll="1d20" value=parade}}</div> <div class="center">{{>die-value type="parade" data-roll="1d20" value=parade data-tooltip=(lookup @root.tooltips.kampf.parade item._id)}}</div>
<div class="center">{{>die-value type="trefferpunkte" data-roll=trefferpunkte}}</div> <div class="center">{{>die-value type="trefferpunkte" data-roll=trefferpunkte value=trefferpunkte_display data-tooltip=(lookup @root.tooltips.kampf.trefferpunkte item._id)}}</div>
</div> </div>
{{/each}} {{/each}}
</div> </div>

19
src/Tooltips/Attacke.hbs Normal file
View File

@ -0,0 +1,19 @@
<div class="dsa41-tooltip">
<ruby>{{talent_attacke}}<rt>{{localize "DSA41.talente.label"}}</rt></ruby>
{{#if (ne modifikator_attacke 0)}}
+ <ruby>{{modifikator_attacke}}<rt>{{localize "DSA41.bewaffnung.nahkampfwaffe.modifikator"}}</rt></ruby>
{{/if}}
{{#if (ne parierwaffe_attacke 0)}}
+ <ruby>{{parierwaffe_attacke}}<rt>{{localize "DSA41.bewaffnung.parierwaffe.label"}}</rt></ruby>
{{/if}}
{{#if (ne schild_attacke 0)}}
+ <ruby>{{schild_attacke}}<rt>{{localize "DSA41.bewaffnung.schild.label"}}</rt></ruby>
{{/if}}
{{#if (lt tp_kk 0)}}
+ <ruby>{{tp_kk}}<rt>{{localize "DSA41.attributes.long.strength"}}</rt></ruby>
{{/if}}
</div>

View File

@ -0,0 +1,9 @@
<div class="dsa41-tooltip">
<ruby>{{initial}}<rt>{{localize "DSA41.attributes.initial"}}</rt></ruby>
{{#if (ne advancement 0)}}
+ <ruby>{{advancement}}<rt>{{localize "DSA41.attributes.advancement"}}</rt></ruby>
{{/if}}
{{#if (ne modifier 0)}}
+ <ruby>{{modifier}}<rt>{{localize "DSA41.attributes.modifier"}}</rt></ruby>
{{/if}}
</div>

19
src/Tooltips/Parade.hbs Normal file
View File

@ -0,0 +1,19 @@
<div class="dsa41-tooltip">
<ruby>{{talent_parade}}<rt>{{localize "DSA41.talente.label"}}</rt></ruby>
{{#if (ne modifikator_parade 0)}}
+ <ruby>{{modifikator_parade}}<rt>{{localize "DSA41.bewaffnung.nahkampfwaffe.modifikator"}}</rt></ruby>
{{/if}}
{{#if (ne parierwaffe_parade 0)}}
+ <ruby>{{parierwaffe_parade}}<rt>{{localize "DSA41.bewaffnung.parierwaffe.label"}}</rt></ruby>
{{/if}}
{{#if (ne schild_parade 0)}}
+ <ruby>{{schild_parade}}<rt>{{localize "DSA41.bewaffnung.schild.label"}}</rt></ruby>
{{/if}}
{{#if (lt tp_kk 0)}}
+ <ruby>{{tp_kk}}<rt>{{localize "DSA41.attributes.long.strength"}}</rt></ruby>
{{/if}}
</div>

View File

@ -0,0 +1,7 @@
<div class="dsa41-tooltip">
<ruby>{{item.system.nahkampfwaffe.basis}}<rt>{{localize "DSA41.bewaffnung.nahkampfwaffe.basis"}}</rt></ruby>
{{#if (ne tp_kk 0)}}
+ <ruby>{{tp_kk}}<rt>{{localize "DSA41.attributes.long.strength"}}</rt></ruby>
{{/if}}
</div>

View File

@ -88,16 +88,16 @@
display: inline-grid; display: inline-grid;
text-align: center; text-align: center;
align-items: center;
color: #fff; color: #fff;
width: 48px;
height: 48px;
} }
.sheet .die > * { .sheet .die > * {
grid-row: 1; grid-row: 1;
grid-column: 1; grid-column: 1;
width: 48px;
height: 48px;
line-height: 48px;
} }
.sheet .die-courage { fill: #b22319; } .sheet .die-courage { fill: #b22319; }
@ -230,3 +230,7 @@
.actor-sheet .kampf .ruestungen > *:last-child { .actor-sheet .kampf .ruestungen > *:last-child {
border: none; border: none;
} }
#tooltip:has(> .dsa41-tooltip) {
/* background-color: #678ec3; */
}

View File

@ -4,11 +4,11 @@ Hooks.once("init", function() {
CONFIG.Actor.dataModels.Player = DSA41_CharacterData; CONFIG.Actor.dataModels.Player = DSA41_CharacterData;
CONFIG.Actor.documentClass = DSA41_CharacterDocument; CONFIG.Actor.documentClass = DSA41_CharacterDocument;
CONFIG.Item. dataModels.Gegenstand = DSA41_GegenstandData; CONFIG.Item.dataModels.Gegenstand = DSA41_GegenstandData;
CONFIG.Item. dataModels.Ruestung = DSA41_RuestungData; CONFIG.Item.dataModels.Ruestung = DSA41_RuestungData;
CONFIG.Item. dataModels.Bewaffnung = DSA41_BewaffnungData; CONFIG.Item.dataModels.Bewaffnung = DSA41_BewaffnungData;
//DocumentSheetConfig.unregisterSheet(Actor, "core", ActorSheet); DocumentSheetConfig.unregisterSheet(Actor, "core", ActorSheet);
DocumentSheetConfig.registerSheet(Actor, "dsa41", DSA41_ActorSheet, { DocumentSheetConfig.registerSheet(Actor, "dsa41", DSA41_ActorSheet, {
makeDefault: true, makeDefault: true,
types: [ types: [
@ -16,7 +16,7 @@ Hooks.once("init", function() {
] ]
}); });
//DocumentSheetConfig.unregisterSheet(Item, "core", ItemSheet); DocumentSheetConfig.unregisterSheet(Item, "core", ItemSheet);
DocumentSheetConfig.registerSheet(Item, "dsa41", DSA41_ItemSheet, { DocumentSheetConfig.registerSheet(Item, "dsa41", DSA41_ItemSheet, {
makeDefault: true, makeDefault: true,
types: [ types: [
@ -25,8 +25,64 @@ Hooks.once("init", function() {
"Bewaffnung", "Bewaffnung",
] ]
}); });
loadTemplates({
"attribute_tooltip": "systems/dsa-4th-edition/src/Tooltips/Attribute.hbs",
"attacke_tooltip": "systems/dsa-4th-edition/src/Tooltips/Attacke.hbs",
"parade_tooltip": "systems/dsa-4th-edition/src/Tooltips/Parade.hbs",
"trefferpunkte_tooltip": "systems/dsa-4th-edition/src/Tooltips/Trefferpunkte.hbs",
});
}); });
function get_minified_formula(formula, data) {
const terms = Roll.simplifyTerms(Roll.parse(formula, data));
let output = [];
let is_combinable = true;
for (let i = 0; i < terms.length; i++) {
const term = terms[i];
if (is_combinable && term instanceof foundry.dice.terms.NumericTerm) {
for (let j = i + 1; j < terms.length - 1; j += 2) {
let operator = terms[j];
let next = terms[j + 1];
if (!(operator instanceof foundry.dice.terms.OperatorTerm && next instanceof foundry.dice.terms.NumericTerm))
break;
switch (operator.operator) {
case "+": {
term.number += next.number;
i += 2;
} break;
case "-": {
term.number -= next.number;
i += 2;
} break;
default:
break;
}
}
is_combinable = false;
} else {
if (term instanceof foundry.dice.terms.OperatorTerm && (term.operator == "+" || term.operator == "-")) {
is_combinable = true;
} else {
is_combinable = false;
}
}
output.push(term);
}
output = Roll.simplifyTerms(output);
return Roll.getFormula(output);
}
const { SchemaField, NumberField, StringField, BooleanField } = foundry.data.fields; const { SchemaField, NumberField, StringField, BooleanField } = foundry.data.fields;
class AttributeField extends foundry.data.fields.SchemaField { class AttributeField extends foundry.data.fields.SchemaField {
@ -231,13 +287,11 @@ class DSA41_CharacterData extends foundry.abstract.TypeDataModel {
} }
} }
prepareDerivedData() { async prepareDerivedData() {
super.prepareDerivedData(); super.prepareDerivedData();
this.computed = { this.computed = {
attributes: { attributes: {},
without_modifiers: {}, attributes_without_modifiers: {},
with_modifiers: {},
},
kampf: { kampf: {
talente: {}, talente: {},
@ -260,19 +314,19 @@ class DSA41_CharacterData extends foundry.abstract.TypeDataModel {
}; };
for (const [attribute, values] of Object.entries(this.attributes)) { for (const [attribute, values] of Object.entries(this.attributes)) {
this.computed.attributes.without_modifiers[attribute] = values.initial + values.advancement; this.computed.attributes[attribute] = values.initial + values.advancement + values.modifier;
this.computed.attributes.with_modifiers [attribute] = values.initial + values.advancement + values.modifier; this.computed.attributes_without_modifiers[attribute] = values.initial + values.advancement;
} }
this.computed.max_lebenspunkte = Math.round((this.computed.attributes.without_modifiers.constitution + this.computed.attributes.without_modifiers.constitution + this.computed.attributes.without_modifiers.strength) / 2); this.computed.max_lebenspunkte = Math.round((this.computed.attributes_without_modifiers.constitution + this.computed.attributes_without_modifiers.constitution + this.computed.attributes_without_modifiers.strength) / 2);
this.computed.max_ausdauer = Math.round((this.computed.attributes.without_modifiers.courage + this.computed.attributes.without_modifiers.constitution + this.computed.attributes.without_modifiers.agility) / 2); this.computed.max_ausdauer = Math.round((this.computed.attributes_without_modifiers.courage + this.computed.attributes_without_modifiers.constitution + this.computed.attributes_without_modifiers.agility) / 2);
this.computed.max_atralenergie = Math.round((this.computed.attributes.without_modifiers.courage + this.computed.attributes.without_modifiers.intuition + this.computed.attributes.without_modifiers.charisma) / 2); this.computed.max_atralenergie = Math.round((this.computed.attributes_without_modifiers.courage + this.computed.attributes_without_modifiers.intuition + this.computed.attributes_without_modifiers.charisma) / 2);
this.computed.magieresistenz = Math.round((this.computed.attributes.without_modifiers.courage + this.computed.attributes.without_modifiers.cleverness + this.computed.attributes.without_modifiers.constitution) / 5); this.computed.magieresistenz = Math.round((this.computed.attributes_without_modifiers.courage + this.computed.attributes_without_modifiers.cleverness + this.computed.attributes_without_modifiers.constitution) / 5);
this.computed.ini_basiswert = Math.round((this.computed.attributes.without_modifiers.courage + this.computed.attributes.without_modifiers.courage + this.computed.attributes.without_modifiers.intuition + this.computed.attributes.without_modifiers.agility) / 5); this.computed.ini_basiswert = Math.round((this.computed.attributes_without_modifiers.courage + this.computed.attributes_without_modifiers.courage + this.computed.attributes_without_modifiers.intuition + this.computed.attributes_without_modifiers.agility) / 5);
this.computed.at_basiswert = Math.round((this.computed.attributes.without_modifiers.courage + this.computed.attributes.without_modifiers.agility + this.computed.attributes.without_modifiers.strength) / 5);; this.computed.at_basiswert = Math.round((this.computed.attributes_without_modifiers.courage + this.computed.attributes_without_modifiers.agility + this.computed.attributes_without_modifiers.strength) / 5);;
this.computed.pa_basiswert = Math.round((this.computed.attributes.without_modifiers.intuition + this.computed.attributes.without_modifiers.agility + this.computed.attributes.without_modifiers.strength) / 5);; this.computed.pa_basiswert = Math.round((this.computed.attributes_without_modifiers.intuition + this.computed.attributes_without_modifiers.agility + this.computed.attributes_without_modifiers.strength) / 5);;
this.computed.fk_basiswert = Math.round((this.computed.attributes.without_modifiers.intuition + this.computed.attributes.without_modifiers.dexterity + this.computed.attributes.without_modifiers.strength) / 5);; this.computed.fk_basiswert = Math.round((this.computed.attributes_without_modifiers.intuition + this.computed.attributes_without_modifiers.dexterity + this.computed.attributes_without_modifiers.strength) / 5);;
const equipped_ruestungen = this.parent.items.filter((x) => x.type === "Ruestung"); const equipped_ruestungen = this.parent.items.filter((x) => x.type === "Ruestung");
for (const item of equipped_ruestungen) { for (const item of equipped_ruestungen) {
@ -307,38 +361,60 @@ class DSA41_CharacterData extends foundry.abstract.TypeDataModel {
const equipped_fernkampfwaffen = equipped_bewaffnung.filter((x) => x.system.fernkampfwaffe.aktiv); const equipped_fernkampfwaffen = equipped_bewaffnung.filter((x) => x.system.fernkampfwaffe.aktiv);
for(const item of equipped_nahkampfwaffen) { for(const item of equipped_nahkampfwaffen) {
this.computed.kampf.waffen[item._id] = { item: item };
if (item.system.nahkampfwaffe.aktiv) { if (item.system.nahkampfwaffe.aktiv) {
let computed = this.computed.kampf.waffen[item._id] = {
item: item,
attacke: 0,
parade: 0,
trefferpunkte: "",
trefferpunkte_display: "",
talent_attacke: 0,
talent_parade: 0,
modifikator_attacke: 0,
modifikator_parade: 0,
tp_kk: 0,
parierwaffe_attacke: 0,
parierwaffe_parade: 0,
schild_attacke: 0,
schild_parade: 0,
};
const talent = item.system.nahkampfwaffe.kampftalente; const talent = item.system.nahkampfwaffe.kampftalente;
this.computed.kampf.waffen[item._id].attacke = this.computed.kampf.talente[talent].attacke + item.system.nahkampfwaffe.modifikator_attacke; computed.talent_attacke = this.computed.kampf.talente[talent].attacke;
this.computed.kampf.waffen[item._id].parade = this.computed.kampf.talente[talent].parade + item.system.nahkampfwaffe.modifikator_attacke; computed.talent_parade = this.computed.kampf.talente[talent].parade;
const tp_kk = Math.trunc((this.computed.attributes.with_modifiers.strength - item.system.nahkampfwaffe.schwellenwert) / item.system.nahkampfwaffe.schadensschritte); computed.modifikator_attacke = item.system.nahkampfwaffe.modifikator_attacke;
computed.modifikator_parade = item.system.nahkampfwaffe.modifikator_parade;
if (tp_kk >= 0) { if (item.system.nahkampfwaffe.schadensschritte != 0) {
this.computed.kampf.waffen[item._id].trefferpunkte = item.system.nahkampfwaffe.basis + " + " + tp_kk; computed.tp_kk = Math.trunc((this.computed.attributes.strength - item.system.nahkampfwaffe.schwellenwert) / item.system.nahkampfwaffe.schadensschritte);
} else {
this.computed.kampf.waffen[item._id].trefferpunkte = item.system.nahkampfwaffe.basis + "" + tp_kk;
this.computed.kampf.waffen[item._id].attacke += tp_kk;
this.computed.kampf.waffen[item._id].parade += tp_kk;
} }
for (const parierwaffe of equipped_parierwaffen) { for (const parierwaffe of equipped_parierwaffen) {
if (parierwaffe._id === item._id) continue; if (parierwaffe._id === item._id) continue;
this.computed.kampf.waffen[item._id].attacke += parierwaffe.system.parierwaffe.modifikator_attacke; computed.parierwaffe_attacke += parierwaffe.system.parierwaffe.modifikator_attacke;
this.computed.kampf.waffen[item._id].parade += parierwaffe.system.parierwaffe.modifikator_parade; computed.parierwaffe_parade += parierwaffe.system.parierwaffe.modifikator_parade;
} }
for (const schild of equipped_schilde) { for (const schild of equipped_schilde) {
if (schild._id === item._id) continue; if (schild._id === item._id) continue;
this.computed.kampf.waffen[item._id].attacke += schild.system.schild.modifikator_attacke; computed.schild_attacke += schild.system.schild.modifikator_attacke;
this.computed.kampf.waffen[item._id].parade += schild.system.schild.modifikator_parade; computed.schild_parade += schild.system.schild.modifikator_parade;
} }
computed.attacke = computed.talent_attacke + computed.modifikator_attacke + computed.parierwaffe_attacke + computed.schild_attacke + Math.min(computed.tp_kk, 0);
computed.parade = computed.talent_parade + computed.modifikator_parade + computed.parierwaffe_parade + computed.schild_parade + Math.min(computed.tp_kk, 0);
computed.trefferpunkte = get_minified_formula(item.system.nahkampfwaffe.basis + (computed.tp_kk != 0 ? " + " + computed.tp_kk : ""));
computed.trefferpunkte_display = computed.trefferpunkte.replace(/[\+\-]/, (op) => "<br>" + op);
} }
} }
} }
@ -461,7 +537,32 @@ class DSA41_ActorSheet extends ActorSheet {
} }
get template() { get template() {
return "systems/dsa-4th-edition/src/ActorSheet.html"; return "systems/dsa-4th-edition/src/ActorSheet.hbs";
}
async getData() {
let data = super.getData();
data.tooltips = {
attributes: {},
kampf: {
attacke: {},
parade: {},
trefferpunkte: {},
}
};
for (const [attribute, value] of Object.entries(data.actor.system.attributes)) {
data.tooltips.attributes[attribute] = await renderTemplate("attribute_tooltip", value);
}
for (const [id, computed] of Object.entries(data.actor.system.computed.kampf.waffen)) {
data.tooltips.kampf.attacke [id] = await renderTemplate("attacke_tooltip", computed);
data.tooltips.kampf.parade [id] = await renderTemplate("parade_tooltip", computed);
data.tooltips.kampf.trefferpunkte[id] = await renderTemplate("trefferpunkte_tooltip", computed);
}
return data;
} }
activateListeners(html) { activateListeners(html) {
@ -506,6 +607,6 @@ class DSA41_ItemSheet extends ItemSheet {
} }
get template() { get template() {
return "systems/dsa-4th-edition/src/ItemSheets/" + this.item.type + ".html"; return "systems/dsa-4th-edition/src/ItemSheets/" + this.item.type + ".hbs";
} }
} }