2024-12-02 15:57:26 -05:00
|
|
|
import { playbookKeys, validatePlaybookKey, getPlaybookMutation } from "../playbooks.mjs";
|
2024-12-04 14:51:41 -05:00
|
|
|
import { updateField } from "../helpers/object-helper.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();
|
|
|
|
|
|
|
|
context.playbookKeys = [...playbookKeys, 'test'].map((k) => ({ key: k, selected: k === this.actor.system.playbook}));
|
|
|
|
|
2024-12-03 23:30:16 -05:00
|
|
|
// TODO define system constants for these
|
|
|
|
context.maxStress = 12;
|
|
|
|
context.maxExp = 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-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
|
|
|
}
|
|
|
|
}
|