mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-11 19:25:21 +01:00
FEAT: simplify the class sheet
This commit is contained in:
parent
678e45840f
commit
1804070764
4 changed files with 118 additions and 140 deletions
|
|
@ -5,21 +5,17 @@ import DHActionConfig from '../../config/Action.mjs';
|
|||
const { TextEditor } = foundry.applications.ux;
|
||||
|
||||
export default class ClassSheet extends DHBaseItemSheet {
|
||||
/**@inheritdoc */
|
||||
static DEFAULT_OPTIONS = {
|
||||
tag: 'form',
|
||||
classes: ['class'],
|
||||
position: { width: 700 },
|
||||
actions: {
|
||||
removeSubclass: this.removeSubclass,
|
||||
viewSubclass: this.viewSubclass,
|
||||
removeItemFromCollection: ClassSheet.#removeItemFromCollection,
|
||||
removeSuggestedItem: ClassSheet.#removeSuggestedItem,
|
||||
viewDoc: ClassSheet.#viewDoc,
|
||||
addFeature: this.addFeature,
|
||||
editFeature: this.editFeature,
|
||||
deleteFeature: this.deleteFeature,
|
||||
removeItem: this.removeItem,
|
||||
viewItem: this.viewItem,
|
||||
removePrimaryWeapon: this.removePrimaryWeapon,
|
||||
removeSecondaryWeapon: this.removeSecondaryWeapon,
|
||||
removeArmor: this.removeArmor
|
||||
deleteFeature: this.deleteFeature
|
||||
},
|
||||
tagifyConfigs: [
|
||||
{
|
||||
|
|
@ -40,9 +36,11 @@ export default class ClassSheet extends DHBaseItemSheet {
|
|||
]
|
||||
};
|
||||
|
||||
/**@override */
|
||||
static PARTS = {
|
||||
header: { template: 'systems/daggerheart/templates/sheets/items/class/header.hbs' },
|
||||
tabs: { template: 'systems/daggerheart/templates/sheets/global/tabs/tab-navigation.hbs' },
|
||||
description: { template: 'systems/daggerheart/templates/sheets/global/tabs/tab-description.hbs' },
|
||||
features: {
|
||||
template: 'systems/daggerheart/templates/sheets/items/class/features.hbs',
|
||||
scrollable: ['.features']
|
||||
|
|
@ -56,9 +54,9 @@ export default class ClassSheet extends DHBaseItemSheet {
|
|||
/** @inheritdoc */
|
||||
static TABS = {
|
||||
primary: {
|
||||
tabs: [{ id: 'description' }, { id: 'settings' }],
|
||||
tabs: [{ id: 'description' }, { id: 'features' }, { id: 'settings' }],
|
||||
initial: 'description',
|
||||
labelPrefix: 'DAGGERHEART.Sheets.Feature.Tabs'
|
||||
labelPrefix: 'DAGGERHEART.Sheets.TABS'
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -69,6 +67,8 @@ export default class ClassSheet extends DHBaseItemSheet {
|
|||
return context;
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
|
||||
/**
|
||||
* Callback function used by `tagifyElement`.
|
||||
* @param {Array<Object>} selectedOptions - The currently selected tag objects.
|
||||
|
|
@ -77,119 +77,7 @@ export default class ClassSheet extends DHBaseItemSheet {
|
|||
await this.document.update({ 'system.domains': selectedOptions.map(x => x.value) });
|
||||
}
|
||||
|
||||
static async removeSubclass(_, button) {
|
||||
await this.document.update({
|
||||
'system.subclasses': this.document.system.subclasses.filter(x => x.uuid !== button.dataset.subclass)
|
||||
});
|
||||
}
|
||||
|
||||
static async viewSubclass(_, button) {
|
||||
const subclass = await fromUuid(button.dataset.subclass);
|
||||
subclass.sheet.render(true);
|
||||
}
|
||||
|
||||
static async deleteFeature(_, button) {
|
||||
await this.document.update({
|
||||
'system.features': this.document.system.features.map(x => x.uuid).filter(x => x !== button.dataset.feature)
|
||||
});
|
||||
}
|
||||
|
||||
static async editFeature(_, button) {
|
||||
const feature = await fromUuid(button.dataset.feature);
|
||||
feature.sheet.render(true);
|
||||
}
|
||||
|
||||
static async removeItem(event, button) {
|
||||
event.stopPropagation();
|
||||
const type = button.dataset.type;
|
||||
const path = `system.inventory.${type}`;
|
||||
await this.document.update({
|
||||
[path]: this.document.system.inventory[type].filter(x => x.uuid !== button.dataset.item)
|
||||
});
|
||||
}
|
||||
|
||||
static async viewItem(_, button) {
|
||||
const item = await fromUuid(button.dataset.item);
|
||||
item.sheet.render(true);
|
||||
}
|
||||
|
||||
static async removePrimaryWeapon(event) {
|
||||
event.stopPropagation();
|
||||
await this.document.update({ 'system.characterGuide.suggestedPrimaryWeapon': null }, { diff: false });
|
||||
}
|
||||
|
||||
static async removeSecondaryWeapon(event) {
|
||||
event.stopPropagation();
|
||||
await this.document.update({ 'system.characterGuide.suggestedSecondaryWeapon': null }, { diff: false });
|
||||
}
|
||||
|
||||
static async removeArmor(event) {
|
||||
event.stopPropagation();
|
||||
await this.document.update({ 'system.characterGuide.suggestedArmor': null }, { diff: false });
|
||||
}
|
||||
|
||||
async selectActionType() {
|
||||
const content = await foundry.applications.handlebars.renderTemplate(
|
||||
'systems/daggerheart/templates/views/actionType.hbs',
|
||||
{ types: SYSTEM.ACTIONS.actionTypes }
|
||||
),
|
||||
title = 'Select Action Type',
|
||||
type = 'form',
|
||||
data = {};
|
||||
return Dialog.prompt({
|
||||
title,
|
||||
label: title,
|
||||
content,
|
||||
type,
|
||||
callback: html => {
|
||||
const form = html[0].querySelector('form'),
|
||||
fd = new foundry.applications.ux.FormDataExtended(form);
|
||||
foundry.utils.mergeObject(data, fd.object, { inplace: true });
|
||||
|
||||
return data;
|
||||
},
|
||||
rejectClose: false
|
||||
});
|
||||
}
|
||||
|
||||
getActionPath(type) {
|
||||
return type === 'hope' ? 'hopeFeatures' : 'classFeatures';
|
||||
}
|
||||
|
||||
static async addFeature(_, target) {
|
||||
const actionPath = this.getActionPath(target.dataset.type);
|
||||
const actionType = await this.selectActionType();
|
||||
const cls = actionsTypes[actionType?.type] ?? actionsTypes.attack,
|
||||
action = new cls(
|
||||
{
|
||||
_id: foundry.utils.randomID(),
|
||||
systemPath: actionPath,
|
||||
type: actionType.type,
|
||||
name: game.i18n.localize(SYSTEM.ACTIONS.actionTypes[actionType.type].name),
|
||||
...cls.getSourceConfig(this.document)
|
||||
},
|
||||
{
|
||||
parent: this.document
|
||||
}
|
||||
);
|
||||
await this.document.update({ [`system.${actionPath}`]: [...this.document.system[actionPath], action] });
|
||||
}
|
||||
|
||||
static async editFeature(_, target) {
|
||||
const action = this.document.system[this.getActionPath(target.dataset.type)].find(
|
||||
x => x._id === target.dataset.feature
|
||||
);
|
||||
await new DHActionConfig(action).render(true);
|
||||
}
|
||||
|
||||
static async deleteFeature(_, target) {
|
||||
const actionPath = this.getActionPath(target.dataset.type);
|
||||
await this.document.update({
|
||||
[`system.${actionPath}`]: this.document.system[actionPath].filter(
|
||||
action => action._id !== target.dataset.feature
|
||||
)
|
||||
});
|
||||
}
|
||||
/* -------------------------------------------- */
|
||||
|
||||
async _onDrop(event) {
|
||||
const data = TextEditor.getDragEventData(event);
|
||||
|
|
@ -245,4 +133,92 @@ export default class ClassSheet extends DHBaseItemSheet {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
/* Application Clicks Actions */
|
||||
/* -------------------------------------------- */
|
||||
|
||||
static async #removeItemFromCollection(_event, element) {
|
||||
const { uuid, target } = element.dataset;
|
||||
const prop = foundry.utils.getProperty(this.document.system, target);
|
||||
await this.document.update({ [target]: prop.filter(i => i.uuid !== uuid) });
|
||||
}
|
||||
|
||||
static async #removeSuggestedItem(_event, element) {
|
||||
const { target } = element.dataset;
|
||||
await this.document.update({ [`system.characterGuide.${target}`]: null });
|
||||
}
|
||||
|
||||
static async #viewDoc(_event, button) {
|
||||
const doc = await fromUuid(button.dataset.uuid);
|
||||
doc.sheet.render({ force: true });
|
||||
}
|
||||
|
||||
//TODO: redo this
|
||||
async selectActionType() {
|
||||
const content = await foundry.applications.handlebars.renderTemplate(
|
||||
'systems/daggerheart/templates/views/actionType.hbs',
|
||||
{ types: SYSTEM.ACTIONS.actionTypes }
|
||||
),
|
||||
title = 'Select Action Type',
|
||||
type = 'form',
|
||||
data = {};
|
||||
return Dialog.prompt({
|
||||
title,
|
||||
label: title,
|
||||
content,
|
||||
type,
|
||||
callback: html => {
|
||||
const form = html[0].querySelector('form'),
|
||||
fd = new foundry.applications.ux.FormDataExtended(form);
|
||||
foundry.utils.mergeObject(data, fd.object, { inplace: true });
|
||||
|
||||
return data;
|
||||
},
|
||||
rejectClose: false
|
||||
});
|
||||
}
|
||||
|
||||
//TODO: redo this
|
||||
getActionPath(type) {
|
||||
return type === 'hope' ? 'hopeFeatures' : 'classFeatures';
|
||||
}
|
||||
|
||||
//TODO: redo this
|
||||
static async addFeature(_, target) {
|
||||
const actionPath = this.getActionPath(target.dataset.type);
|
||||
const actionType = await this.selectActionType();
|
||||
const cls = actionsTypes[actionType?.type] ?? actionsTypes.attack,
|
||||
action = new cls(
|
||||
{
|
||||
_id: foundry.utils.randomID(),
|
||||
systemPath: actionPath,
|
||||
type: actionType.type,
|
||||
name: game.i18n.localize(SYSTEM.ACTIONS.actionTypes[actionType.type].name),
|
||||
...cls.getSourceConfig(this.document)
|
||||
},
|
||||
{
|
||||
parent: this.document
|
||||
}
|
||||
);
|
||||
await this.document.update({ [`system.${actionPath}`]: [...this.document.system[actionPath], action] });
|
||||
}
|
||||
|
||||
//TODO: redo this
|
||||
static async editFeature(_, target) {
|
||||
const action = this.document.system[this.getActionPath(target.dataset.type)].find(
|
||||
x => x._id === target.dataset.feature
|
||||
);
|
||||
await new DHActionConfig(action).render(true);
|
||||
}
|
||||
|
||||
//TODO: redo this
|
||||
static async deleteFeature(_, target) {
|
||||
const actionPath = this.getActionPath(target.dataset.type);
|
||||
await this.document.update({
|
||||
[`system.${actionPath}`]: this.document.system[actionPath].filter(
|
||||
action => action._id !== target.dataset.feature
|
||||
)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,16 +36,17 @@
|
|||
<div class='controls'>
|
||||
<a
|
||||
class='effect-control'
|
||||
data-action='viewSubclass'
|
||||
data-subclass={{subclass.uuid}}
|
||||
data-action='viewDoc'
|
||||
data-uuid={{subclass.uuid}}
|
||||
data-tooltip='{{localize "DAGGERHEART.Tooltip.openItemWorld"}}'
|
||||
>
|
||||
<i class="fa-solid fa-globe"></i>
|
||||
</a>
|
||||
<a
|
||||
class='effect-control'
|
||||
data-action='removeSubclass'
|
||||
data-subclass={{subclass.uuid}}
|
||||
data-action='removeItemFromCollection'
|
||||
data-target="subclasses"
|
||||
data-uuid={{subclass.uuid}}
|
||||
data-tooltip='{{localize "DAGGERHEART.Tooltip.delete"}}'
|
||||
>
|
||||
<i class='fas fa-trash'></i>
|
||||
|
|
|
|||
|
|
@ -39,11 +39,11 @@
|
|||
<legend>{{localize "DAGGERHEART.Sheets.Class.Guide.SuggestedPrimaryWeaponTitle"}}</legend>
|
||||
<div class="drop-section-body list-items">
|
||||
{{#if document.system.characterGuide.suggestedPrimaryWeapon}}
|
||||
<div class="suggested-item item-line" data-action="viewItem" data-item="{{document.system.characterGuide.suggestedPrimaryWeapon.uuid}}">
|
||||
<div class="suggested-item item-line" data-action="viewDoc" data-uuid="{{document.system.characterGuide.suggestedPrimaryWeapon.uuid}}">
|
||||
<img class="image" src="{{document.system.characterGuide.suggestedPrimaryWeapon.img}}" />
|
||||
<span>{{document.system.characterGuide.suggestedPrimaryWeapon.name}}</span>
|
||||
<div class="controls">
|
||||
<i data-action="removePrimaryWeapon" class="fa-solid fa-trash icon-button"></i>
|
||||
<i data-action="removeSuggestedItem" data-target="suggestedPrimaryWeapon" class="fa-solid fa-trash icon-button"></i>
|
||||
</div>
|
||||
</div>
|
||||
{{/if}}
|
||||
|
|
@ -54,11 +54,11 @@
|
|||
<legend>{{localize "DAGGERHEART.Sheets.Class.Guide.SuggestedSecondaryWeaponTitle"}}</legend>
|
||||
<div class="drop-section-body list-items">
|
||||
{{#if document.system.characterGuide.suggestedSecondaryWeapon}}
|
||||
<div class="suggested-item item-line" data-action="viewItem" data-item="{{system.system.characterGuide.suggestedSecondaryWeapon.uuid}}">
|
||||
<div class="suggested-item item-line" data-action="viewDoc" data-uuid="{{system.system.characterGuide.suggestedSecondaryWeapon.uuid}}">
|
||||
<img class="image" src="{{document.system.characterGuide.suggestedSecondaryWeapon.img}}" />
|
||||
<span>{{document.system.characterGuide.suggestedSecondaryWeapon.name}}</span>
|
||||
<div class="controls">
|
||||
<i data-action="removeSecondaryWeapon" class="fa-solid fa-trash icon-button"></i>
|
||||
<i data-action="removeSuggestedItem" data-target="suggestedSecondaryWeapon" class="fa-solid fa-trash icon-button"></i>
|
||||
</div>
|
||||
</div>
|
||||
{{/if}}
|
||||
|
|
@ -69,11 +69,11 @@
|
|||
<legend>{{localize "DAGGERHEART.Sheets.Class.Guide.SuggestedArmorTitle"}}</legend>
|
||||
<div class="drop-section-body list-items">
|
||||
{{#if document.system.characterGuide.suggestedArmor}}
|
||||
<div class="suggested-item item-line" data-action="viewItem" data-item="{{document.system.characterGuide.suggestedArmor.uuid}}">
|
||||
<div class="suggested-item item-line" data-action="viewDoc" data-uuid="{{document.system.characterGuide.suggestedArmor.uuid}}">
|
||||
<img class="image" src="{{document.system.characterGuide.suggestedArmor.img}}" />
|
||||
<span>{{document.system.characterGuide.suggestedArmor.name}}</span>
|
||||
<div class="controls">
|
||||
<i data-action="removeArmor" class="fa-solid fa-trash icon-button"></i>
|
||||
<i data-action="removeSuggestedItem" data-target="suggestedArmor" class="fa-solid fa-trash icon-button"></i>
|
||||
</div>
|
||||
</div>
|
||||
{{/if}}
|
||||
|
|
@ -87,11 +87,11 @@
|
|||
<legend>{{localize "DAGGERHEART.Sheets.Class.Guide.Inventory.Take"}}</legend>
|
||||
<div class="drop-section-body list-items">
|
||||
{{#each source.system.inventory.take}}
|
||||
<div class="suggested-item item-line" data-action="viewItem" data-item="{{this.uuid}}">
|
||||
<div class="suggested-item item-line" data-action="viewDoc" data-uuid="{{this.uuid}}">
|
||||
<img class="image" src="{{this.img}}" />
|
||||
<span>{{this.name}}</span>
|
||||
<div class="controls">
|
||||
<i data-action="removeItem" data-type="take" data-item="{{this.uuid}}" class="fa-solid fa-trash icon-button"></i>
|
||||
<i data-action="removeItemFromCollection" data-target="invetory.take" data-uuid="{{this.uuid}}" class="fa-solid fa-trash icon-button"></i>
|
||||
</div>
|
||||
</div>
|
||||
{{/each}}
|
||||
|
|
@ -102,11 +102,11 @@
|
|||
<legend>{{localize "DAGGERHEART.Sheets.Class.Guide.Inventory.ThenChoose"}}</legend>
|
||||
<div class="drop-section-body list-items">
|
||||
{{#each source.system.inventory.choiceA}}
|
||||
<div class="suggested-item item-line" data-action="viewItem" data-item="{{this.uuid}}">
|
||||
<div class="suggested-item item-line" data-action="viewDoc" data-uuid="{{this.uuid}}">
|
||||
<img class="image" src="{{this.img}}" />
|
||||
<span>{{this.name}}</span>
|
||||
<div class="controls">
|
||||
<i data-action="removeItem" data-type="choiceA" data-item="{{this.uuid}}" class="fa-solid fa-trash icon-button"></i>
|
||||
<i data-action="removeItemFromCollection" data-target="invetory.choiceA" data-uuid="{{this.uuid}}" class="fa-solid fa-trash icon-button"></i>
|
||||
</div>
|
||||
</div>
|
||||
{{/each}}
|
||||
|
|
@ -117,11 +117,11 @@
|
|||
<legend>{{localize "DAGGERHEART.Sheets.Class.Guide.Inventory.AndEither"}}</legend>
|
||||
<div class="drop-section-body list-items">
|
||||
{{#each source.system.inventory.choiceB}}
|
||||
<div class="suggested-item item-line" data-action="viewItem" data-item="{{this.uuid}}">
|
||||
<div class="suggested-item item-line" data-action="viewDoc" data-uuid="{{this.uuid}}">
|
||||
<img class="image" src="{{this.img}}" />
|
||||
<span>{{this.name}}</span>
|
||||
<div class="controls">
|
||||
<i data-action="removeItem" data-type="choiceB" data-item="{{this.uuid}}" class="fa-solid fa-trash icon-button"></i>
|
||||
<i data-action="removeItemFromCollection" data-target="invetory.choiceB" data-uuid="{{this.uuid}}" class="fa-solid fa-trash icon-button"></i>
|
||||
</div>
|
||||
</div>
|
||||
{{/each}}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
{{#each types}}
|
||||
<li>
|
||||
<label>
|
||||
{{! TODO: remove dh-icon}}
|
||||
<dh-icon class="dh-icon fas {{icon}}"></dh-icon>
|
||||
<span>{{localize name}}</span>
|
||||
<input type="radio" name="type" value="{{id}}" {{#if (eq @index 0)}}checked{{/if}}>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue