mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-12 03:31:07 +01:00
Feature/238 companion sheet template (#252)
* new companion sheet templates * Data fixes * Changed from evasion.value to evasion.total in display * add attack config and disable experience value input --------- Co-authored-by: WBHarry <williambjrklund@gmail.com>
This commit is contained in:
parent
1b9bd45e9c
commit
cae659b9a5
21 changed files with 1027 additions and 106 deletions
|
|
@ -1,6 +1,6 @@
|
|||
export { default as DhCharacterSheet } from './sheets/actors/character.mjs';
|
||||
export { default as DhpAdversarySheet } from './sheets/actors/adversary.mjs';
|
||||
export { default as DhCompanionSheet } from './sheets/companion.mjs';
|
||||
export { default as DhCompanionSheet } from './sheets/actors/companion.mjs';
|
||||
export { default as DhpClassSheet } from './sheets/items/class.mjs';
|
||||
export { default as DhpSubclass } from './sheets/items/subclass.mjs';
|
||||
export { default as DhpFeatureSheet } from './sheets/items/feature.mjs';
|
||||
|
|
|
|||
108
module/applications/sheets/actors/companion.mjs
Normal file
108
module/applications/sheets/actors/companion.mjs
Normal file
|
|
@ -0,0 +1,108 @@
|
|||
import DaggerheartSheet from '../daggerheart-sheet.mjs';
|
||||
import DHCompanionSettings from '../applications/companion-settings.mjs';
|
||||
|
||||
const { ActorSheetV2 } = foundry.applications.sheets;
|
||||
export default class DhCompanionSheet extends DaggerheartSheet(ActorSheetV2) {
|
||||
static DEFAULT_OPTIONS = {
|
||||
tag: 'form',
|
||||
classes: ['daggerheart', 'sheet', 'actor', 'dh-style', 'companion'],
|
||||
position: { width: 300 },
|
||||
actions: {
|
||||
viewActor: this.viewActor,
|
||||
openSettings: this.openSettings,
|
||||
useItem: this.useItem,
|
||||
toChat: this.toChat
|
||||
},
|
||||
form: {
|
||||
handler: this.updateForm,
|
||||
submitOnChange: true,
|
||||
closeOnSubmit: false
|
||||
}
|
||||
};
|
||||
|
||||
static PARTS = {
|
||||
header: { template: 'systems/daggerheart/templates/sheets/actors/companion/header.hbs' },
|
||||
details: { template: 'systems/daggerheart/templates/sheets/actors/companion/details.hbs' },
|
||||
effects: { template: 'systems/daggerheart/templates/sheets/actors/companion/effects.hbs' }
|
||||
};
|
||||
|
||||
static TABS = {
|
||||
details: {
|
||||
active: true,
|
||||
cssClass: '',
|
||||
group: 'primary',
|
||||
id: 'details',
|
||||
icon: null,
|
||||
label: 'DAGGERHEART.General.tabs.details'
|
||||
},
|
||||
effects: {
|
||||
active: false,
|
||||
cssClass: '',
|
||||
group: 'primary',
|
||||
id: 'effects',
|
||||
icon: null,
|
||||
label: 'DAGGERHEART.Sheets.PC.Tabs.effects'
|
||||
}
|
||||
};
|
||||
|
||||
async _prepareContext(_options) {
|
||||
const context = await super._prepareContext(_options);
|
||||
context.document = this.document;
|
||||
context.tabs = super._getTabs(this.constructor.TABS);
|
||||
|
||||
return context;
|
||||
}
|
||||
|
||||
static async updateForm(event, _, formData) {
|
||||
await this.document.update(formData.object);
|
||||
this.render();
|
||||
}
|
||||
|
||||
static 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);
|
||||
}
|
||||
|
||||
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 useItem(event) {
|
||||
const action = this.getAction(event) ?? this.actor.system.attack;
|
||||
action.use(event);
|
||||
}
|
||||
|
||||
static async toChat(event, button) {
|
||||
if (button?.dataset?.type === 'experience') {
|
||||
const experience = this.document.system.experiences[button.dataset.uuid];
|
||||
const cls = getDocumentClass('ChatMessage');
|
||||
const systemData = {
|
||||
name: game.i18n.localize('DAGGERHEART.General.Experience.Single'),
|
||||
description: `${experience.name} ${experience.total < 0 ? experience.total : `+${experience.total}`}`
|
||||
};
|
||||
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 {
|
||||
const item = this.getAction(event) ?? this.document.system.attack;
|
||||
item.toChat(this.document.id);
|
||||
}
|
||||
}
|
||||
|
||||
static async openSettings() {
|
||||
await new DHCompanionSettings(this.document).render(true);
|
||||
}
|
||||
}
|
||||
160
module/applications/sheets/applications/companion-settings.mjs
Normal file
160
module/applications/sheets/applications/companion-settings.mjs
Normal file
|
|
@ -0,0 +1,160 @@
|
|||
import { GMUpdateEvent, socketEvent } from '../../../helpers/socket.mjs';
|
||||
import DhCompanionlevelUp from '../../levelup/companionLevelup.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.Sheets.TABS.settings')}`;
|
||||
}
|
||||
|
||||
static DEFAULT_OPTIONS = {
|
||||
tag: 'form',
|
||||
classes: ['daggerheart', 'dh-style', 'dialog', 'companion-settings'],
|
||||
window: {
|
||||
icon: 'fa-solid fa-wrench',
|
||||
resizable: false
|
||||
},
|
||||
position: { width: 455, height: 'auto' },
|
||||
actions: {
|
||||
levelUp: this.levelUp
|
||||
},
|
||||
form: {
|
||||
handler: this.updateForm,
|
||||
submitOnChange: true,
|
||||
closeOnSubmit: false
|
||||
}
|
||||
};
|
||||
|
||||
static PARTS = {
|
||||
header: {
|
||||
id: 'header',
|
||||
template: 'systems/daggerheart/templates/sheets/applications/companion-settings/header.hbs'
|
||||
},
|
||||
tabs: { template: 'systems/daggerheart/templates/sheets/global/tabs/tab-navigation.hbs' },
|
||||
details: {
|
||||
id: 'details',
|
||||
template: 'systems/daggerheart/templates/sheets/applications/companion-settings/details.hbs'
|
||||
},
|
||||
experiences: {
|
||||
id: 'experiences',
|
||||
template: 'systems/daggerheart/templates/sheets/applications/companion-settings/experiences.hbs'
|
||||
},
|
||||
attack: {
|
||||
id: 'attack',
|
||||
template: 'systems/daggerheart/templates/sheets/applications/companion-settings/attack.hbs'
|
||||
}
|
||||
};
|
||||
|
||||
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'
|
||||
}
|
||||
};
|
||||
|
||||
_attachPartListeners(partId, htmlElement, options) {
|
||||
super._attachPartListeners(partId, htmlElement, options);
|
||||
|
||||
htmlElement.querySelector('.partner-value')?.addEventListener('change', this.onPartnerChange.bind(this));
|
||||
}
|
||||
|
||||
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)
|
||||
)
|
||||
.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;
|
||||
}
|
||||
|
||||
async onPartnerChange(event) {
|
||||
const partnerDocument = event.target.value
|
||||
? await foundry.utils.fromUuid(event.target.value)
|
||||
: this.actor.system.partner;
|
||||
const partnerUpdate = { 'system.companion': event.target.value ? this.actor.uuid : null };
|
||||
|
||||
if (!partnerDocument.testUserPermission(game.user, CONST.DOCUMENT_OWNERSHIP_LEVELS.OWNER)) {
|
||||
await game.socket.emit(`system.${SYSTEM.id}`, {
|
||||
action: socketEvent.GMUpdate,
|
||||
data: {
|
||||
action: GMUpdateEvent.UpdateDocument,
|
||||
uuid: partnerDocument.uuid,
|
||||
update: update
|
||||
}
|
||||
});
|
||||
} else {
|
||||
await partnerDocument.update(partnerUpdate);
|
||||
}
|
||||
|
||||
await this.actor.update({ 'system.partner': event.target.value });
|
||||
|
||||
if (!event.target.value) {
|
||||
await this.actor.updateLevel(1);
|
||||
}
|
||||
|
||||
this.render();
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,86 +0,0 @@
|
|||
import { GMUpdateEvent, socketEvent } from '../../helpers/socket.mjs';
|
||||
import DhCompanionlevelUp from '../levelup/companionLevelup.mjs';
|
||||
import DaggerheartSheet from './daggerheart-sheet.mjs';
|
||||
|
||||
const { ActorSheetV2 } = foundry.applications.sheets;
|
||||
export default class DhCompanionSheet extends DaggerheartSheet(ActorSheetV2) {
|
||||
static DEFAULT_OPTIONS = {
|
||||
tag: 'form',
|
||||
classes: ['daggerheart', 'sheet', 'actor', 'dh-style', 'companion'],
|
||||
position: { width: 700, height: 1000 },
|
||||
actions: {
|
||||
attackRoll: this.attackRoll,
|
||||
levelUp: this.levelUp
|
||||
},
|
||||
form: {
|
||||
handler: this.updateForm,
|
||||
submitOnChange: true,
|
||||
closeOnSubmit: false
|
||||
}
|
||||
};
|
||||
|
||||
static PARTS = {
|
||||
sidebar: { template: 'systems/daggerheart/templates/sheets/actors/companion/tempMain.hbs' }
|
||||
};
|
||||
|
||||
_attachPartListeners(partId, htmlElement, options) {
|
||||
super._attachPartListeners(partId, htmlElement, options);
|
||||
|
||||
htmlElement.querySelector('.partner-value')?.addEventListener('change', this.onPartnerChange.bind(this));
|
||||
}
|
||||
|
||||
async _prepareContext(_options) {
|
||||
const context = await super._prepareContext(_options);
|
||||
context.document = this.document;
|
||||
context.playerCharacters = game.actors
|
||||
.filter(
|
||||
x =>
|
||||
x.type === 'character' &&
|
||||
(x.ownership.default === 3 ||
|
||||
x.ownership[game.user.id] === 3 ||
|
||||
this.document.system.partner?.uuid === x.uuid)
|
||||
)
|
||||
.map(x => ({ key: x.uuid, name: x.name }));
|
||||
|
||||
return context;
|
||||
}
|
||||
|
||||
static async updateForm(event, _, formData) {
|
||||
await this.document.update(formData.object);
|
||||
this.render();
|
||||
}
|
||||
|
||||
async onPartnerChange(event) {
|
||||
const partnerDocument = event.target.value
|
||||
? await foundry.utils.fromUuid(event.target.value)
|
||||
: this.document.system.partner;
|
||||
const partnerUpdate = { 'system.companion': event.target.value ? this.document.uuid : null };
|
||||
|
||||
if (!partnerDocument.testUserPermission(game.user, CONST.DOCUMENT_OWNERSHIP_LEVELS.OWNER)) {
|
||||
await game.socket.emit(`system.${SYSTEM.id}`, {
|
||||
action: socketEvent.GMUpdate,
|
||||
data: {
|
||||
action: GMUpdateEvent.UpdateDocument,
|
||||
uuid: partnerDocument.uuid,
|
||||
update: update
|
||||
}
|
||||
});
|
||||
} else {
|
||||
await partnerDocument.update(partnerUpdate);
|
||||
}
|
||||
|
||||
await this.document.update({ 'system.partner': event.target.value });
|
||||
|
||||
if (!event.target.value) {
|
||||
await this.document.updateLevel(1);
|
||||
}
|
||||
}
|
||||
|
||||
static async attackRoll(event) {
|
||||
this.actor.system.attack.use(event);
|
||||
}
|
||||
|
||||
static async levelUp() {
|
||||
new DhCompanionlevelUp(this.document).render(true);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue