Adds Rollable Attributes

feature/data-binding
macniel 2025-09-27 22:56:26 +02:00
parent 9e261b5b34
commit 68d1fd1477
3 changed files with 95 additions and 1 deletions

View File

@ -7,4 +7,21 @@ export class Character extends Actor {
this.prepareEmbeddedDocuments();
}
getRollData() {
const data = super.getRollData();
if (this.type !== 'character') return;
// Copy the ability scores to the top level, so that rolls can use
// formulas like `@str.mod + 4`.
if (data.attribute) {
for (let [k, v] of Object.entries(data.attribute)) {
data[k] = foundry.utils.deepClone(v);
}
}
console.log(data);
return data;
}
}

View File

@ -34,6 +34,49 @@ export class CharacterSheet extends ActorSheet {
// Add the actor's data to context.data for easier access, as well as flags.
context.system = actorData.system;
context.flags = actorData.flags;
context.attributs = [
{
attribut: "mu",
name: "Mut",
wert: actorData.system.attribute.mu ?? 0,
},
{
attribut: "kl",
name: "Klugheit",
wert: actorData.system.attribute.kl ?? 0,
},
{
attribut: "in",
name: "Intuition",
wert: actorData.system.attribute.in ?? 0,
},
{
attribut: "ch",
name: "Charisma",
wert: actorData.system.attribute.ch ?? 0,
},
{
attribut: "ff",
name: "Fingerfertigkeit",
wert: actorData.system.attribute.ff ?? 0,
},
{
attribut: "ge",
name: "Geschicklichkeit",
wert: actorData.system.attribute.ge ?? 0,
},
{
attribut: "ko",
name: "Konstitution",
wert: actorData.system.attribute.ko ?? 0,
},
{
attribut: "kk",
name: "Körperkraft",
wert: actorData.system.attribute.kk ?? 0,
},
];
context.skills = [];
if ( context.system.talente?.length >= 0) {
context.system.talente.forEach(talent => {
@ -51,9 +94,31 @@ export class CharacterSheet extends ActorSheet {
return context;
}
_onRoll(event) {
event.preventDefault();
const dataset = event.currentTarget.dataset;
console.log(dataset)
if (dataset.roll) {
let label = dataset.label ? `[Attribut] ${dataset.label}` : '';
console.log(this.actor.getRollData());
let roll = new Roll(dataset.roll, this.actor.getRollData());
roll.toMessage({
speaker: ChatMessage.getSpeaker({ actor: this.actor }),
flavor: label,
rollMode: game.settings.get('core', 'rollMode'),
});
return roll;
}
}
activateListeners(html) {
super.activateListeners(html);
html.on('click', '.attribut.rollable', (evt) => {
console.log(evt);
this._onRoll(evt);
});
// Everything below here is only needed if the sheet is editable
if (!this.isEditable) return;

View File

@ -6,6 +6,18 @@
<img class="profile-img" src="{{actor.img}}" data-edit="img" title="{{actor.name}}" height="100" width="100"/>
<div class="header-fields">
<h1 class="charname"><input name="name" type="text" value="{{actor.name}}" placeholder="Name"/></h1>
<div class="attribute">
{{#each attributs}}
<button class="attribut rollable" data-label="{{this.name}}" data-roll="1d20cs<=@{{this.attribut}}">
<span class="attribut-wert">
{{this.wert}}
</span>
<span class="attribut-name">
{{this.name}}
</span>
</button>
{{/each}}
</div>
</div>
</header>
@ -34,7 +46,7 @@
<div class="tab skills" data-group="primary" data-tab="skills">
<ul>
{{#each skills}}
<li><div>
<li><div class="talent rollable" data-roll="1d20cs<=@{{this.p1}}">
<b>{{this.talentName}}</b>
{{this.probe}}
</div></li>