Add int fields, implement checkboxes for whole sheet

This commit is contained in:
walcutt 2024-12-03 23:30:16 -05:00
parent f5b414b6b0
commit e56c65629f
4 changed files with 42 additions and 8 deletions

View File

@ -2,6 +2,12 @@ import { HenchDataModel } from "./module/data-models.mjs";
import { HenchDebugSheet } from "./module/sheets/hench-debug.mjs";
Handlebars.registerHelper('int2checkbox', (size, threshold, options) => {
return new Array(size).fill(0).map(
(e, i) => options.fn({index: i + 1, marked: i < threshold})
);
});
Hooks.once("init", () => {
CONFIG.Actor.dataModels = {
hench: HenchDataModel,

View File

@ -75,6 +75,7 @@ export function updateField(actor, dataPathString, value) {
console.log(`Converted ${dataPathString} to:`);
console.log(dataPath);
console.log(`Writing: ${value}`);
if(dataPath.isArray) {
const initial = getValueAtPath(actor, dataPath.path);

View File

@ -13,6 +13,10 @@ export class HenchDebugSheet extends ActorSheet {
context.playbookKeys = [...playbookKeys, 'test'].map((k) => ({ key: k, selected: k === this.actor.system.playbook}));
// TODO define system constants for these
context.maxStress = 12;
context.maxExp = 5;
return context;
}
@ -33,6 +37,18 @@ export class HenchDebugSheet extends ActorSheet {
updateField(this.actor, path, value);
});
// int checkboxes
html.find('.hench-checkbox-int-field').on('change', (event) => {
const element = event.currentTarget;
const path = element.dataset.fieldPath;
const checked = element.checked;
const valueData = parseInt(element.dataset.value);
const value = checked ? valueData : valueData - 1;
updateField(this.actor, path, value);
});
}
_changePlaybook(newPlaybookKeyEvent) {

View File

@ -41,9 +41,10 @@
<h3>Gear</h3>
<ul>
{{#each actor.system.gear}}
{{#each actor.system.fixedGear}}
<li><input type="checkbox" class="hench-checkbox-toggle-field" data-field-path="system.fixedGear[{{@index}}].marked" {{#if this.marked}}checked{{/if}}/> {{this.description}}</li>
{{/each}}
<li><input type="checkbox" class="hench-checkbox-toggle-field" data-field-path="system.customGear.marked" {{#if system.customGear.marked}}checked{{/if}}/> {{system.customGear.description}}</li>
</ul>
<h3> Harm: </h3>
@ -51,45 +52,55 @@
<h4>Level 1:</h4>
<ul>
{{#each actor.system.harm.levelOne}}
<li><b>{{#if this.marked}} X {{else}} O {{/if}}</b> {{this.description}}</li>
<li><input type="checkbox" class="hench-checkbox-toggle-field" data-field-path="system.harm.levelOne[{{@index}}].marked" {{#if this.marked}}checked{{/if}} /> {{this.description}}</li>
{{/each}}
</ul>
<h4>Level 2:</h4>
<ul>
{{#each actor.system.harm.levelTwo}}
<li><b>{{#if this.marked}} X {{else}} O {{/if}}</b> {{this.description}}</li>
<li><input type="checkbox" class="hench-checkbox-toggle-field" data-field-path="system.harm.levelTwo[{{@index}}].marked" {{#if this.marked}}checked{{/if}} /> {{this.description}}</li>
{{/each}}
</ul>
<h4>Level 3:</h4>
<ul>
{{#each actor.system.harm.levelThree}}
<li><b>{{#if this.marked}} X {{else}} O {{/if}}</b> {{this.description}}</li>
<li><input type="checkbox" class="hench-checkbox-toggle-field" data-field-path="system.harm.levelThree[{{@index}}].marked" {{#if this.marked}}checked{{/if}} /> {{this.description}}</li>
{{/each}}
</ul>
<h4>Level 3:</h4>
<ul>
{{#each actor.system.harm.levelFour}}
<li><b>{{#if this.marked}} X {{else}} O {{/if}}</b> {{this.description}}</li>
<li><input type="checkbox" class="hench-checkbox-toggle-field" data-field-path="system.harm.levelFour[{{@index}}].marked" {{#if this.marked}}checked{{/if}} /> {{this.description}}</li>
{{/each}}
</ul>
</div>
<p>Stress: {{ actor.system.stress }}</p>
<ul>
{{#int2checkbox maxStress actor.system.stress}}
<li style="display:inline"><input type="checkbox" class="hench-checkbox-int-field" data-field-path="system.stress" data-value="{{index}}" {{#if marked}}checked{{/if}} /> </li>
{{/int2checkbox}}
</ul>
<h3>Experience Triggers</h3>
<ul>
{{#each actor.system.experienceTriggers}}
<li><b>{{#if this.marked}} X {{else}} O {{/if}}</b> {{this.description}}</li>
<li><input type="checkbox" class="hench-checkbox-toggle-field" data-field-path="system.experienceTriggers[{{@index}}].marked" {{#if this.marked}}checked{{/if}} /> {{this.description}}</li>
{{/each}}
</ul>
<p>Experience: {{ actor.system.experience }}</p>
<ul>
{{#int2checkbox maxExp actor.system.experience}}
<li style="display:inline"><input type="checkbox" class="hench-checkbox-int-field" data-field-path="system.experience" data-value="{{index}}" {{#if marked}}checked{{/if}} /> </li>
{{/int2checkbox}}
</ul>
<h3>Advancements</h3>
<ul>
{{#each actor.system.baseAdvancements}}
<li><b>{{#if this.marked}} X {{else}} O {{/if}}</b> {{this.description}}</li>
<li><input type="checkbox" class="hench-checkbox-toggle-field" data-field-path="system.baseAdvancements[{{@index}}].marked" {{#if this.marked}}checked{{/if}} /> {{this.description}}</li>
{{/each}}
<hr />
{{#each actor.system.exAdvancements}}
<li><b>{{#if this.marked}} X {{else}} O {{/if}}</b> {{this.description}}</li>
<li><input type="checkbox" class="hench-checkbox-toggle-field" data-field-path="system.exAdvancements[{{@index}}].marked" {{#if this.marked}}checked{{/if}} /> {{this.description}}</li>
{{/each}}
</ul>
</div>