mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-03-07 14:36:13 +01:00
REFACTOR: remove unused method on setting sheet
FEAT: create BaseActorSetting FIX: add type="button" to button on actor's sheet
This commit is contained in:
parent
79a4c13a1b
commit
0189805dd6
20 changed files with 185 additions and 387 deletions
|
|
@ -1,36 +1,15 @@
|
|||
const { HandlebarsApplicationMixin, ApplicationV2 } = foundry.applications.api;
|
||||
import DHBaseActorSettings from "../sheets/api/actor-setting.mjs";
|
||||
|
||||
export default class DHAdversarySettings extends HandlebarsApplicationMixin(ApplicationV2) {
|
||||
constructor(actor) {
|
||||
super({});
|
||||
|
||||
this.actor = actor;
|
||||
this._dragDrop = this._createDragDropHandlers();
|
||||
}
|
||||
|
||||
get title() {
|
||||
return `${game.i18n.localize('DAGGERHEART.GENERAL.Tabs.settings')}`;
|
||||
}
|
||||
/**@typedef {import('@client/applications/_types.mjs').ApplicationClickAction} ApplicationClickAction */
|
||||
|
||||
export default class DHAdversarySettings extends DHBaseActorSettings {
|
||||
/**@inheritdoc */
|
||||
static DEFAULT_OPTIONS = {
|
||||
tag: 'form',
|
||||
classes: ['daggerheart', 'dh-style', 'dialog', 'adversary-settings'],
|
||||
window: {
|
||||
icon: 'fa-solid fa-wrench',
|
||||
resizable: false
|
||||
},
|
||||
classes: ['adversary-settings'],
|
||||
position: { width: 455, height: 'auto' },
|
||||
actions: {
|
||||
addExperience: this.#addExperience,
|
||||
removeExperience: this.#removeExperience,
|
||||
addFeature: this.#addFeature,
|
||||
editFeature: this.#editFeature,
|
||||
removeFeature: this.#removeFeature
|
||||
},
|
||||
form: {
|
||||
handler: this.updateForm,
|
||||
submitOnChange: true,
|
||||
closeOnSubmit: false
|
||||
addExperience: DHAdversarySettings.#addExperience,
|
||||
removeExperience: DHAdversarySettings.#removeExperience,
|
||||
},
|
||||
dragDrop: [
|
||||
{ dragSelector: null, dropSelector: '.tab.features' },
|
||||
|
|
@ -38,6 +17,7 @@ export default class DHAdversarySettings extends HandlebarsApplicationMixin(Appl
|
|||
]
|
||||
};
|
||||
|
||||
/**@override */
|
||||
static PARTS = {
|
||||
header: {
|
||||
id: 'header',
|
||||
|
|
@ -62,116 +42,36 @@ export default class DHAdversarySettings extends HandlebarsApplicationMixin(Appl
|
|||
}
|
||||
};
|
||||
|
||||
|
||||
/** @override */
|
||||
static TABS = {
|
||||
details: {
|
||||
active: true,
|
||||
cssClass: '',
|
||||
group: 'primary',
|
||||
id: 'details',
|
||||
icon: null,
|
||||
label: 'DAGGERHEART.GENERAL.Tabs.details'
|
||||
},
|
||||
attack: {
|
||||
active: false,
|
||||
cssClass: '',
|
||||
group: 'primary',
|
||||
id: 'attack',
|
||||
icon: null,
|
||||
label: 'DAGGERHEART.GENERAL.Tabs.attack'
|
||||
},
|
||||
experiences: {
|
||||
active: false,
|
||||
cssClass: '',
|
||||
group: 'primary',
|
||||
id: 'experiences',
|
||||
icon: null,
|
||||
label: 'DAGGERHEART.GENERAL.Tabs.experiences'
|
||||
},
|
||||
features: {
|
||||
active: false,
|
||||
cssClass: '',
|
||||
group: 'primary',
|
||||
id: 'features',
|
||||
icon: null,
|
||||
label: 'DAGGERHEART.GENERAL.Tabs.features'
|
||||
primary: {
|
||||
tabs: [{ id: 'details' }, { id: 'attack' }, { id: 'experiences' }, { id: 'features' }],
|
||||
initial: 'details',
|
||||
labelPrefix: 'DAGGERHEART.GENERAL.Tabs'
|
||||
}
|
||||
};
|
||||
|
||||
async _prepareContext(_options) {
|
||||
const context = await super._prepareContext(_options);
|
||||
context.document = this.actor;
|
||||
context.tabs = this._getTabs(this.constructor.TABS);
|
||||
context.systemFields = this.actor.system.schema.fields;
|
||||
context.systemFields.attack.fields = this.actor.system.attack.schema.fields;
|
||||
context.isNPC = true;
|
||||
|
||||
return context;
|
||||
}
|
||||
|
||||
_attachPartListeners(partId, htmlElement, options) {
|
||||
super._attachPartListeners(partId, htmlElement, options);
|
||||
|
||||
this._dragDrop.forEach(d => d.bind(htmlElement));
|
||||
}
|
||||
|
||||
_createDragDropHandlers() {
|
||||
return this.options.dragDrop.map(d => {
|
||||
d.callbacks = {
|
||||
dragstart: this._onDragStart.bind(this),
|
||||
drop: this._onDrop.bind(this)
|
||||
};
|
||||
return new foundry.applications.ux.DragDrop.implementation(d);
|
||||
});
|
||||
}
|
||||
|
||||
_getTabs(tabs) {
|
||||
for (const v of Object.values(tabs)) {
|
||||
v.active = this.tabGroups[v.group] ? this.tabGroups[v.group] === v.id : v.active;
|
||||
v.cssClass = v.active ? 'active' : '';
|
||||
}
|
||||
|
||||
return tabs;
|
||||
}
|
||||
/* -------------------------------------------- */
|
||||
|
||||
/**
|
||||
* Adds a new experience entry to the actor.
|
||||
* @type {ApplicationClickAction}
|
||||
*/
|
||||
static async #addExperience() {
|
||||
const newExperience = {
|
||||
name: 'Experience',
|
||||
modifier: 0
|
||||
};
|
||||
await this.actor.update({ [`system.experiences.${foundry.utils.randomID()}`]: newExperience });
|
||||
this.render();
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes an experience entry from the actor.
|
||||
* @type {ApplicationClickAction}
|
||||
*/
|
||||
static async #removeExperience(_, target) {
|
||||
await this.actor.update({ [`system.experiences.-=${target.dataset.experience}`]: null });
|
||||
this.render();
|
||||
}
|
||||
|
||||
static async #addFeature(_, _button) {
|
||||
await this.actor.createEmbeddedDocuments('Item', [
|
||||
{
|
||||
type: 'feature',
|
||||
name: game.i18n.format('DOCUMENT.New', { type: game.i18n.localize('TYPES.Item.feature') }),
|
||||
img: 'icons/skills/melee/weapons-crossed-swords-black.webp'
|
||||
}
|
||||
]);
|
||||
this.render();
|
||||
}
|
||||
|
||||
static async #editFeature(event, target) {
|
||||
event.stopPropagation();
|
||||
this.actor.items.get(target.id).sheet.render(true);
|
||||
}
|
||||
|
||||
static async #removeFeature(event, target) {
|
||||
event.stopPropagation();
|
||||
await this.actor.deleteEmbeddedDocuments('Item', [target.id]);
|
||||
this.render();
|
||||
}
|
||||
|
||||
static async updateForm(event, _, formData) {
|
||||
await this.actor.update(formData.object);
|
||||
this.render();
|
||||
}
|
||||
|
||||
async _onDragStart(event) {
|
||||
|
|
@ -192,7 +92,6 @@ export default class DHAdversarySettings extends HandlebarsApplicationMixin(Appl
|
|||
const item = await fromUuid(data.uuid);
|
||||
if (item.type === 'feature') {
|
||||
await this.actor.createEmbeddedDocuments('Item', [item]);
|
||||
this.render();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,37 +1,20 @@
|
|||
import { GMUpdateEvent, socketEvent } from '../../systemRegistration/socket.mjs';
|
||||
import DhCompanionlevelUp from '../levelup/companionLevelup.mjs';
|
||||
import DHBaseActorSettings from '../sheets/api/actor-setting.mjs';
|
||||
|
||||
const { HandlebarsApplicationMixin, ApplicationV2 } = foundry.applications.api;
|
||||
|
||||
export default class DHCompanionSettings extends HandlebarsApplicationMixin(ApplicationV2) {
|
||||
constructor(actor) {
|
||||
super({});
|
||||
|
||||
this.actor = actor;
|
||||
}
|
||||
|
||||
get title() {
|
||||
return `${game.i18n.localize('DAGGERHEART.GENERAL.Tabs.settings')}`;
|
||||
}
|
||||
/**@typedef {import('@client/applications/_types.mjs').ApplicationClickAction} ApplicationClickAction */
|
||||
|
||||
export default class DHCompanionSettings extends DHBaseActorSettings {
|
||||
/**@inheritdoc */
|
||||
static DEFAULT_OPTIONS = {
|
||||
tag: 'form',
|
||||
classes: ['daggerheart', 'dh-style', 'dialog', 'companion-settings'],
|
||||
window: {
|
||||
icon: 'fa-solid fa-wrench',
|
||||
resizable: false
|
||||
},
|
||||
classes: ['companion-settings'],
|
||||
position: { width: 455, height: 'auto' },
|
||||
actions: {
|
||||
levelUp: this.levelUp
|
||||
levelUp: DHCompanionSettings.#levelUp
|
||||
},
|
||||
form: {
|
||||
handler: this.updateForm,
|
||||
submitOnChange: true,
|
||||
closeOnSubmit: false
|
||||
}
|
||||
};
|
||||
|
||||
/**@inheritdoc */
|
||||
static PARTS = {
|
||||
header: {
|
||||
id: 'header',
|
||||
|
|
@ -52,109 +35,67 @@ export default class DHCompanionSettings extends HandlebarsApplicationMixin(Appl
|
|||
}
|
||||
};
|
||||
|
||||
|
||||
/** @inheritdoc */
|
||||
static TABS = {
|
||||
details: {
|
||||
active: true,
|
||||
cssClass: '',
|
||||
group: 'primary',
|
||||
id: 'details',
|
||||
icon: null,
|
||||
label: 'DAGGERHEART.GENERAL.Tabs.details'
|
||||
},
|
||||
experiences: {
|
||||
active: false,
|
||||
cssClass: '',
|
||||
group: 'primary',
|
||||
id: 'experiences',
|
||||
icon: null,
|
||||
label: 'DAGGERHEART.GENERAL.Tabs.experiences'
|
||||
},
|
||||
attack: {
|
||||
active: false,
|
||||
cssClass: '',
|
||||
group: 'primary',
|
||||
id: 'attack',
|
||||
icon: null,
|
||||
label: 'DAGGERHEART.GENERAL.Tabs.attack'
|
||||
primary: {
|
||||
tabs: [{ id: 'details' }, { id: 'attack' }, { id: 'experiences' }],
|
||||
initial: 'details',
|
||||
labelPrefix: 'DAGGERHEART.GENERAL.Tabs'
|
||||
}
|
||||
};
|
||||
|
||||
_attachPartListeners(partId, htmlElement, options) {
|
||||
super._attachPartListeners(partId, htmlElement, options);
|
||||
|
||||
htmlElement.querySelector('.partner-value')?.addEventListener('change', this.onPartnerChange.bind(this));
|
||||
/**@inheritdoc */
|
||||
async _onRender(context, options) {
|
||||
await super._onRender(context, options);
|
||||
this.element.querySelector('.partner-value')?.addEventListener('change', this.onPartnerChange.bind(this));
|
||||
}
|
||||
|
||||
/**@inheritdoc */
|
||||
async _prepareContext(_options) {
|
||||
const context = await super._prepareContext(_options);
|
||||
context.document = this.actor;
|
||||
context.tabs = this._getTabs(this.constructor.TABS);
|
||||
context.systemFields = this.actor.system.schema.fields;
|
||||
context.systemFields.attack.fields = this.actor.system.attack.schema.fields;
|
||||
context.isNPC = true;
|
||||
|
||||
context.playerCharacters = game.actors
|
||||
.filter(
|
||||
x =>
|
||||
x.type === 'character' &&
|
||||
(x.testUserPermission(game.user, CONST.DOCUMENT_OWNERSHIP_LEVELS.OWNER) ||
|
||||
this.document.system.partner?.uuid === x.uuid)
|
||||
)
|
||||
.filter(x => x.type === 'character' && (x.isOwner || this.document.system.partner?.uuid === x.uuid))
|
||||
.map(x => ({ key: x.uuid, name: x.name }));
|
||||
|
||||
return context;
|
||||
}
|
||||
|
||||
_getTabs(tabs) {
|
||||
for (const v of Object.values(tabs)) {
|
||||
v.active = this.tabGroups[v.group] ? this.tabGroups[v.group] === v.id : v.active;
|
||||
v.cssClass = v.active ? 'active' : '';
|
||||
}
|
||||
|
||||
return tabs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles changes to the actor's partner selection.
|
||||
* @param {Event} event - The change event triggered by the partner input element.
|
||||
*/
|
||||
async onPartnerChange(event) {
|
||||
const partnerDocument = event.target.value
|
||||
? await foundry.utils.fromUuid(event.target.value)
|
||||
const value = event.target.value;
|
||||
const partnerDocument = value
|
||||
? await foundry.utils.fromUuid(value)
|
||||
: this.actor.system.partner;
|
||||
const partnerUpdate = { 'system.companion': event.target.value ? this.actor.uuid : null };
|
||||
const partnerUpdate = { 'system.companion': value ? this.actor.uuid : null };
|
||||
|
||||
if (!partnerDocument.testUserPermission(game.user, CONST.DOCUMENT_OWNERSHIP_LEVELS.OWNER)) {
|
||||
if (!partnerDocument.isOwner) {
|
||||
await game.socket.emit(`system.${CONFIG.DH.id}`, {
|
||||
action: socketEvent.GMUpdate,
|
||||
data: {
|
||||
action: GMUpdateEvent.UpdateDocument,
|
||||
uuid: partnerDocument.uuid,
|
||||
update: update
|
||||
update: partnerUpdate
|
||||
}
|
||||
});
|
||||
} else {
|
||||
await partnerDocument.update(partnerUpdate);
|
||||
}
|
||||
|
||||
await this.actor.update({ 'system.partner': event.target.value });
|
||||
await this.actor.update({ 'system.partner': value });
|
||||
|
||||
if (!event.target.value) {
|
||||
await this.actor.updateLevel(1);
|
||||
}
|
||||
|
||||
this.render();
|
||||
if (!value) await this.actor.updateLevel(1);
|
||||
}
|
||||
|
||||
async viewActor(_, button) {
|
||||
const target = button.closest('[data-item-uuid]');
|
||||
const actor = await foundry.utils.fromUuid(target.dataset.itemUuid);
|
||||
if (!actor) return;
|
||||
|
||||
actor.sheet.render(true);
|
||||
}
|
||||
|
||||
static async levelUp() {
|
||||
new DhCompanionlevelUp(this.actor).render(true);
|
||||
}
|
||||
|
||||
static async updateForm(event, _, formData) {
|
||||
await this.actor.update(formData.object);
|
||||
this.render();
|
||||
/**
|
||||
* Opens the companion level-up dialog for the associated actor.
|
||||
* @type {ApplicationClickAction}
|
||||
*/
|
||||
static async #levelUp() {
|
||||
new DhCompanionlevelUp(this.actor).render({ force: true });
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,39 +1,17 @@
|
|||
const { HandlebarsApplicationMixin, ApplicationV2 } = foundry.applications.api;
|
||||
import DHBaseActorSettings from "../sheets/api/actor-setting.mjs";
|
||||
|
||||
export default class DHEnvironmentSettings extends HandlebarsApplicationMixin(ApplicationV2) {
|
||||
constructor(actor) {
|
||||
super({});
|
||||
|
||||
this.actor = actor;
|
||||
this._dragDrop = this._createDragDropHandlers();
|
||||
}
|
||||
|
||||
get title() {
|
||||
return `${game.i18n.localize('DAGGERHEART.GENERAL.Tabs.settings')}`;
|
||||
}
|
||||
/**@typedef {import('@client/applications/_types.mjs').ApplicationClickAction} ApplicationClickAction */
|
||||
|
||||
export default class DHEnvironmentSettings extends DHBaseActorSettings {
|
||||
/**@inheritdoc */
|
||||
static DEFAULT_OPTIONS = {
|
||||
tag: 'form',
|
||||
classes: ['daggerheart', 'dh-style', 'dialog', 'environment-settings'],
|
||||
window: {
|
||||
icon: 'fa-solid fa-wrench',
|
||||
resizable: false
|
||||
},
|
||||
position: { width: 455, height: 'auto' },
|
||||
classes: ['environment-settings'],
|
||||
actions: {
|
||||
addFeature: this.#addFeature,
|
||||
editFeature: this.#editFeature,
|
||||
removeFeature: this.#removeFeature,
|
||||
addCategory: this.#addCategory,
|
||||
deleteProperty: this.#deleteProperty,
|
||||
addCategory: DHEnvironmentSettings.#addCategory,
|
||||
removeCategory: DHEnvironmentSettings.#removeCategory,
|
||||
viewAdversary: this.#viewAdversary,
|
||||
deleteAdversary: this.#deleteAdversary
|
||||
},
|
||||
form: {
|
||||
handler: this.updateForm,
|
||||
submitOnChange: true,
|
||||
closeOnSubmit: false
|
||||
},
|
||||
dragDrop: [
|
||||
{ dragSelector: null, dropSelector: '.category-container' },
|
||||
{ dragSelector: null, dropSelector: '.tab.features' },
|
||||
|
|
@ -41,6 +19,7 @@ export default class DHEnvironmentSettings extends HandlebarsApplicationMixin(Ap
|
|||
]
|
||||
};
|
||||
|
||||
/**@override */
|
||||
static PARTS = {
|
||||
header: {
|
||||
id: 'header',
|
||||
|
|
@ -61,100 +40,34 @@ export default class DHEnvironmentSettings extends HandlebarsApplicationMixin(Ap
|
|||
}
|
||||
};
|
||||
|
||||
/** @inheritdoc */
|
||||
static TABS = {
|
||||
details: {
|
||||
active: true,
|
||||
cssClass: '',
|
||||
group: 'primary',
|
||||
id: 'details',
|
||||
icon: null,
|
||||
label: 'DAGGERHEART.GENERAL.Tabs.details'
|
||||
},
|
||||
features: {
|
||||
active: false,
|
||||
cssClass: '',
|
||||
group: 'primary',
|
||||
id: 'features',
|
||||
icon: null,
|
||||
label: 'DAGGERHEART.GENERAL.Tabs.features'
|
||||
},
|
||||
adversaries: {
|
||||
active: false,
|
||||
cssClass: '',
|
||||
group: 'primary',
|
||||
id: 'adversaries',
|
||||
icon: null,
|
||||
label: 'DAGGERHEART.GENERAL.Tabs.adversaries'
|
||||
primary: {
|
||||
tabs: [{ id: 'details' }, { id: 'features' }, { id: 'adversaries' }],
|
||||
initial: 'details',
|
||||
labelPrefix: 'DAGGERHEART.GENERAL.Tabs'
|
||||
}
|
||||
};
|
||||
|
||||
async _prepareContext(_options) {
|
||||
const context = await super._prepareContext(_options);
|
||||
context.document = this.actor;
|
||||
context.tabs = this._getTabs(this.constructor.TABS);
|
||||
context.systemFields = this.actor.system.schema.fields;
|
||||
context.isNPC = true;
|
||||
|
||||
return context;
|
||||
}
|
||||
|
||||
_attachPartListeners(partId, htmlElement, options) {
|
||||
super._attachPartListeners(partId, htmlElement, options);
|
||||
|
||||
this._dragDrop.forEach(d => d.bind(htmlElement));
|
||||
}
|
||||
|
||||
_createDragDropHandlers() {
|
||||
return this.options.dragDrop.map(d => {
|
||||
d.callbacks = {
|
||||
dragstart: this._onDragStart.bind(this),
|
||||
drop: this._onDrop.bind(this)
|
||||
};
|
||||
return new foundry.applications.ux.DragDrop.implementation(d);
|
||||
});
|
||||
}
|
||||
|
||||
_getTabs(tabs) {
|
||||
for (const v of Object.values(tabs)) {
|
||||
v.active = this.tabGroups[v.group] ? this.tabGroups[v.group] === v.id : v.active;
|
||||
v.cssClass = v.active ? 'active' : '';
|
||||
}
|
||||
|
||||
return tabs;
|
||||
}
|
||||
|
||||
static async #addFeature(_, _button) {
|
||||
await this.actor.createEmbeddedDocuments('Item', [
|
||||
{
|
||||
type: 'feature',
|
||||
name: game.i18n.format('DOCUMENT.New', { type: game.i18n.localize('TYPES.Item.feature') }),
|
||||
img: 'icons/magic/perception/orb-crystal-ball-scrying-blue.webp'
|
||||
}
|
||||
]);
|
||||
this.render();
|
||||
}
|
||||
|
||||
static async #editFeature(_, target) {
|
||||
this.actor.items.get(target.id).sheet.render(true);
|
||||
}
|
||||
|
||||
static async #removeFeature(_, target) {
|
||||
await this.actor.deleteEmbeddedDocuments('Item', [target.id]);
|
||||
this.render();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new category entry to the actor.
|
||||
* @type {ApplicationClickAction}
|
||||
*/
|
||||
static async #addCategory() {
|
||||
await this.actor.update({
|
||||
[`system.potentialAdversaries.${foundry.utils.randomID()}.label`]: game.i18n.localize(
|
||||
'DAGGERHEART.ACTORS.Environment.newAdversary'
|
||||
)
|
||||
});
|
||||
this.render();
|
||||
}
|
||||
|
||||
static async #deleteProperty(_, target) {
|
||||
await this.actor.update({ [`${target.dataset.path}.-=${target.id}`]: null });
|
||||
this.render();
|
||||
/**
|
||||
* Removes an category entry from the actor.
|
||||
* @type {ApplicationClickAction}
|
||||
*/
|
||||
static async #removeCategory(_, target) {
|
||||
await this.actor.update({ [`system.potentialAdversaries.-=${target.dataset.categoryId}`]: null });
|
||||
}
|
||||
|
||||
static async #viewAdversary(_, button) {
|
||||
|
|
@ -164,17 +77,17 @@ export default class DHEnvironmentSettings extends HandlebarsApplicationMixin(Ap
|
|||
return;
|
||||
}
|
||||
|
||||
adversary.sheet.render(true);
|
||||
adversary.sheet.render({ force: true });
|
||||
}
|
||||
|
||||
static async #deleteAdversary(event, target) {
|
||||
const adversaryKey = target.dataset.adversary;
|
||||
const path = `system.potentialAdversaries.${target.dataset.potentialAdversary}.adversaries`;
|
||||
console.log(target.dataset.potentialAdversar);
|
||||
const newAdversaries = foundry.utils
|
||||
.getProperty(this.actor, path)
|
||||
.filter(x => x && (x?.uuid ?? x) !== adversaryKey);
|
||||
await this.actor.update({ [path]: newAdversaries });
|
||||
this.render();
|
||||
}
|
||||
|
||||
async _onDragStart(event) {
|
||||
|
|
@ -206,9 +119,4 @@ export default class DHEnvironmentSettings extends HandlebarsApplicationMixin(Ap
|
|||
this.render();
|
||||
}
|
||||
}
|
||||
|
||||
static async updateForm(event, _, formData) {
|
||||
await this.actor.update(formData.object);
|
||||
this.render();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,3 +2,4 @@ export { default as DHApplicationMixin } from './application-mixin.mjs';
|
|||
export { default as DHBaseItemSheet } from './base-item.mjs';
|
||||
export { default as DHHeritageSheet } from './heritage-sheet.mjs';
|
||||
export { default as DHBaseActorSheet } from "./base-actor.mjs";
|
||||
export { default as DHBaseActorSettings } from "./actor-setting.mjs";
|
||||
|
|
|
|||
51
module/applications/sheets/api/actor-setting.mjs
Normal file
51
module/applications/sheets/api/actor-setting.mjs
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
import DHApplicationMixin from './application-mixin.mjs';
|
||||
const { DocumentSheetV2 } = foundry.applications.api;
|
||||
|
||||
/**@typedef {import('@client/applications/_types.mjs').ApplicationClickAction} ApplicationClickAction */
|
||||
|
||||
/**
|
||||
* Base settings sheet for Daggerheart actors.
|
||||
* @extends {DHApplicationMixin<DocumentSheetV2>}
|
||||
*/
|
||||
export default class DHBaseActorSettings extends DHApplicationMixin(DocumentSheetV2) {
|
||||
|
||||
/**@inheritdoc */
|
||||
static DEFAULT_OPTIONS = {
|
||||
classes: ['dialog'],
|
||||
window: {
|
||||
icon: 'fa-solid fa-wrench',
|
||||
resizable: false,
|
||||
title: "DAGGERHEART.GENERAL.Tabs.settings"
|
||||
},
|
||||
position: { width: 455, height: 'auto' },
|
||||
actions: {},
|
||||
form: {
|
||||
submitOnChange: true,
|
||||
},
|
||||
dragDrop: [
|
||||
{ dragSelector: null, dropSelector: '.tab.features' },
|
||||
{ dragSelector: '.feature-item', dropSelector: null }
|
||||
]
|
||||
};
|
||||
|
||||
/** @inheritDoc */
|
||||
_initializeApplicationOptions(options) {
|
||||
options = super._initializeApplicationOptions(options);
|
||||
options.classes = options.classes.filter(c => c !== "sheet");
|
||||
return options;
|
||||
}
|
||||
|
||||
/**@returns {foundry.documents.Actor} */
|
||||
get actor() {
|
||||
return this.document;
|
||||
}
|
||||
|
||||
/**@inheritdoc */
|
||||
async _prepareContext(options) {
|
||||
const context = await super._prepareContext(options);
|
||||
context.systemFields.attack.fields = this.actor.system.attack.schema.fields;
|
||||
context.isNPC = this.actor.isNPC;
|
||||
|
||||
return context
|
||||
}
|
||||
}
|
||||
|
|
@ -221,17 +221,15 @@ export default function DHApplicationMixin(Base) {
|
|||
* @param {HTMLElement} button - The capturing HTML element which defines the [data-action="removeAction"]
|
||||
*/
|
||||
static async #createDoc(event, button) {
|
||||
const { type } = button.dataset;
|
||||
const operation = {
|
||||
parent: this.document,
|
||||
pack: this.document.pack,
|
||||
renderSheet: !event.shiftKey,
|
||||
}
|
||||
const { documentClass, type } = button.dataset;
|
||||
console.log(documentClass, type);
|
||||
const parent = this.document;
|
||||
|
||||
const cls = getDocumentClass(type);
|
||||
const cls = getDocumentClass(documentClass);
|
||||
return await cls.createDocuments([{
|
||||
name: cls.defaultName(operation)
|
||||
}], operation);
|
||||
name: cls.defaultName({ type, parent }),
|
||||
type,
|
||||
}], { parent, renderSheet: !event.shiftKey });
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
import DHBaseActorSettings from './actor-setting.mjs';
|
||||
import DHApplicationMixin from './application-mixin.mjs';
|
||||
|
||||
const { ActorSheetV2 } = foundry.applications.sheets;
|
||||
|
|
@ -25,14 +26,13 @@ export default class DHBaseActorSheet extends DHApplicationMixin(ActorSheetV2) {
|
|||
dragDrop: [],
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
/**@type {typeof DHBaseActorSettings}*/
|
||||
#settingSheet;
|
||||
|
||||
/**@returns {DHBaseActorSettings|null} */
|
||||
get settingSheet() {
|
||||
const SheetClass = this.document.system.metadata.settingSheet;
|
||||
return this.#settingSheet ??= SheetClass ? new SheetClass(this.document): null;
|
||||
return this.#settingSheet ??= SheetClass ? new SheetClass({document: this.document}): null;
|
||||
}
|
||||
|
||||
/**@inheritdoc */
|
||||
|
|
@ -43,7 +43,7 @@ export default class DHBaseActorSheet extends DHApplicationMixin(ActorSheetV2) {
|
|||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Open the Actor Setting Sheet
|
||||
* @type {ApplicationClickAction}
|
||||
*/
|
||||
static async #openSettings() {
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@ import DHApplicationMixin from './application-mixin.mjs';
|
|||
|
||||
const { ItemSheetV2 } = foundry.applications.sheets;
|
||||
|
||||
/**@typedef {import('@client/applications/_types.mjs').ApplicationClickAction} ApplicationClickAction */
|
||||
|
||||
/**
|
||||
* A base item sheet extending {@link ItemSheetV2} via {@link DHApplicationMixin}
|
||||
* @extends ItemSheetV2
|
||||
|
|
@ -92,8 +94,7 @@ export default class DHBaseItemSheet extends DHApplicationMixin(ItemSheetV2) {
|
|||
|
||||
/**
|
||||
* Add a new action to the item, prompting the user for its type.
|
||||
* @param {PointerEvent} _event - The originating click event
|
||||
* @param {HTMLElement} _button - The capturing HTML element which defines the [data-action="addAction"]
|
||||
* @type {ApplicationClickAction}
|
||||
*/
|
||||
static async #addAction(_event, _button) {
|
||||
const actionType = await DHBaseItemSheet.selectActionType();
|
||||
|
|
@ -124,8 +125,7 @@ export default class DHBaseItemSheet extends DHApplicationMixin(ItemSheetV2) {
|
|||
|
||||
/**
|
||||
* Edit an existing action on the item
|
||||
* @param {PointerEvent} _event - The originating click event
|
||||
* @param {HTMLElement} button - The capturing HTML element which defines the [data-action="editAction"]
|
||||
* @type {ApplicationClickAction}
|
||||
*/
|
||||
static async #editAction(_event, button) {
|
||||
const action = this.document.system.actions[button.dataset.index];
|
||||
|
|
@ -134,8 +134,7 @@ export default class DHBaseItemSheet extends DHApplicationMixin(ItemSheetV2) {
|
|||
|
||||
/**
|
||||
* Remove an action from the item.
|
||||
* @param {PointerEvent} event - The originating click event
|
||||
* @param {HTMLElement} button - The capturing HTML element which defines the [data-action="removeAction"]
|
||||
* @type {ApplicationClickAction}
|
||||
*/
|
||||
static async #removeAction(event, button) {
|
||||
event.stopPropagation();
|
||||
|
|
@ -147,8 +146,7 @@ export default class DHBaseItemSheet extends DHApplicationMixin(ItemSheetV2) {
|
|||
|
||||
/**
|
||||
* Add a new feature to the item, prompting the user for its type.
|
||||
* @param {PointerEvent} _event - The originating click event
|
||||
* @param {HTMLElement} _button - The capturing HTML element which defines the [data-action="addFeature"]
|
||||
* @type {ApplicationClickAction}
|
||||
*/
|
||||
static async #addFeature(_event, _button) {
|
||||
const feature = await game.items.documentClass.create({
|
||||
|
|
@ -162,8 +160,7 @@ export default class DHBaseItemSheet extends DHApplicationMixin(ItemSheetV2) {
|
|||
|
||||
/**
|
||||
* Edit an existing feature on the item
|
||||
* @param {PointerEvent} _event - The originating click event
|
||||
* @param {HTMLElement} button - The capturing HTML element which defines the [data-action="editFeature"]
|
||||
* @type {ApplicationClickAction}
|
||||
*/
|
||||
static async #editFeature(_event, button) {
|
||||
const target = button.closest('.feature-item');
|
||||
|
|
@ -178,8 +175,7 @@ export default class DHBaseItemSheet extends DHApplicationMixin(ItemSheetV2) {
|
|||
|
||||
/**
|
||||
* Remove a feature from the item.
|
||||
* @param {PointerEvent} event - The originating click event
|
||||
* @param {HTMLElement} button - The capturing HTML element which defines the [data-action="removeFeature"]
|
||||
* @type {ApplicationClickAction}
|
||||
*/
|
||||
static async #removeFeature(event, button) {
|
||||
event.stopPropagation();
|
||||
|
|
|
|||
|
|
@ -1,10 +1,12 @@
|
|||
import DHBaseActorSettings from "../../applications/sheets/api/actor-setting.mjs";
|
||||
|
||||
/**
|
||||
* Describes metadata about the actor data model type
|
||||
* @typedef {Object} ActorDataModelMetadata
|
||||
* @property {string} label - A localizable label used on application.
|
||||
* @property {string} type - The system type that this data model represents.
|
||||
* @property {Boolean} isNPC - This data model represents a NPC?
|
||||
* @property {typeof foundry.applications.api.DocumentSheetV2} settingSheet - The sheet class used to render the settings UI for this actor type.
|
||||
* @property {typeof DHBaseActorSettings} settingSheet - The sheet class used to render the settings UI for this actor type.
|
||||
*/
|
||||
export default class BaseDataActor extends foundry.abstract.TypeDataModel {
|
||||
/** @returns {ActorDataModelMetadata}*/
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
data-tab='{{tabs.experiences.id}}'
|
||||
data-group='{{tabs.experiences.group}}'
|
||||
>
|
||||
<button class="add-experience-btn" type="button" data-action="addExperience">
|
||||
<button type="button" class="add-experience-btn" type="button" data-action="addExperience">
|
||||
<span>New Experience</span>
|
||||
</button>
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
data-tab='{{tabs.features.id}}'
|
||||
data-group='{{tabs.features.group}}'
|
||||
>
|
||||
<button class="add-feature-btn" data-action="addFeature">
|
||||
<button type="button" class="add-feature-btn" data-action="createDoc" data-document-class="Item" data-type="feature">
|
||||
{{localize "DOCUMENT.New" type=(localize "TYPES.Item.feature")}}
|
||||
</button>
|
||||
<fieldset>
|
||||
|
|
@ -16,8 +16,8 @@
|
|||
<span>{{feature.name}}</span>
|
||||
</div>
|
||||
<div class="controls">
|
||||
<a data-action="editFeature" id="{{feature.id}}" data-tooltip="{{localize 'DAGGERHEART.Tooltip.edit'}}"><i class="fa-solid fa-pen-to-square"></i></a>
|
||||
<a data-action="removeFeature" id="{{feature.id}}" data-tooltip="{{localize 'CONTROLS.CommonDelete'}}"><i class="fa-solid fa-trash"></i></a>
|
||||
<a data-action="editDoc" data-type="Item" data-doc-id="{{feature.id}}" data-tooltip="{{localize 'DAGGERHEART.Tooltip.edit'}}"><i class="fa-solid fa-pen-to-square"></i></a>
|
||||
<a data-action="deleteDoc" data-type="Item" data-doc-id="{{feature.id}}" data-tooltip="{{localize 'CONTROLS.CommonDelete'}}"><i class="fa-solid fa-trash"></i></a>
|
||||
</div>
|
||||
</li>
|
||||
{{/each}}
|
||||
|
|
|
|||
|
|
@ -13,11 +13,11 @@
|
|||
<div class="form-group">
|
||||
<div class="form-fields">
|
||||
<label>{{localize "DAGGERHEART.ACTORS.Companion.FIELDS.partner.label"}}</label>
|
||||
<select class="partner-value">
|
||||
<select class="partner-value" name="system.partner">
|
||||
{{selectOptions playerCharacters selected=document.system.partner.uuid labelAttr="name" valueAttr="key" blank=""}}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</fieldset>
|
||||
<button data-action="levelUp" {{#if (not document.system.levelData.canLevelUp)}}disabled{{/if}}>Level Up</button>
|
||||
<button type="button" data-action="levelUp" {{#if (not document.system.levelData.canLevelUp)}}disabled{{/if}}>Level Up</button>
|
||||
</section>
|
||||
|
|
@ -3,18 +3,20 @@
|
|||
data-tab='{{tabs.adversaries.id}}'
|
||||
data-group='{{tabs.adversaries.group}}'
|
||||
>
|
||||
<button class="add-action-btn" data-action="addCategory">
|
||||
<button type="button" class="add-action-btn" data-action="addCategory">
|
||||
New Category
|
||||
</button>
|
||||
{{#each document.system.potentialAdversaries}}
|
||||
<fieldset class="category-container" data-potential-adversary="{{@key}}">
|
||||
<legend>{{this.label}}</legend>
|
||||
{{#each document.system.potentialAdversaries as |category id|}}
|
||||
<fieldset class="category-container" data-potential-adversary="{{id}}">
|
||||
<legend>{{category.label}}</legend>
|
||||
<div class="category-name">
|
||||
<input type="text" name="{{concat "system.potentialAdversaries." @key ".label" }}" value="{{this.label}}" />
|
||||
<a><i class="fa-solid fa-trash" data-action="deleteProperty" data-path="system.potentialAdversaries" id={{@key}} data-tooltip='{{localize "CONTROLS.CommonDelete"}}'></i></a>
|
||||
<input type="text" name="{{concat "system.potentialAdversaries." @key ".label" }}" value="{{category.label}}" />
|
||||
<a data-action="removeCategory" data-category-id={{id}} data-tooltip='{{localize "CONTROLS.CommonDelete"}}'>
|
||||
<i class="fa-solid fa-trash"></i>
|
||||
</a>
|
||||
</div>
|
||||
<div class="adversaries-container">
|
||||
{{#each this.adversaries as |adversary|}}
|
||||
{{#each category.adversaries as |adversary|}}
|
||||
<div class="adversary-container">
|
||||
{{> 'systems/daggerheart/templates/sheets/global/partials/inventory-item.hbs' item=adversary type='adversary' isActor=true categoryAdversary=@../key}}
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
data-tab='{{tabs.features.id}}'
|
||||
data-group='{{tabs.features.group}}'
|
||||
>
|
||||
<button class="add-feature-btn" data-action="addFeature">
|
||||
<button type="button" class="add-feature-btn" data-action="createDoc" data-document-class="Item" data-type="feature">
|
||||
{{localize "DOCUMENT.New" type=(localize "TYPES.Item.feature")}}
|
||||
</button>
|
||||
<fieldset>
|
||||
|
|
@ -16,8 +16,8 @@
|
|||
<span>{{feature.name}}</span>
|
||||
</div>
|
||||
<div class="controls">
|
||||
<a data-action="editFeature" id="{{feature.id}}" data-tooltip="{{localize 'DAGGERHEART.Tooltip.edit'}}"><i class="fa-solid fa-pen-to-square"></i></a>
|
||||
<a data-action="removeFeature" id="{{feature.id}}" data-tooltip="{{localize 'CONTROLS.CommonDelete'}}"><i class="fa-solid fa-trash"></i></a>
|
||||
<a data-action="editDoc" data-type="Item" data-doc-id="{{feature.id}}" data-tooltip="{{localize 'DAGGERHEART.Tooltip.edit'}}"><i class="fa-solid fa-pen-to-square"></i></a>
|
||||
<a data-action="deleteDoc" data-type="Item" data-doc-id="{{feature.id}}" data-tooltip="{{localize 'CONTROLS.CommonDelete'}}"><i class="fa-solid fa-trash"></i></a>
|
||||
</div>
|
||||
</li>
|
||||
{{/each}}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,8 @@
|
|||
<div class='level-div'>
|
||||
<h3 class='label'>
|
||||
{{#if (or document.system.needsCharacterSetup document.system.levelData.canLevelUp)}}
|
||||
<button
|
||||
<button
|
||||
type="button"
|
||||
class="level-button glow" data-tooltip="{{#if document.system.needsCharacterSetup}}{{localize "DAGGERHEART.Sheets.PC.CharacterSetup"}}{{else}}{{localize "DAGGERHEART.ACTORS.Character.levelUp"}}{{/if}}"
|
||||
data-action="levelManagement"
|
||||
>
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
<a class="filter-button">
|
||||
<i class="fa-solid fa-filter"></i>
|
||||
</a>
|
||||
<button class="btn-toggle-view" data-action="toggleLoadoutView" data-value="{{listView}}">
|
||||
<button type="button" class="btn-toggle-view" data-action="toggleLoadoutView" data-value="{{listView}}">
|
||||
<span class="{{ifThen listView 'list-active' ''}} list-icon">
|
||||
<i class="fa-solid fa-bars"></i>
|
||||
</span>
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@
|
|||
</div>
|
||||
<div class="companion-navigation">
|
||||
{{> 'systems/daggerheart/templates/sheets/global/tabs/tab-navigation.hbs'}}
|
||||
<button data-action="openSettings">
|
||||
<button type="button" data-action="openSettings">
|
||||
<i class="fa-solid fa-wrench"></i>
|
||||
</button>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@
|
|||
</div>
|
||||
<div class="environment-navigation">
|
||||
{{> 'systems/daggerheart/templates/sheets/global/tabs/tab-navigation.hbs'}}
|
||||
<button data-action="openSettings">
|
||||
<button type="button" data-action="openSettings">
|
||||
<i class="fa-solid fa-wrench"></i>
|
||||
</button>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
<fieldset class="one-column">
|
||||
<legend>
|
||||
{{localize "DAGGERHEART.GENERAL.Effect.plural"}}
|
||||
<a data-action="createDoc" data-type="ActiveEffect">
|
||||
<a data-action="createDoc" data-document-class="ActiveEffect" data-type="base">
|
||||
<i class="fa-solid fa-plus icon-button"></i>
|
||||
</a>
|
||||
</legend>
|
||||
|
|
|
|||
|
|
@ -14,7 +14,6 @@
|
|||
<span>-</span>
|
||||
{{localize (concat 'DAGGERHEART.CONFIG.Range.' source.system.range '.name')}}
|
||||
<span>-</span>
|
||||
{{log this}}
|
||||
{{source.system.damage.dice}} + {{source.system.damage.bonus}}
|
||||
({{localize (concat 'DAGGERHEART.CONFIG.DamageType.' source.system.damage.type '.abbreviation')}})
|
||||
<span>-</span>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue