mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-06-08 13:48:11 +02:00
Merge branch 'development' into feature/1383-Companion-Bonus-Levelups
This commit is contained in:
commit
2fcad0ff25
66 changed files with 1389 additions and 151 deletions
|
|
@ -1,5 +1,6 @@
|
|||
export { default as AttributionDialog } from './attributionDialog.mjs';
|
||||
export { default as BeastformDialog } from './beastformDialog.mjs';
|
||||
export { default as CharacterResetDialog } from './characterResetDialog.mjs';
|
||||
export { default as d20RollDialog } from './d20RollDialog.mjs';
|
||||
export { default as DamageDialog } from './damageDialog.mjs';
|
||||
export { default as DamageReductionDialog } from './damageReductionDialog.mjs';
|
||||
|
|
|
|||
105
module/applications/dialogs/characterResetDialog.mjs
Normal file
105
module/applications/dialogs/characterResetDialog.mjs
Normal file
|
|
@ -0,0 +1,105 @@
|
|||
const { ApplicationV2, HandlebarsApplicationMixin } = foundry.applications.api;
|
||||
|
||||
export default class CharacterResetDialog extends HandlebarsApplicationMixin(ApplicationV2) {
|
||||
constructor(actor, options = {}) {
|
||||
super(options);
|
||||
|
||||
this.actor = actor;
|
||||
this.data = {
|
||||
delete: {
|
||||
class: { keep: false, label: 'TYPES.Item.class' },
|
||||
subclass: { keep: false, label: 'TYPES.Item.subclass' },
|
||||
ancestry: { keep: false, label: 'TYPES.Item.ancestry' },
|
||||
community: { keep: false, label: 'TYPES.Item.community' }
|
||||
},
|
||||
optional: {
|
||||
portrait: { keep: true, label: 'DAGGERHEART.GENERAL.portrait' },
|
||||
name: { keep: true, label: 'Name' },
|
||||
biography: { keep: true, label: 'DAGGERHEART.GENERAL.Tabs.biography' },
|
||||
inventory: { keep: true, label: 'DAGGERHEART.GENERAL.inventory' }
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
static DEFAULT_OPTIONS = {
|
||||
tag: 'form',
|
||||
classes: ['daggerheart', 'dialog', 'dh-style', 'views', 'character-reset'],
|
||||
window: {
|
||||
icon: 'fa-solid fa-arrow-rotate-left',
|
||||
title: 'DAGGERHEART.APPLICATIONS.CharacterReset.title'
|
||||
},
|
||||
actions: {
|
||||
finishSelection: this.#finishSelection
|
||||
},
|
||||
form: {
|
||||
handler: this.updateData,
|
||||
submitOnChange: true,
|
||||
submitOnClose: false
|
||||
}
|
||||
};
|
||||
|
||||
/** @override */
|
||||
static PARTS = {
|
||||
resourceDice: {
|
||||
id: 'resourceDice',
|
||||
template: 'systems/daggerheart/templates/dialogs/characterReset.hbs'
|
||||
}
|
||||
};
|
||||
|
||||
async _prepareContext(_options) {
|
||||
const context = await super._prepareContext(_options);
|
||||
context.data = this.data;
|
||||
|
||||
return context;
|
||||
}
|
||||
|
||||
static async updateData(event, _, formData) {
|
||||
const { data } = foundry.utils.expandObject(formData.object);
|
||||
|
||||
this.data = foundry.utils.mergeObject(this.data, data);
|
||||
this.render();
|
||||
}
|
||||
|
||||
static getUpdateData() {
|
||||
const update = {};
|
||||
if (!this.data.optional.portrait) update.if(!this.data.optional.biography);
|
||||
|
||||
if (!this.data.optional.inventory) return update;
|
||||
}
|
||||
|
||||
static async #finishSelection() {
|
||||
const update = {};
|
||||
if (!this.data.optional.name.keep) {
|
||||
const defaultName = game.system.api.documents.DhpActor.defaultName({ type: 'character' });
|
||||
foundry.utils.setProperty(update, 'name', defaultName);
|
||||
foundry.utils.setProperty(update, 'prototypeToken.name', defaultName);
|
||||
}
|
||||
|
||||
if (!this.data.optional.portrait.keep) {
|
||||
foundry.utils.setProperty(update, 'img', this.actor.schema.fields.img.initial(this.actor));
|
||||
foundry.utils.setProperty(update, 'prototypeToken.==texture', {});
|
||||
foundry.utils.setProperty(update, 'prototypeToken.==ring', {});
|
||||
}
|
||||
|
||||
if (this.data.optional.biography.keep)
|
||||
foundry.utils.setProperty(update, 'system.biography', this.actor.system.biography);
|
||||
|
||||
if (this.data.optional.inventory.keep) foundry.utils.setProperty(update, 'system.gold', this.actor.system.gold);
|
||||
|
||||
const { system, ...rest } = update;
|
||||
await this.actor.update({
|
||||
...rest,
|
||||
'==system': system ?? {}
|
||||
});
|
||||
|
||||
const inventoryItemTypes = ['weapon', 'armor', 'consumable', 'loot'];
|
||||
await this.actor.deleteEmbeddedDocuments(
|
||||
'Item',
|
||||
this.actor.items
|
||||
.filter(x => !inventoryItemTypes.includes(x.type) || !this.data.optional.inventory.keep)
|
||||
.map(x => x.id)
|
||||
);
|
||||
|
||||
this.close();
|
||||
}
|
||||
}
|
||||
|
|
@ -109,11 +109,17 @@ export default class D20RollDialog extends HandlebarsApplicationMixin(Applicatio
|
|||
context.roll = this.roll;
|
||||
context.rollType = this.roll?.constructor.name;
|
||||
context.rallyDie = this.roll.rallyChoices;
|
||||
const experiences = this.config.data?.system?.experiences || {};
|
||||
|
||||
const actorExperiences = this.config.data?.system?.experiences || {};
|
||||
const companionExperiences = this.config.roll.companionRoll
|
||||
? (this.config.data?.companion?.system.experiences ?? {})
|
||||
: null;
|
||||
const experiences = companionExperiences ?? actorExperiences;
|
||||
context.experiences = Object.keys(experiences).map(id => ({
|
||||
id,
|
||||
...experiences[id]
|
||||
}));
|
||||
|
||||
context.selectedExperiences = this.config.experiences;
|
||||
context.advantage = this.config.roll?.advantage;
|
||||
context.disadvantage = this.config.roll?.disadvantage;
|
||||
|
|
|
|||
|
|
@ -54,10 +54,9 @@ export default class DhDeathMove extends HandlebarsApplicationMixin(ApplicationV
|
|||
|
||||
if (!config.roll.fate) return;
|
||||
|
||||
let returnMessage = game.i18n.localize('DAGGERHEART.UI.Chat.deathMove.avoidScar');
|
||||
if (config.roll.fate.value <= this.actor.system.levelData.level.current) {
|
||||
// apply scarring - for now directly apply - later add a button.
|
||||
const newScarAmount = this.actor.system.scars + 1;
|
||||
|
||||
await this.actor.update({
|
||||
system: {
|
||||
scars: newScarAmount
|
||||
|
|
@ -65,13 +64,15 @@ export default class DhDeathMove extends HandlebarsApplicationMixin(ApplicationV
|
|||
});
|
||||
|
||||
if (newScarAmount >= this.actor.system.resources.hope.max) {
|
||||
await this.actor.setDeathMoveDefeated(CONFIG.DH.GENERAL.defeatedConditionChoices.dead.id);
|
||||
return game.i18n.format('DAGGERHEART.UI.Chat.deathMove.journeysEnd', { scars: newScarAmount });
|
||||
}
|
||||
|
||||
return game.i18n.localize('DAGGERHEART.UI.Chat.deathMove.gainScar');
|
||||
returnMessage = game.i18n.localize('DAGGERHEART.UI.Chat.deathMove.gainScar');
|
||||
}
|
||||
|
||||
return game.i18n.localize('DAGGERHEART.UI.Chat.deathMove.avoidScar');
|
||||
await this.actor.setDeathMoveDefeated(CONFIG.DH.GENERAL.defeatedConditionChoices.unconscious.id);
|
||||
return returnMessage;
|
||||
}
|
||||
|
||||
async handleRiskItAll() {
|
||||
|
|
@ -84,6 +85,7 @@ export default class DhDeathMove extends HandlebarsApplicationMixin(ApplicationV
|
|||
label: game.i18n.localize('DAGGERHEART.GENERAL.dualityDice'),
|
||||
actionType: null,
|
||||
advantage: null,
|
||||
grantResources: false,
|
||||
customConfig: { skips: { resources: true, reaction: true } }
|
||||
});
|
||||
|
||||
|
|
@ -118,6 +120,7 @@ export default class DhDeathMove extends HandlebarsApplicationMixin(ApplicationV
|
|||
}
|
||||
|
||||
if (config.roll.result.duality == -1) {
|
||||
await this.actor.setDeathMoveDefeated(CONFIG.DH.GENERAL.defeatedConditionChoices.dead.id);
|
||||
chatMessage = game.i18n.localize('DAGGERHEART.UI.Chat.deathMove.riskItAllFailure');
|
||||
}
|
||||
|
||||
|
|
@ -141,6 +144,7 @@ export default class DhDeathMove extends HandlebarsApplicationMixin(ApplicationV
|
|||
}
|
||||
]);
|
||||
|
||||
await this.actor.setDeathMoveDefeated(CONFIG.DH.GENERAL.defeatedConditionChoices.dead.id);
|
||||
return game.i18n.localize('DAGGERHEART.UI.Chat.deathMove.blazeOfGlory');
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,8 @@ export default class DHTokenHUD extends foundry.applications.hud.TokenHUD {
|
|||
classes: ['daggerheart'],
|
||||
actions: {
|
||||
combat: DHTokenHUD.#onToggleCombat,
|
||||
togglePartyTokens: DHTokenHUD.#togglePartyTokens
|
||||
togglePartyTokens: DHTokenHUD.#togglePartyTokens,
|
||||
toggleCompanions: DHTokenHUD.#toggleCompanions
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -26,7 +27,7 @@ export default class DHTokenHUD extends foundry.applications.hud.TokenHUD {
|
|||
context.partyOnCanvas =
|
||||
this.actor.type === 'party' &&
|
||||
this.actor.system.partyMembers.some(member => member.getActiveTokens().length > 0);
|
||||
context.icons.toggleParty = 'systems/daggerheart/assets/icons/arrow-dunk.png';
|
||||
context.icons.toggleClowncar = 'systems/daggerheart/assets/icons/arrow-dunk.png';
|
||||
context.actorType = this.actor.type;
|
||||
context.usesEffects = this.actor.type !== 'party';
|
||||
context.canToggleCombat = DHTokenHUD.#nonCombatTypes.includes(this.actor.type)
|
||||
|
|
@ -56,6 +57,9 @@ export default class DHTokenHUD extends foundry.applications.hud.TokenHUD {
|
|||
}, {})
|
||||
: null;
|
||||
|
||||
context.hasCompanion = this.actor.system.companion;
|
||||
context.companionOnCanvas = context.hasCompanion && this.actor.system.companion.getActiveTokens().length > 0;
|
||||
|
||||
return context;
|
||||
}
|
||||
|
||||
|
|
@ -101,8 +105,24 @@ export default class DHTokenHUD extends foundry.applications.hud.TokenHUD {
|
|||
: 'DAGGERHEART.APPLICATIONS.HUD.tokenHUD.depositPartyTokens'
|
||||
);
|
||||
|
||||
await this.toggleClowncar(this.actor.system.partyMembers);
|
||||
}
|
||||
|
||||
static async #toggleCompanions(_, button) {
|
||||
const icon = button.querySelector('img');
|
||||
icon.classList.toggle('flipped');
|
||||
button.dataset.tooltip = game.i18n.localize(
|
||||
icon.classList.contains('flipped')
|
||||
? 'DAGGERHEART.APPLICATIONS.HUD.tokenHUD.retrieveCompanionTokens'
|
||||
: 'DAGGERHEART.APPLICATIONS.HUD.tokenHUD.depositCompanionTokens'
|
||||
);
|
||||
|
||||
await this.toggleClowncar([this.actor.system.companion]);
|
||||
}
|
||||
|
||||
async toggleClowncar(actors) {
|
||||
const animationDuration = 500;
|
||||
const activeTokens = this.actor.system.partyMembers.flatMap(member => member.getActiveTokens());
|
||||
const activeTokens = actors.flatMap(member => member.getActiveTokens());
|
||||
const { x: actorX, y: actorY } = this.document;
|
||||
if (activeTokens.length > 0) {
|
||||
for (let token of activeTokens) {
|
||||
|
|
@ -114,14 +134,15 @@ export default class DHTokenHUD extends foundry.applications.hud.TokenHUD {
|
|||
}
|
||||
} else {
|
||||
const activeScene = game.scenes.find(x => x.id === game.user.viewedScene);
|
||||
const partyTokenData = [];
|
||||
for (let member of this.actor.system.partyMembers) {
|
||||
const tokenData = [];
|
||||
for (let member of actors) {
|
||||
const data = await member.getTokenDocument();
|
||||
partyTokenData.push(data.toObject());
|
||||
tokenData.push(data.toObject());
|
||||
}
|
||||
|
||||
const newTokens = await activeScene.createEmbeddedDocuments(
|
||||
'Token',
|
||||
partyTokenData.map(tokenData => ({
|
||||
tokenData.map(tokenData => ({
|
||||
...tokenData,
|
||||
alpha: 0,
|
||||
x: actorX,
|
||||
|
|
|
|||
|
|
@ -65,8 +65,15 @@ export default class DhSceneConfigSettings extends foundry.applications.sheets.S
|
|||
const data = foundry.applications.ux.TextEditor.implementation.getDragEventData(event);
|
||||
const item = await foundry.utils.fromUuid(data.uuid);
|
||||
if (item instanceof game.system.api.documents.DhpActor && item.type === 'environment') {
|
||||
let sceneUuid = data.uuid;
|
||||
if (item.pack) {
|
||||
const inWorldActor = await game.system.api.documents.DhpActor.create([item.toObject()]);
|
||||
if (!inWorldActor.length) return;
|
||||
sceneUuid = inWorldActor[0].uuid;
|
||||
}
|
||||
|
||||
await this.daggerheartFlag.updateSource({
|
||||
sceneEnvironments: [...this.daggerheartFlag.sceneEnvironments, data.uuid]
|
||||
sceneEnvironments: [...this.daggerheartFlag.sceneEnvironments, sceneUuid]
|
||||
});
|
||||
this.render({ internalRefresh: true });
|
||||
}
|
||||
|
|
@ -97,6 +104,10 @@ export default class DhSceneConfigSettings extends foundry.applications.sheets.S
|
|||
/** @override */
|
||||
async _processSubmitData(event, form, submitData, options) {
|
||||
submitData.flags.daggerheart = this.daggerheartFlag.toObject();
|
||||
submitData.flags.daggerheart.sceneEnvironments = submitData.flags.daggerheart.sceneEnvironments.filter(x =>
|
||||
foundry.utils.fromUuidSync(x)
|
||||
);
|
||||
|
||||
for (const key of Object.keys(this.document._source.flags.daggerheart?.sceneEnvironments ?? {})) {
|
||||
if (!submitData.flags.daggerheart.sceneEnvironments[key]) {
|
||||
submitData.flags.daggerheart.sceneEnvironments[`-=${key}`] = null;
|
||||
|
|
|
|||
|
|
@ -36,7 +36,8 @@ export default class DhHomebrewSettings extends HandlebarsApplicationMixin(Appli
|
|||
addItem: this.addItem,
|
||||
editItem: this.editItem,
|
||||
removeItem: this.removeItem,
|
||||
resetMoves: this.resetMoves,
|
||||
resetDowntimeMoves: this.resetDowntimeMoves,
|
||||
resetItemFeatures: this.resetItemFeatures,
|
||||
addDomain: this.addDomain,
|
||||
toggleSelectedDomain: this.toggleSelectedDomain,
|
||||
deleteDomain: this.deleteDomain,
|
||||
|
|
@ -232,7 +233,7 @@ export default class DhHomebrewSettings extends HandlebarsApplicationMixin(Appli
|
|||
this.render();
|
||||
}
|
||||
|
||||
static async resetMoves(_, target) {
|
||||
static async resetDowntimeMoves(_, target) {
|
||||
const confirmed = await foundry.applications.api.DialogV2.confirm({
|
||||
window: {
|
||||
title: game.i18n.format('DAGGERHEART.SETTINGS.Homebrew.resetMovesTitle', {
|
||||
|
|
@ -266,7 +267,7 @@ export default class DhHomebrewSettings extends HandlebarsApplicationMixin(Appli
|
|||
...move,
|
||||
name: game.i18n.localize(move.name),
|
||||
description: game.i18n.localize(move.description),
|
||||
actions: move.actions.reduce((acc, key) => {
|
||||
actions: Object.keys(move.actions).reduce((acc, key) => {
|
||||
const action = move.actions[key];
|
||||
acc[key] = {
|
||||
...action,
|
||||
|
|
@ -293,6 +294,31 @@ export default class DhHomebrewSettings extends HandlebarsApplicationMixin(Appli
|
|||
this.render();
|
||||
}
|
||||
|
||||
static async resetItemFeatures(_, target) {
|
||||
const confirmed = await foundry.applications.api.DialogV2.confirm({
|
||||
window: {
|
||||
title: game.i18n.format('DAGGERHEART.SETTINGS.Homebrew.resetItemFeaturesTitle', {
|
||||
type: game.i18n.localize(`DAGGERHEART.GENERAL.${target.dataset.type}`)
|
||||
})
|
||||
},
|
||||
content: game.i18n.localize('DAGGERHEART.SETTINGS.Homebrew.resetMovesText')
|
||||
});
|
||||
|
||||
if (!confirmed) return;
|
||||
|
||||
await this.settings.updateSource({
|
||||
[`itemFeatures.${target.dataset.type}`]: Object.keys(
|
||||
this.settings.itemFeatures[target.dataset.type]
|
||||
).reduce((acc, key) => {
|
||||
acc[`-=${key}`] = null;
|
||||
|
||||
return acc;
|
||||
}, {})
|
||||
});
|
||||
|
||||
this.render();
|
||||
}
|
||||
|
||||
static async addDomain(event) {
|
||||
event.preventDefault();
|
||||
const content = new foundry.data.fields.StringField({
|
||||
|
|
|
|||
|
|
@ -125,6 +125,7 @@ export default class DHActionBaseConfig extends DaggerheartSheet(ApplicationV2)
|
|||
async _prepareContext(_options) {
|
||||
const context = await super._prepareContext(_options, 'action');
|
||||
context.source = this.action.toObject(true);
|
||||
context.action = this.action;
|
||||
|
||||
context.summons = [];
|
||||
for (const summon of context.source.summon ?? []) {
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
export * as actors from './actors/_module.mjs';
|
||||
export * as api from './api/_modules.mjs';
|
||||
export * as items from './items/_module.mjs';
|
||||
export * as rollTables from './rollTables/_module.mjs';
|
||||
|
|
|
|||
|
|
@ -669,26 +669,7 @@ export default class CharacterSheet extends DHBaseActorSheet {
|
|||
* Resets the character data and removes all embedded documents.
|
||||
*/
|
||||
static async #resetCharacter() {
|
||||
const confirmed = await foundry.applications.api.DialogV2.confirm({
|
||||
window: {
|
||||
title: game.i18n.localize('DAGGERHEART.ACTORS.Character.resetCharacterConfirmationTitle')
|
||||
},
|
||||
content: game.i18n.localize('DAGGERHEART.ACTORS.Character.resetCharacterConfirmationContent')
|
||||
});
|
||||
|
||||
if (!confirmed) return;
|
||||
|
||||
await this.document.update({
|
||||
'==system': {}
|
||||
});
|
||||
await this.document.deleteEmbeddedDocuments(
|
||||
'Item',
|
||||
this.document.items.map(x => x.id)
|
||||
);
|
||||
await this.document.deleteEmbeddedDocuments(
|
||||
'ActiveEffect',
|
||||
this.document.effects.map(x => x.id)
|
||||
);
|
||||
new game.system.api.applications.dialogs.CharacterResetDialog(this.document).render({ force: true });
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -753,8 +734,9 @@ export default class CharacterSheet extends DHBaseActorSheet {
|
|||
if (!result) return;
|
||||
|
||||
/* This could be avoided by baking config.costs into config.resourceUpdates. Didn't feel like messing with it at the time */
|
||||
const costResources = result.costs?.filter(x => x.enabled)
|
||||
.map(cost => ({ ...cost, value: -cost.value, total: -cost.total })) || {};
|
||||
const costResources =
|
||||
result.costs?.filter(x => x.enabled).map(cost => ({ ...cost, value: -cost.value, total: -cost.total })) ||
|
||||
{};
|
||||
config.resourceUpdates.addResources(costResources);
|
||||
await config.resourceUpdates.updateResources();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -62,10 +62,10 @@ export default class DhCompanionSheet extends DHBaseActorSheet {
|
|||
title: `${game.i18n.localize('DAGGERHEART.GENERAL.Roll.action')}: ${this.actor.name}`,
|
||||
headerTitle: `Companion ${game.i18n.localize('DAGGERHEART.GENERAL.Roll.action')}`,
|
||||
roll: {
|
||||
trait: partner.system.spellcastModifierTrait?.key
|
||||
trait: partner.system.spellcastModifierTrait?.key,
|
||||
companionRoll: true
|
||||
},
|
||||
hasRoll: true,
|
||||
data: partner.getRollData()
|
||||
hasRoll: true
|
||||
};
|
||||
|
||||
const result = await partner.diceRoll(config);
|
||||
|
|
|
|||
|
|
@ -600,7 +600,7 @@ export default function DHApplicationMixin(Base) {
|
|||
{
|
||||
relativeTo: isAction ? doc.parent : doc,
|
||||
rollData: doc.getRollData?.(),
|
||||
secrets: isAction ? doc.parent.isOwner : doc.isOwner
|
||||
secrets: isAction ? doc.parent.parent.isOwner : doc.isOwner
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
|||
1
module/applications/sheets/rollTables/_module.mjs
Normal file
1
module/applications/sheets/rollTables/_module.mjs
Normal file
|
|
@ -0,0 +1 @@
|
|||
export { default as RollTableSheet } from './rollTable.mjs';
|
||||
191
module/applications/sheets/rollTables/rollTable.mjs
Normal file
191
module/applications/sheets/rollTables/rollTable.mjs
Normal file
|
|
@ -0,0 +1,191 @@
|
|||
export default class DhRollTableSheet extends foundry.applications.sheets.RollTableSheet {
|
||||
static DEFAULT_OPTIONS = {
|
||||
...super.DEFAULT_OPTIONS,
|
||||
actions: {
|
||||
changeMode: DhRollTableSheet.#onChangeMode,
|
||||
drawResult: DhRollTableSheet.#onDrawResult,
|
||||
resetResults: DhRollTableSheet.#onResetResults,
|
||||
addFormula: DhRollTableSheet.#addFormula,
|
||||
removeFormula: DhRollTableSheet.#removeFormula
|
||||
}
|
||||
};
|
||||
|
||||
static buildParts() {
|
||||
const { footer, header, sheet, results, ...parts } = super.PARTS;
|
||||
return {
|
||||
sheet: {
|
||||
...sheet,
|
||||
template: 'systems/daggerheart/templates/sheets/rollTable/sheet.hbs'
|
||||
},
|
||||
header: { template: 'systems/daggerheart/templates/sheets/rollTable/header.hbs' },
|
||||
...parts,
|
||||
results: {
|
||||
template: 'systems/daggerheart/templates/sheets/rollTable/results.hbs',
|
||||
templates: ['templates/sheets/roll-table/result-details.hbs'],
|
||||
scrollable: ['table[data-results] tbody']
|
||||
},
|
||||
summary: { template: 'systems/daggerheart/templates/sheets/rollTable/summary.hbs' },
|
||||
footer
|
||||
};
|
||||
}
|
||||
|
||||
static PARTS = DhRollTableSheet.buildParts();
|
||||
|
||||
async _preRender(context, options) {
|
||||
await super._preRender(context, options);
|
||||
|
||||
if (!options.internalRefresh)
|
||||
this.daggerheartFlag = new game.system.api.data.DhRollTable(this.document.flags.daggerheart);
|
||||
}
|
||||
|
||||
/* root PART has a blank element on _attachPartListeners, so it cannot be used to set the eventListeners for the view mode */
|
||||
async _onRender(context, options) {
|
||||
super._onRender(context, options);
|
||||
|
||||
for (const element of this.element.querySelectorAll('.system-update-field'))
|
||||
element.addEventListener('change', this.updateSystemField.bind(this));
|
||||
}
|
||||
|
||||
async _preparePartContext(partId, context, options) {
|
||||
context = await super._preparePartContext(partId, context, options);
|
||||
|
||||
switch (partId) {
|
||||
case 'sheet':
|
||||
context.altFormula = this.daggerheartFlag.altFormula;
|
||||
context.usesAltFormula = Object.keys(this.daggerheartFlag.altFormula).length > 0;
|
||||
context.altFormulaOptions = {
|
||||
'': { name: this.daggerheartFlag.formulaName },
|
||||
...this.daggerheartFlag.altFormula
|
||||
};
|
||||
context.activeAltFormula = this.daggerheartFlag.activeAltFormula;
|
||||
context.selectedFormula = this.daggerheartFlag.getActiveFormula(this.document.formula);
|
||||
context.results = this.getExtendedResults(context.results);
|
||||
break;
|
||||
case 'header':
|
||||
context.altFormula = this.daggerheartFlag.altFormula;
|
||||
context.usesAltFormula = Object.keys(this.daggerheartFlag.altFormula).length > 0;
|
||||
context.altFormulaOptions = {
|
||||
'': { name: this.daggerheartFlag.formulaName },
|
||||
...this.daggerheartFlag.altFormula
|
||||
};
|
||||
context.activeAltFormula = this.daggerheartFlag.activeAltFormula;
|
||||
break;
|
||||
case 'summary':
|
||||
context.systemFields = this.daggerheartFlag.schema.fields;
|
||||
context.altFormula = this.daggerheartFlag.altFormula;
|
||||
context.formulaName = this.daggerheartFlag.formulaName;
|
||||
break;
|
||||
case 'results':
|
||||
context.results = this.getExtendedResults(context.results);
|
||||
break;
|
||||
}
|
||||
|
||||
return context;
|
||||
}
|
||||
|
||||
getExtendedResults(results) {
|
||||
const bodyDarkMode = document.body.classList.contains('theme-dark');
|
||||
const elementLightMode = this.element.classList.contains('theme-light');
|
||||
const elementDarkMode = this.element.classList.contains('theme-dark');
|
||||
const isDarkMode = elementDarkMode || (!elementLightMode && bodyDarkMode);
|
||||
|
||||
return results.map(x => ({
|
||||
...x,
|
||||
displayImg: isDarkMode && x.img === 'icons/svg/d20-black.svg' ? 'icons/svg/d20.svg' : x.img
|
||||
}));
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
/* Flag SystemData update methods */
|
||||
/* -------------------------------------------- */
|
||||
|
||||
async updateSystemField(event) {
|
||||
const { dataset, value } = event.target;
|
||||
await this.daggerheartFlag.updateSource({ [dataset.path]: value });
|
||||
this.render({ internalRefresh: true });
|
||||
}
|
||||
|
||||
getSystemFlagUpdate() {
|
||||
const deleteUpdate = Object.keys(this.document._source.flags.daggerheart?.altFormula ?? {}).reduce(
|
||||
(acc, formulaKey) => {
|
||||
if (!this.daggerheartFlag.altFormula[formulaKey]) acc.altFormula[`-=${formulaKey}`] = null;
|
||||
|
||||
return acc;
|
||||
},
|
||||
{ altFormula: {} }
|
||||
);
|
||||
|
||||
return { ['flags.daggerheart']: foundry.utils.mergeObject(this.daggerheartFlag.toObject(), deleteUpdate) };
|
||||
}
|
||||
|
||||
static async #addFormula() {
|
||||
await this.daggerheartFlag.updateSource({
|
||||
[`altFormula.${foundry.utils.randomID()}`]: game.system.api.data.DhRollTable.getDefaultFormula()
|
||||
});
|
||||
this.render({ internalRefresh: true });
|
||||
}
|
||||
|
||||
static async #removeFormula(_event, target) {
|
||||
await this.daggerheartFlag.updateSource({
|
||||
[`altFormula.-=${target.dataset.key}`]: null
|
||||
});
|
||||
this.render({ internalRefresh: true });
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
/* Extended RollTable methods */
|
||||
/* -------------------------------------------- */
|
||||
|
||||
/**
|
||||
* Alternate between view and edit modes.
|
||||
* @this {RollTableSheet}
|
||||
* @type {ApplicationClickAction}
|
||||
*/
|
||||
static async #onChangeMode() {
|
||||
this.mode = this.isEditMode ? 'view' : 'edit';
|
||||
await this.document.update(this.getSystemFlagUpdate());
|
||||
await this.render({ internalRefresh: true });
|
||||
}
|
||||
|
||||
/** @inheritdoc */
|
||||
async _processSubmitData(event, form, submitData, options) {
|
||||
/* RollTable sends an empty dummy event when swapping from view/edit first time */
|
||||
if (Object.keys(submitData).length) {
|
||||
if (!submitData.flags) submitData.flags = { daggerheart: {} };
|
||||
submitData.flags.daggerheart = this.getSystemFlagUpdate();
|
||||
}
|
||||
|
||||
super._processSubmitData(event, form, submitData, options);
|
||||
}
|
||||
|
||||
/** @inheritdoc */
|
||||
static async #onResetResults() {
|
||||
await this.document.update(this.getSystemFlagUpdate());
|
||||
await this.document.resetResults();
|
||||
}
|
||||
|
||||
/**
|
||||
* Roll and draw a TableResult.
|
||||
* @this {RollTableSheet}
|
||||
* @type {ApplicationClickAction}
|
||||
*/
|
||||
static async #onDrawResult(_event, button) {
|
||||
if (this.form) await this.submit({ operation: { render: false } });
|
||||
button.disabled = true;
|
||||
const table = this.document;
|
||||
|
||||
await this.document.update(this.getSystemFlagUpdate());
|
||||
|
||||
/* Sending in the currently selectd activeFormula to table.roll to use as the formula */
|
||||
const selectedFormula = this.daggerheartFlag.getActiveFormula(this.document.formula);
|
||||
const tableRoll = await table.roll({ selectedFormula });
|
||||
const draws = table.getResultsForRoll(tableRoll.roll.total);
|
||||
if (draws.length > 0) {
|
||||
if (game.settings.get('core', 'animateRollTable')) await this._animateRoll(draws);
|
||||
await table.draw(tableRoll);
|
||||
}
|
||||
|
||||
// Reenable the button if drawing with replacement since the draw won't trigger a sheet re-render
|
||||
if (table.replacement) button.disabled = false;
|
||||
}
|
||||
}
|
||||
|
|
@ -42,8 +42,8 @@ export default class DhCombatTracker extends foundry.applications.sidebar.tabs.C
|
|||
this.combats
|
||||
.find(x => x.active)
|
||||
?.system?.extendedBattleToggles?.reduce((acc, toggle) => (acc ?? 0) + toggle.category, null) ?? null;
|
||||
const maxBP = CONFIG.DH.ENCOUNTER.BaseBPPerEncounter(context.characters.length) + modifierBP;
|
||||
const currentBP = AdversaryBPPerEncounter(context.adversaries, context.characters);
|
||||
const maxBP = CONFIG.DH.ENCOUNTER.BaseBPPerEncounter(context.allCharacters.length) + modifierBP;
|
||||
const currentBP = AdversaryBPPerEncounter(context.adversaries, context.allCharacters);
|
||||
|
||||
Object.assign(context, {
|
||||
fear: game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Resources.Fear),
|
||||
|
|
@ -73,9 +73,8 @@ export default class DhCombatTracker extends foundry.applications.sidebar.tabs.C
|
|||
Object.assign(context, {
|
||||
actionTokens: game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.variantRules).actionTokens,
|
||||
adversaries,
|
||||
characters: characters
|
||||
?.filter(x => !x.isNPC)
|
||||
.filter(x => !spotlightQueueEnabled || x.system.spotlight.requestOrderIndex == 0),
|
||||
allCharacters: characters,
|
||||
characters: characters.filter(x => !spotlightQueueEnabled || x.system.spotlight.requestOrderIndex == 0),
|
||||
spotlightRequests
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -76,6 +76,8 @@ export default class DhEffectsDisplay extends HandlebarsApplicationMixin(Applica
|
|||
};
|
||||
|
||||
toggleHidden(token, focused) {
|
||||
if (!this.element) return;
|
||||
|
||||
const effects = DhEffectsDisplay.getTokenEffects(focused ? token : null);
|
||||
this.element.hidden = effects.length === 0;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue