2024-12-02 15:57:26 -05:00
|
|
|
import { playbookKeys, validatePlaybookKey, getPlaybookMutation } from "../playbooks.mjs";
|
2024-12-04 14:58:31 -05:00
|
|
|
import { updateField } from "../helpers/mutation-helper.mjs";
|
2024-12-13 22:31:03 -05:00
|
|
|
import { storylineKeys } from "../boss.mjs";
|
2024-12-02 15:57:26 -05:00
|
|
|
|
2024-12-04 14:51:41 -05:00
|
|
|
export class HenchActorSheet extends ActorSheet {
|
2024-11-27 19:39:42 -05:00
|
|
|
/** @override */
|
|
|
|
get template() {
|
2024-12-04 14:51:41 -05:00
|
|
|
console.log(`Mapping sheet: ${this.actor.type} => systems/hench/templates/actors/${this.actor.type}.hbs`)
|
|
|
|
return `systems/hench/templates/actors/${this.actor.type}.hbs`;
|
2024-11-27 19:39:42 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/** @override */
|
|
|
|
getData() {
|
2024-12-02 15:57:26 -05:00
|
|
|
const context = super.getData();
|
|
|
|
|
2024-12-13 14:02:47 -05:00
|
|
|
context.playbookKeys = playbookKeys.map((k) => ({ key: k, selected: k === this.actor.system.playbook}));
|
2024-12-13 22:31:03 -05:00
|
|
|
context.storylineKeys = storylineKeys.map((k) => ({ key: k, selected: k === this.actor.system.storyline}));
|
2024-12-02 15:57:26 -05:00
|
|
|
|
2024-12-03 23:30:16 -05:00
|
|
|
// TODO define system constants for these
|
2025-01-17 15:00:22 -05:00
|
|
|
context.maxStress = 8;
|
2024-12-03 23:30:16 -05:00
|
|
|
context.maxExp = 5;
|
2024-12-13 22:31:03 -05:00
|
|
|
context.maxHeat = 18;
|
2024-12-03 23:30:16 -05:00
|
|
|
|
2024-12-11 23:27:19 -05:00
|
|
|
context.minGear = 3;
|
|
|
|
context.maxGear = 5;
|
|
|
|
|
2024-12-02 15:57:26 -05:00
|
|
|
return context;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @override */
|
|
|
|
activateListeners(html) {
|
|
|
|
super.activateListeners(html);
|
|
|
|
|
|
|
|
html.on('change', '.hench-hench-sheet-playbook-dropdown', this._changePlaybook.bind(this));
|
2024-12-02 22:18:47 -05:00
|
|
|
|
|
|
|
html.on('click', '#hench-console-log', (event) => console.log(this.actor));
|
|
|
|
|
|
|
|
// Checkbox logic
|
|
|
|
// boolean checkboxes
|
|
|
|
html.find('.hench-checkbox-toggle-field').on('change', (event) => {
|
|
|
|
const element = event.currentTarget;
|
2024-12-03 22:17:31 -05:00
|
|
|
const path = element.dataset.fieldPath;
|
2024-12-02 22:18:47 -05:00
|
|
|
const value = element.checked;
|
|
|
|
|
2024-12-03 22:17:31 -05:00
|
|
|
updateField(this.actor, path, value);
|
2024-12-02 22:18:47 -05:00
|
|
|
});
|
2024-12-03 23:30:16 -05:00
|
|
|
|
|
|
|
// 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);
|
|
|
|
});
|
2024-12-04 16:20:08 -05:00
|
|
|
|
2024-12-13 22:31:03 -05:00
|
|
|
// normal dropdowns
|
|
|
|
html.find('.hench-hench-sheet-dropdown').on('change', (event) => {
|
|
|
|
const value = event.target.value;
|
|
|
|
const path = event.currentTarget.dataset.fieldPath;
|
|
|
|
|
|
|
|
updateField(this.actor, path, value);
|
|
|
|
});
|
|
|
|
|
2024-12-04 16:20:08 -05:00
|
|
|
// text fields
|
2024-12-11 16:17:00 -05:00
|
|
|
html.find('.hench-text-input').on('change', async (event) => {
|
2024-12-04 16:20:08 -05:00
|
|
|
const element = event.currentTarget;
|
|
|
|
const path = element.dataset.fieldPath;
|
|
|
|
const value = element.value;
|
|
|
|
|
2024-12-11 16:17:00 -05:00
|
|
|
await updateField(this.actor, path, value);
|
|
|
|
});
|
|
|
|
|
|
|
|
// harm auto-marking
|
|
|
|
html.find('.hench-harm-field').on('change', async (event) => {
|
|
|
|
const element = event.currentTarget;
|
|
|
|
const primaryPath = element.dataset.fieldPath;
|
|
|
|
const secondaryPath = element.dataset.dependentPath;
|
|
|
|
const stringValue = element.value;
|
|
|
|
|
|
|
|
const markedValue = stringValue !== null && stringValue !== undefined && stringValue !== "";
|
|
|
|
|
|
|
|
await updateField(this.actor, primaryPath, stringValue)
|
|
|
|
await updateField(this.actor, secondaryPath, markedValue);
|
2024-12-04 16:20:08 -05:00
|
|
|
});
|
2024-12-11 23:27:19 -05:00
|
|
|
|
|
|
|
// increase/decrease buttons
|
|
|
|
html.find('.hench-increment-button-field').click((event) => {
|
|
|
|
const element = event.currentTarget;
|
|
|
|
const path = element.dataset.fieldPath;
|
|
|
|
const value = element.dataset.value;
|
|
|
|
|
|
|
|
updateField(this.actor, path, value);
|
|
|
|
});
|
2024-12-02 15:57:26 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
_changePlaybook(newPlaybookKeyEvent) {
|
|
|
|
const newPlaybookKey = newPlaybookKeyEvent.target.value;
|
|
|
|
|
|
|
|
if(validatePlaybookKey(newPlaybookKey)) {
|
|
|
|
const mutation = getPlaybookMutation(newPlaybookKey, 'system.');
|
|
|
|
|
|
|
|
this.actor.update(mutation);
|
|
|
|
}
|
2024-11-27 19:39:42 -05:00
|
|
|
}
|
|
|
|
}
|