mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-12 03:31:07 +01:00
[Feature] New Environment Sheet (#243)
* rework new environment template sheet, add environment-settings sheet, improve adversary-settings sheet and delete legacy actor sheet templates * Potential Adversaries can be dragged out of the sheet onto canvas * Added ToChat and UseItem --------- Co-authored-by: WBHarry <williambjrklund@gmail.com>
This commit is contained in:
parent
d58f303907
commit
3a6a973ea2
40 changed files with 1160 additions and 1143 deletions
|
|
@ -12,7 +12,7 @@ export { default as DhpConsumable } from './sheets/items/consumable.mjs';
|
|||
export { default as DhpWeapon } from './sheets/items/weapon.mjs';
|
||||
export { default as DhpArmor } from './sheets/items/armor.mjs';
|
||||
export { default as DhpChatMessage } from './chatMessage.mjs';
|
||||
export { default as DhpEnvironment } from './sheets/environment.mjs';
|
||||
export { default as DhpEnvironment } from './sheets/actors/environment.mjs';
|
||||
export { default as DhActiveEffectConfig } from './sheets/activeEffectConfig.mjs';
|
||||
export { default as DhContextMenu } from './contextMenu.mjs';
|
||||
|
||||
|
|
|
|||
131
module/applications/sheets/actors/environment.mjs
Normal file
131
module/applications/sheets/actors/environment.mjs
Normal file
|
|
@ -0,0 +1,131 @@
|
|||
import DaggerheartSheet from '../daggerheart-sheet.mjs';
|
||||
import DHEnvironmentSettings from '../applications/environment-settings.mjs';
|
||||
|
||||
const { ActorSheetV2 } = foundry.applications.sheets;
|
||||
export default class DhpEnvironment extends DaggerheartSheet(ActorSheetV2) {
|
||||
static DEFAULT_OPTIONS = {
|
||||
tag: 'form',
|
||||
classes: ['daggerheart', 'sheet', 'actor', 'dh-style', 'environment'],
|
||||
position: {
|
||||
width: 500
|
||||
},
|
||||
actions: {
|
||||
addAdversary: this.addAdversary,
|
||||
deleteProperty: this.deleteProperty,
|
||||
viewAdversary: this.viewAdversary,
|
||||
openSettings: this.openSettings,
|
||||
useItem: this.useItem,
|
||||
toChat: this.toChat
|
||||
},
|
||||
form: {
|
||||
handler: this._updateForm,
|
||||
submitOnChange: true,
|
||||
closeOnSubmit: false
|
||||
},
|
||||
dragDrop: [{ dragSelector: '.action-section .inventory-item', dropSelector: null }]
|
||||
};
|
||||
|
||||
static PARTS = {
|
||||
header: { template: 'systems/daggerheart/templates/sheets/actors/environment/header.hbs' },
|
||||
actions: { template: 'systems/daggerheart/templates/sheets/actors/environment/actions.hbs' },
|
||||
potentialAdversaries: {
|
||||
template: 'systems/daggerheart/templates/sheets/actors/environment/potentialAdversaries.hbs'
|
||||
},
|
||||
notes: { template: 'systems/daggerheart/templates/sheets/actors/environment/notes.hbs' }
|
||||
};
|
||||
|
||||
static TABS = {
|
||||
actions: {
|
||||
active: true,
|
||||
cssClass: '',
|
||||
group: 'primary',
|
||||
id: 'actions',
|
||||
icon: null,
|
||||
label: 'DAGGERHEART.General.tabs.actions'
|
||||
},
|
||||
potentialAdversaries: {
|
||||
active: false,
|
||||
cssClass: '',
|
||||
group: 'primary',
|
||||
id: 'potentialAdversaries',
|
||||
icon: null,
|
||||
label: 'DAGGERHEART.General.tabs.potentialAdversaries'
|
||||
},
|
||||
notes: {
|
||||
active: false,
|
||||
cssClass: '',
|
||||
group: 'primary',
|
||||
id: 'notes',
|
||||
icon: null,
|
||||
label: 'DAGGERHEART.Sheets.Adversary.Tabs.notes'
|
||||
}
|
||||
};
|
||||
|
||||
async _prepareContext(_options) {
|
||||
const context = await super._prepareContext(_options);
|
||||
context.document = this.document;
|
||||
context.tabs = super._getTabs(this.constructor.TABS);
|
||||
context.getEffectDetails = this.getEffectDetails.bind(this);
|
||||
|
||||
return context;
|
||||
}
|
||||
|
||||
getAction(element) {
|
||||
const itemId = (element.target ?? element).closest('[data-item-id]').dataset.itemId,
|
||||
item = this.document.system.actions.find(x => x.id === itemId);
|
||||
return item;
|
||||
}
|
||||
|
||||
static async openSettings() {
|
||||
await new DHEnvironmentSettings(this.document).render(true);
|
||||
}
|
||||
|
||||
static async _updateForm(event, _, formData) {
|
||||
await this.document.update(formData.object);
|
||||
this.render();
|
||||
}
|
||||
|
||||
getEffectDetails(id) {
|
||||
return {};
|
||||
}
|
||||
|
||||
static async addAdversary() {
|
||||
await this.document.update({
|
||||
[`system.potentialAdversaries.${foundry.utils.randomID()}.label`]: game.i18n.localize(
|
||||
'DAGGERHEART.Sheets.Environment.newAdversary'
|
||||
)
|
||||
});
|
||||
this.render();
|
||||
}
|
||||
|
||||
static async deleteProperty(_, target) {
|
||||
await this.document.update({ [`${target.dataset.path}.-=${target.id}`]: null });
|
||||
this.render();
|
||||
}
|
||||
|
||||
static async viewAdversary(_, button) {
|
||||
const adversary = await foundry.utils.fromUuid(button.dataset.adversary);
|
||||
adversary.sheet.render(true);
|
||||
}
|
||||
|
||||
static async useItem(event) {
|
||||
const action = this.getAction(event);
|
||||
action.use(event);
|
||||
}
|
||||
|
||||
static async toChat(event) {
|
||||
const item = this.getAction(event);
|
||||
item.toChat(this.document.id);
|
||||
}
|
||||
|
||||
async _onDragStart(event) {
|
||||
const item = event.currentTarget.closest('.inventory-item');
|
||||
|
||||
if (item) {
|
||||
const adversary = game.actors.find(x => x.type === 'adversary' && x.id === item.dataset.itemId);
|
||||
const adversaryData = { type: 'Actor', uuid: adversary.uuid };
|
||||
event.dataTransfer.setData('text/plain', JSON.stringify(adversaryData));
|
||||
event.dataTransfer.setDragImage(item, 60, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -146,7 +146,6 @@ export default class DHAdversarySettings extends HandlebarsApplicationMixin(Appl
|
|||
parent: this.actor
|
||||
}
|
||||
);
|
||||
console.log(action);
|
||||
await this.actor.update({ 'system.actions': [...this.actor.system.actions, action] });
|
||||
await new DHActionConfig(this.actor.system.actions[this.actor.system.actions.length - 1]).render({
|
||||
force: true
|
||||
|
|
|
|||
213
module/applications/sheets/applications/environment-settings.mjs
Normal file
213
module/applications/sheets/applications/environment-settings.mjs
Normal file
|
|
@ -0,0 +1,213 @@
|
|||
import DHActionConfig from '../../config/Action.mjs';
|
||||
import DHBaseItemSheet from '../api/base-item.mjs';
|
||||
import { actionsTypes } from '../../../data/_module.mjs';
|
||||
|
||||
const { HandlebarsApplicationMixin, ApplicationV2 } = foundry.applications.api;
|
||||
|
||||
export default class DHEnvironmentSettings extends HandlebarsApplicationMixin(ApplicationV2) {
|
||||
constructor(actor) {
|
||||
super({});
|
||||
|
||||
this.actor = actor;
|
||||
this._dragDrop = this._createDragDropHandlers();
|
||||
}
|
||||
|
||||
get title() {
|
||||
return `${game.i18n.localize('DAGGERHEART.Sheets.TABS.settings')}`;
|
||||
}
|
||||
|
||||
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' },
|
||||
actions: {
|
||||
addAction: this.#addAction,
|
||||
editAction: this.#editAction,
|
||||
removeAction: this.#removeAction,
|
||||
addCategory: this.#addCategory,
|
||||
deleteProperty: this.#deleteProperty,
|
||||
viewAdversary: this.#viewAdversary,
|
||||
deleteAdversary: this.#deleteAdversary
|
||||
},
|
||||
form: {
|
||||
handler: this.updateForm,
|
||||
submitOnChange: true,
|
||||
closeOnSubmit: false
|
||||
},
|
||||
dragDrop: [{ dragSelector: null, dropSelector: '.category-container' }]
|
||||
};
|
||||
|
||||
static PARTS = {
|
||||
header: {
|
||||
id: 'header',
|
||||
template: 'systems/daggerheart/templates/sheets/applications/environment-settings/header.hbs'
|
||||
},
|
||||
tabs: { template: 'systems/daggerheart/templates/sheets/global/tabs/tab-navigation.hbs' },
|
||||
details: {
|
||||
id: 'details',
|
||||
template: 'systems/daggerheart/templates/sheets/applications/environment-settings/details.hbs'
|
||||
},
|
||||
actions: {
|
||||
id: 'actions',
|
||||
template: 'systems/daggerheart/templates/sheets/applications/environment-settings/actions.hbs'
|
||||
},
|
||||
adversaries: {
|
||||
id: 'adversaries',
|
||||
template: 'systems/daggerheart/templates/sheets/applications/environment-settings/adversaries.hbs'
|
||||
}
|
||||
};
|
||||
|
||||
static TABS = {
|
||||
details: {
|
||||
active: true,
|
||||
cssClass: '',
|
||||
group: 'primary',
|
||||
id: 'details',
|
||||
icon: null,
|
||||
label: 'DAGGERHEART.General.tabs.details'
|
||||
},
|
||||
actions: {
|
||||
active: false,
|
||||
cssClass: '',
|
||||
group: 'primary',
|
||||
id: 'actions',
|
||||
icon: null,
|
||||
label: 'DAGGERHEART.General.tabs.actions'
|
||||
},
|
||||
adversaries: {
|
||||
active: false,
|
||||
cssClass: '',
|
||||
group: 'primary',
|
||||
id: 'adversaries',
|
||||
icon: null,
|
||||
label: 'DAGGERHEART.General.tabs.adversaries'
|
||||
}
|
||||
};
|
||||
|
||||
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 = {
|
||||
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 #addAction(_event, _button) {
|
||||
const actionType = await DHBaseItemSheet.selectActionType();
|
||||
if (!actionType) return;
|
||||
try {
|
||||
const cls = actionsTypes[actionType] ?? actionsTypes.attack,
|
||||
action = new cls(
|
||||
{
|
||||
_id: foundry.utils.randomID(),
|
||||
type: actionType,
|
||||
name: game.i18n.localize(SYSTEM.ACTIONS.actionTypes[actionType].name),
|
||||
...cls.getSourceConfig(this.actor)
|
||||
},
|
||||
{
|
||||
parent: this.actor
|
||||
}
|
||||
);
|
||||
await this.actor.update({ 'system.actions': [...this.actor.system.actions, action] });
|
||||
await new DHActionConfig(this.actor.system.actions[this.actor.system.actions.length - 1]).render({
|
||||
force: true
|
||||
});
|
||||
this.render();
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
}
|
||||
|
||||
static async #editAction(event, target) {
|
||||
event.stopPropagation();
|
||||
const actionIndex = target.dataset.index;
|
||||
await new DHActionConfig(this.actor.system.actions[actionIndex]).render({
|
||||
force: true
|
||||
});
|
||||
}
|
||||
|
||||
static async #removeAction(event, target) {
|
||||
event.stopPropagation();
|
||||
const actionIndex = target.dataset.index;
|
||||
await this.actor.update({
|
||||
'system.actions': this.actor.system.actions.filter((_, index) => index !== Number.parseInt(actionIndex))
|
||||
});
|
||||
this.render();
|
||||
}
|
||||
|
||||
static async #addCategory() {
|
||||
await this.actor.update({
|
||||
[`system.potentialAdversaries.${foundry.utils.randomID()}.label`]: game.i18n.localize(
|
||||
'DAGGERHEART.Sheets.Environment.newAdversary'
|
||||
)
|
||||
});
|
||||
this.render();
|
||||
}
|
||||
|
||||
static async #deleteProperty(_, target) {
|
||||
await this.actor.update({ [`${target.dataset.path}.-=${target.id}`]: null });
|
||||
this.render();
|
||||
}
|
||||
|
||||
static async #viewAdversary(_, button) {
|
||||
const adversary = await foundry.utils.fromUuid(button.dataset.adversary);
|
||||
adversary.sheet.render(true);
|
||||
}
|
||||
|
||||
static async #deleteAdversary(event, target) {
|
||||
const adversaryKey = target.dataset.adversary;
|
||||
const path = `system.potentialAdversaries.${target.dataset.potentialAdversary}.adversaries`;
|
||||
const newAdversaries = foundry.utils.getProperty(this.actor, path).filter(x => x.uuid !== adversaryKey);
|
||||
await this.actor.update({ [path]: newAdversaries });
|
||||
this.render();
|
||||
}
|
||||
|
||||
async _onDrop(event) {
|
||||
const data = TextEditor.getDragEventData(event);
|
||||
const item = await fromUuid(data.uuid);
|
||||
if (item.type === 'adversary') {
|
||||
const target = event.target.closest('.category-container');
|
||||
const path = `system.potentialAdversaries.${target.dataset.potentialAdversary}.adversaries`;
|
||||
const current = foundry.utils.getProperty(this.actor, path).map(x => x.uuid);
|
||||
await this.actor.update({
|
||||
[path]: [...current, item.uuid]
|
||||
});
|
||||
this.render();
|
||||
}
|
||||
}
|
||||
|
||||
static async updateForm(event, _, formData) {
|
||||
await this.actor.update(formData.object);
|
||||
this.render();
|
||||
}
|
||||
}
|
||||
|
|
@ -60,7 +60,7 @@ export default function DhpApplicationMixin(Base) {
|
|||
// drop: this._canDragDrop.bind(this)
|
||||
// };
|
||||
d.callbacks = {
|
||||
// dragstart: this._onDragStart.bind(this),
|
||||
dragstart: this._onDragStart.bind(this),
|
||||
// dragover: this._onDragOver.bind(this),
|
||||
drop: this._onDrop.bind(this)
|
||||
};
|
||||
|
|
@ -68,6 +68,7 @@ export default function DhpApplicationMixin(Base) {
|
|||
});
|
||||
}
|
||||
|
||||
async _onDragStart(event) {}
|
||||
_onDrop(event) {}
|
||||
|
||||
_getTabs(tabs) {
|
||||
|
|
|
|||
|
|
@ -1,107 +0,0 @@
|
|||
import DaggerheartSheet from './daggerheart-sheet.mjs';
|
||||
|
||||
const { ActorSheetV2 } = foundry.applications.sheets;
|
||||
export default class DhpEnvironment extends DaggerheartSheet(ActorSheetV2) {
|
||||
static DEFAULT_OPTIONS = {
|
||||
tag: 'form',
|
||||
classes: ['daggerheart', 'sheet', 'actor', 'dh-style', 'environment'],
|
||||
position: {
|
||||
width: 450,
|
||||
height: 1000
|
||||
},
|
||||
actions: {
|
||||
addAdversary: this.addAdversary,
|
||||
addFeature: this.addFeature,
|
||||
deleteProperty: this.deleteProperty,
|
||||
viewAdversary: this.viewAdversary
|
||||
},
|
||||
form: {
|
||||
handler: this._updateForm,
|
||||
submitOnChange: true,
|
||||
closeOnSubmit: false
|
||||
},
|
||||
dragDrop: [{ dragSelector: null, dropSelector: '.adversary-container' }]
|
||||
};
|
||||
|
||||
static PARTS = {
|
||||
header: { template: 'systems/daggerheart/templates/sheets/actors/environment/header.hbs' },
|
||||
tabs: { template: 'systems/daggerheart/templates/sheets/global/tabs/tab-navigation.hbs' },
|
||||
main: { template: 'systems/daggerheart/templates/sheets/actors/environment/main.hbs' },
|
||||
information: { template: 'systems/daggerheart/templates/sheets/actors/environment/information.hbs' }
|
||||
};
|
||||
|
||||
static TABS = {
|
||||
main: {
|
||||
active: true,
|
||||
cssClass: '',
|
||||
group: 'primary',
|
||||
id: 'main',
|
||||
icon: null,
|
||||
label: 'DAGGERHEART.Sheets.Environment.Tabs.Main'
|
||||
},
|
||||
information: {
|
||||
active: false,
|
||||
cssClass: '',
|
||||
group: 'primary',
|
||||
id: 'information',
|
||||
icon: null,
|
||||
label: 'DAGGERHEART.Sheets.Environment.Tabs.Information'
|
||||
}
|
||||
};
|
||||
|
||||
async _prepareContext(_options) {
|
||||
const context = await super._prepareContext(_options);
|
||||
context.document = this.document;
|
||||
context.tabs = super._getTabs(this.constructor.TABS);
|
||||
context.getEffectDetails = this.getEffectDetails.bind(this);
|
||||
|
||||
return context;
|
||||
}
|
||||
|
||||
static async _updateForm(event, _, formData) {
|
||||
await this.document.update(formData.object);
|
||||
this.render();
|
||||
}
|
||||
|
||||
getEffectDetails(id) {
|
||||
return {};
|
||||
}
|
||||
|
||||
static async addAdversary() {
|
||||
await this.document.update({
|
||||
[`system.potentialAdversaries.${foundry.utils.randomID()}.label`]: game.i18n.localize(
|
||||
'DAGGERHEART.Sheets.Environment.newAdversary'
|
||||
)
|
||||
});
|
||||
this.render();
|
||||
}
|
||||
|
||||
static async addFeature() {
|
||||
ui.notifications.error('Not Implemented yet. Awaiting datamodel rework');
|
||||
}
|
||||
|
||||
static async deleteProperty(_, target) {
|
||||
await this.document.update({ [`${target.dataset.path}.-=${target.id}`]: null });
|
||||
this.render();
|
||||
}
|
||||
|
||||
static async viewAdversary(_, button) {
|
||||
const adversary = foundry.utils.getProperty(
|
||||
this.document.system.potentialAdversaries,
|
||||
`${button.dataset.potentialAdversary}.adversaries.${button.dataset.adversary}`
|
||||
);
|
||||
adversary.sheet.render(true);
|
||||
}
|
||||
|
||||
async _onDrop(event) {
|
||||
const data = TextEditor.getDragEventData(event);
|
||||
const item = await fromUuid(data.uuid);
|
||||
if (item.type === 'adversary') {
|
||||
const target = event.target.closest('.adversary-container');
|
||||
const path = `system.potentialAdversaries.${target.dataset.potentialAdversary}.adversaries.${item.id}`;
|
||||
await this.document.update({
|
||||
[path]: item.uuid
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -135,20 +135,20 @@ export const adversaryTypes = {
|
|||
|
||||
export const environmentTypes = {
|
||||
exploration: {
|
||||
label: 'DAGGERHEART.Environment.Type.Exploration.label',
|
||||
description: 'DAGGERHEART.Environment.Type.Exploration.description'
|
||||
label: 'DAGGERHEART.Environment.Type.exploration.label',
|
||||
description: 'DAGGERHEART.Environment.Type.exploration.description'
|
||||
},
|
||||
social: {
|
||||
label: 'DAGGERHEART.Environment.Type.Social.label',
|
||||
description: 'DAGGERHEART.Environment.Type.Social.description'
|
||||
label: 'DAGGERHEART.Environment.Type.social.label',
|
||||
description: 'DAGGERHEART.Environment.Type.social.description'
|
||||
},
|
||||
traversal: {
|
||||
label: 'DAGGERHEART.Environment.Type.Traversal.label',
|
||||
description: 'DAGGERHEART.Environment.Type.Traversal.description'
|
||||
label: 'DAGGERHEART.Environment.Type.traversal.label',
|
||||
description: 'DAGGERHEART.Environment.Type.traversal.description'
|
||||
},
|
||||
event: {
|
||||
label: 'DAGGERHEART.Environment.Type.Event.label',
|
||||
description: 'DAGGERHEART.Environment.Type.Event.description'
|
||||
label: 'DAGGERHEART.Environment.Type.event.label',
|
||||
description: 'DAGGERHEART.Environment.Type.event.description'
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
import { environmentTypes } from '../../config/actorConfig.mjs';
|
||||
import BaseDataActor from './base.mjs';
|
||||
import ForeignDocumentUUIDField from '../fields/foreignDocumentUUIDField.mjs';
|
||||
import ActionField from '../fields/actionField.mjs';
|
||||
import ForeignDocumentUUIDArrayField from '../fields/foreignDocumentUUIDArrayField.mjs';
|
||||
|
||||
export default class DhEnvironment extends BaseDataActor {
|
||||
static LOCALIZATION_PREFIXES = ['DAGGERHEART.Sheets.Environment'];
|
||||
|
|
@ -21,15 +23,17 @@ export default class DhEnvironment extends BaseDataActor {
|
|||
initial: SYSTEM.GENERAL.tiers.tier1.id
|
||||
}),
|
||||
type: new fields.StringField({ choices: environmentTypes }),
|
||||
impulses: new fields.HTMLField(),
|
||||
description: new fields.StringField(),
|
||||
impulses: new fields.StringField(),
|
||||
difficulty: new fields.NumberField({ required: true, initial: 11, integer: true }),
|
||||
potentialAdversaries: new fields.TypedObjectField(
|
||||
new fields.SchemaField({
|
||||
label: new fields.StringField(),
|
||||
adversaries: new fields.TypedObjectField(new ForeignDocumentUUIDField({ type: 'Actor' }))
|
||||
adversaries: new ForeignDocumentUUIDArrayField({ type: 'Actor' })
|
||||
})
|
||||
)
|
||||
/* Features pending datamodel rework */
|
||||
),
|
||||
actions: new fields.ArrayField(new ActionField()),
|
||||
notes: new fields.HTMLField()
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue