mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-12 19:51:08 +01:00
Reworked Action storage
This commit is contained in:
parent
3333a9e00a
commit
ce593d02f3
16 changed files with 196 additions and 23 deletions
|
|
@ -6,6 +6,8 @@ import DaggerheartSheet from './daggerheart-sheet.mjs';
|
|||
import { abilities } from '../../config/actorConfig.mjs';
|
||||
import DhCharacterlevelUp from '../levelup/characterLevelup.mjs';
|
||||
import DhCharacterCreation from '../characterCreation.mjs';
|
||||
import DHActionConfig from '../config/Action.mjs';
|
||||
import { DHBaseAction } from '../../data/action/action.mjs';
|
||||
|
||||
const { ActorSheetV2 } = foundry.applications.sheets;
|
||||
const { TextEditor } = foundry.applications.ux;
|
||||
|
|
@ -51,6 +53,7 @@ export default class CharacterSheet extends DaggerheartSheet(ActorSheetV2) {
|
|||
levelManagement: this.levelManagement,
|
||||
editImage: this._onEditImage,
|
||||
triggerContextMenu: this.triggerContextMenu
|
||||
// editAction: this.editAction,
|
||||
},
|
||||
window: {
|
||||
resizable: true
|
||||
|
|
@ -303,17 +306,27 @@ export default class CharacterSheet extends DaggerheartSheet(ActorSheetV2) {
|
|||
}
|
||||
|
||||
getItem(element) {
|
||||
const itemId = (element.target ?? element).closest('[data-item-id]').dataset.itemId,
|
||||
const listElement = (element.target ?? element).closest('[data-item-id]');
|
||||
if (listElement.dataset.isAction) return this.getAction(listElement);
|
||||
|
||||
const itemId = listElement.dataset.itemId,
|
||||
item = this.document.items.get(itemId);
|
||||
return item;
|
||||
}
|
||||
|
||||
getAction(listElement) {
|
||||
const target = listElement.dataset.partner === 'true' ? this.document.system.companion : this.document;
|
||||
if (!target) return null;
|
||||
|
||||
return target.system.actions.find(x => x.id === listElement.dataset.itemId);
|
||||
}
|
||||
|
||||
static triggerContextMenu(event, button) {
|
||||
return CONFIG.ux.ContextMenu.triggerContextMenu(event);
|
||||
}
|
||||
|
||||
static _onEditImage() {
|
||||
const fp = new FilePicker({
|
||||
const fp = new foundry.applications.apps.FilePicker.implementation({
|
||||
current: this.document.img,
|
||||
type: 'image',
|
||||
redirectToRoot: ['icons/svg/mystery-man.svg'],
|
||||
|
|
@ -616,10 +629,15 @@ export default class CharacterSheet extends DaggerheartSheet(ActorSheetV2) {
|
|||
}
|
||||
}
|
||||
|
||||
static async viewObject(event, button) {
|
||||
static async viewObject(event) {
|
||||
const item = this.getItem(event);
|
||||
if (!item) return;
|
||||
item.sheet.render(true);
|
||||
|
||||
if (item instanceof DHBaseAction) {
|
||||
new DHActionConfig(item).render({ force: true });
|
||||
} else {
|
||||
item.sheet.render(true);
|
||||
}
|
||||
}
|
||||
|
||||
editItem(event) {
|
||||
|
|
@ -672,10 +690,16 @@ export default class CharacterSheet extends DaggerheartSheet(ActorSheetV2) {
|
|||
this.render();
|
||||
}
|
||||
|
||||
static async deleteItem(event, button) {
|
||||
static async deleteItem(event) {
|
||||
const item = this.getItem(event);
|
||||
if (!item) return;
|
||||
await item.delete();
|
||||
|
||||
if (item instanceof DHBaseAction) {
|
||||
const newActions = item.parent.actions.filter(x => x.id !== item.id);
|
||||
await item.parent.parent.update({ ['system.actions']: newActions });
|
||||
} else {
|
||||
await item.delete();
|
||||
}
|
||||
}
|
||||
|
||||
static async setItemQuantity(button, value) {
|
||||
|
|
@ -711,7 +735,30 @@ export default class CharacterSheet extends DaggerheartSheet(ActorSheetV2) {
|
|||
}
|
||||
|
||||
static async toChat(event, button) {
|
||||
if (button?.dataset?.type === 'experience') {
|
||||
const item = event.dataset ? event : button.closest(['[data-item-id']);
|
||||
if (item?.dataset.isAction) {
|
||||
const action = this.getAction(item);
|
||||
const cls = getDocumentClass('ChatMessage');
|
||||
const systemData = {
|
||||
title: action.name,
|
||||
origin: this,
|
||||
img: action.img,
|
||||
name: action.name,
|
||||
description: action.description,
|
||||
actions: []
|
||||
};
|
||||
const msg = new cls({
|
||||
type: 'abilityUse',
|
||||
user: game.user.id,
|
||||
system: systemData,
|
||||
content: await foundry.applications.handlebars.renderTemplate(
|
||||
'systems/daggerheart/templates/chat/ability-use.hbs',
|
||||
systemData
|
||||
)
|
||||
});
|
||||
|
||||
cls.create(msg.toObject());
|
||||
} else if (button?.dataset?.type === 'experience') {
|
||||
const experience = this.document.system.experiences[button.dataset.uuid];
|
||||
const cls = getDocumentClass('ChatMessage');
|
||||
const systemData = {
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ export default function DhpApplicationMixin(Base) {
|
|||
const attr = target.dataset.edit;
|
||||
const current = foundry.utils.getProperty(this.document, attr);
|
||||
const { img } = this.document.constructor.getDefaultArtwork?.(this.document.toObject()) ?? {};
|
||||
const fp = new FilePicker({
|
||||
const fp = new foundry.applications.apps.FilePicker.implementation({
|
||||
current,
|
||||
type: 'image',
|
||||
redirectToRoot: img ? [img] : [],
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue