mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-11 19:25:21 +01:00
* start development * finish party members tab * start resources tab * finish resources tab * finish inventory tab and add inital template to projects tab * add resource buttons actions methods * add group roll dialog * Main implementation * Fixed costs * Minor fixes and tweaks for the party sheet (#1239) * Minor fixes and tweaks for the party sheet * Fix scroll restoration for party sheet tabs * Finished GroupRoll * Removed/commented-out not yet implemented things * Commented out Difficulty since it's not used yet * Re-render party when members update (#1242) * Fixed so style applies in preview chat message * Added the clown car * Fixed so items can be dropped into the Party sheet * Added delete icon to inventory * Fixed TokenHUD token property useage. Fixed skipping roll message * Added visible modifier to GroupRoll leader result * Leader roll displays the large result display right away after rolling * Corrected tokenHUD for non-player-tokens * Fixed clowncar tokenData * Fixed TagTeam roll message and sound * Removed final TagTeamRoll roll sound * [PR] [Party Sheets] Sidebar character sheet changes (#1249) * Something experimenting * I am silly (wearning Dunce hat) * Stressful task * Armor functional to be hit * CSS Changes to accomadate pip boy * last minute change to resource section for better visual feeling * restoring old css for toggle * Added setting to toggle pip/number display * toggle functionality added * Fixed light-mode in characterSheet * Fixed multi-row resource pips display for character * Fixed separators * Added pip-display to Adversary and Companion. Some fixing on armor display --------- Co-authored-by: WBHarry <williambjrklund@gmail.com> * Fixed party height and resource armor update * Fixed deletebutton padding * Only showing expand-me icon on InventoryItem if there is a description to show * . * Fixed menu icon to be beige instead of white in dark mode --------- Co-authored-by: moliloo <dev.murilobrito@gmail.com> Co-authored-by: Carlos Fernandez <CarlosFdez@users.noreply.github.com> Co-authored-by: Nikhil Nagarajan <potter.nikhil@gmail.com>
227 lines
8.5 KiB
JavaScript
227 lines
8.5 KiB
JavaScript
import { abilities } from '../../config/actorConfig.mjs';
|
|
|
|
const { ApplicationV2, HandlebarsApplicationMixin } = foundry.applications.api;
|
|
|
|
export default class D20RollDialog extends HandlebarsApplicationMixin(ApplicationV2) {
|
|
constructor(roll, config = {}, options = {}) {
|
|
super(options);
|
|
|
|
this.roll = roll;
|
|
this.config = config;
|
|
this.config.experiences = [];
|
|
this.reactionOverride = config.actionType === 'reaction';
|
|
|
|
if (config.source?.action) {
|
|
this.item = config.data.parent.items.get(config.source.item) ?? config.data.parent;
|
|
this.action =
|
|
config.data.attack?._id == config.source.action
|
|
? config.data.attack
|
|
: this.item.system.actionsList?.find(a => a.id === config.source.action);
|
|
}
|
|
}
|
|
|
|
static DEFAULT_OPTIONS = {
|
|
tag: 'form',
|
|
// id: 'roll-selection',
|
|
classes: ['daggerheart', 'dialog', 'dh-style', 'views', 'roll-selection'],
|
|
position: {
|
|
width: 'auto'
|
|
},
|
|
window: {
|
|
icon: 'fa-solid fa-dice'
|
|
},
|
|
actions: {
|
|
updateIsAdvantage: this.updateIsAdvantage,
|
|
selectExperience: this.selectExperience,
|
|
toggleReaction: this.toggleReaction,
|
|
toggleTagTeamRoll: this.toggleTagTeamRoll,
|
|
submitRoll: this.submitRoll
|
|
},
|
|
form: {
|
|
handler: this.updateRollConfiguration,
|
|
submitOnChange: true,
|
|
submitOnClose: false
|
|
}
|
|
};
|
|
|
|
get title() {
|
|
return `${this.config.title}${this.actor ? `: ${this.actor.name}` : ''}`;
|
|
}
|
|
|
|
get actor() {
|
|
return this.config?.data?.parent;
|
|
}
|
|
|
|
/** @override */
|
|
static PARTS = {
|
|
header: {
|
|
id: 'header',
|
|
template: 'systems/daggerheart/templates/dialogs/dice-roll/header.hbs'
|
|
},
|
|
rollSelection: {
|
|
id: 'rollSelection',
|
|
template: 'systems/daggerheart/templates/dialogs/dice-roll/rollSelection.hbs'
|
|
}
|
|
};
|
|
|
|
async _prepareContext(_options) {
|
|
const context = await super._prepareContext(_options);
|
|
context.rollConfig = this.config;
|
|
context.hasRoll = !!this.config.roll;
|
|
context.canRoll = true;
|
|
context.selectedRollMode = this.config.selectedRollMode ?? game.settings.get('core', 'rollMode');
|
|
context.rollModes = Object.entries(CONFIG.Dice.rollModes).map(([action, { label, icon }]) => ({
|
|
action,
|
|
label,
|
|
icon
|
|
}));
|
|
|
|
this.config.costs ??= [];
|
|
if (this.config.costs?.length) {
|
|
const updatedCosts = game.system.api.fields.ActionFields.CostField.calcCosts.call(
|
|
this.action ?? { actor: this.actor },
|
|
this.config.costs
|
|
);
|
|
context.costs = updatedCosts.map(x => ({
|
|
...x,
|
|
label: x.itemId
|
|
? this.action.parent.parent.name
|
|
: game.i18n.localize(CONFIG.DH.GENERAL.abilityCosts[x.key].label)
|
|
}));
|
|
context.canRoll = game.system.api.fields.ActionFields.CostField.hasCost.call(
|
|
this.action ?? { actor: this.actor },
|
|
updatedCosts
|
|
);
|
|
this.config.data.scale = this.config.costs[0].total;
|
|
}
|
|
if (this.config.uses?.max) {
|
|
context.uses = game.system.api.fields.ActionFields.UsesField.calcUses.call(this.action, this.config.uses);
|
|
context.canRoll =
|
|
context.canRoll &&
|
|
game.system.api.fields.ActionFields.UsesField.hasUses.call(this.action, context.uses);
|
|
}
|
|
if (this.roll) {
|
|
context.roll = this.roll;
|
|
context.rollType = this.roll?.constructor.name;
|
|
context.rallyDie = this.roll.rallyChoices;
|
|
const experiences = this.config.data?.experiences || {};
|
|
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;
|
|
context.diceOptions = CONFIG.DH.GENERAL.diceTypes;
|
|
context.isLite = this.config.roll?.lite;
|
|
context.extraFormula = this.config.extraFormula;
|
|
context.formula = this.roll.constructFormula(this.config);
|
|
if (this.actor.system.traits) context.abilities = this.getTraitModifiers();
|
|
|
|
context.showReaction = !this.config.roll?.type && context.rollType === 'DualityRoll';
|
|
context.reactionOverride = this.reactionOverride;
|
|
}
|
|
|
|
const tagTeamSetting = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.TagTeamRoll);
|
|
if (tagTeamSetting.members[this.actor.id] && !this.config.skips?.createMessage) {
|
|
context.activeTagTeamRoll = true;
|
|
context.tagTeamSelected = this.config.tagTeamSelected;
|
|
}
|
|
|
|
return context;
|
|
}
|
|
|
|
getTraitModifiers() {
|
|
return Object.values(abilities).map(a => ({
|
|
id: a.id,
|
|
label: `${game.i18n.localize(a.label)} (${this.actor.system.traits[a.id]?.value.signedString() ?? 0})`
|
|
}));
|
|
}
|
|
|
|
static updateRollConfiguration(event, _, formData) {
|
|
const { ...rest } = foundry.utils.expandObject(formData.object);
|
|
|
|
this.config.selectedRollMode = rest.selectedRollMode;
|
|
|
|
if (this.config.costs) {
|
|
this.config.costs = foundry.utils.mergeObject(this.config.costs, rest.costs);
|
|
}
|
|
if (this.config.uses) this.config.uses = foundry.utils.mergeObject(this.config.uses, rest.uses);
|
|
if (rest.roll?.dice) {
|
|
Object.entries(rest.roll.dice).forEach(([key, value]) => {
|
|
this.roll[key] = value;
|
|
});
|
|
}
|
|
if (rest.hasOwnProperty('trait')) {
|
|
this.config.roll.trait = rest.trait;
|
|
this.config.title = game.i18n.format('DAGGERHEART.UI.Chat.dualityRoll.abilityCheckTitle', {
|
|
ability: game.i18n.localize(abilities[this.config.roll.trait]?.label)
|
|
});
|
|
}
|
|
this.config.extraFormula = rest.extraFormula;
|
|
this.render();
|
|
}
|
|
|
|
static updateIsAdvantage(_, button) {
|
|
const advantage = Number(button.dataset.advantage);
|
|
this.advantage = advantage === 1;
|
|
this.disadvantage = advantage === -1;
|
|
|
|
this.config.roll.advantage = this.config.roll.advantage === advantage ? 0 : advantage;
|
|
this.render();
|
|
}
|
|
|
|
static selectExperience(_, button) {
|
|
this.config.experiences =
|
|
this.config.experiences.indexOf(button.dataset.key) > -1
|
|
? this.config.experiences.filter(x => x !== button.dataset.key)
|
|
: [...this.config.experiences, button.dataset.key];
|
|
this.config.costs =
|
|
this.config.costs.indexOf(this.config.costs.find(c => c.extKey === button.dataset.key)) > -1
|
|
? this.config.costs.filter(x => x.extKey !== button.dataset.key)
|
|
: [
|
|
...this.config.costs,
|
|
{
|
|
extKey: button.dataset.key,
|
|
key: this.config?.data?.parent?.isNPC ? 'fear' : 'hope',
|
|
value: 1,
|
|
name: this.config.data?.experiences?.[button.dataset.key]?.name
|
|
}
|
|
];
|
|
this.render();
|
|
}
|
|
|
|
static toggleReaction() {
|
|
if (this.config.roll) {
|
|
this.reactionOverride = !this.reactionOverride;
|
|
this.config.actionType = this.reactionOverride
|
|
? CONFIG.DH.ITEM.actionTypes.reaction.id
|
|
: this.config.actionType === CONFIG.DH.ITEM.actionTypes.reaction.id
|
|
? null
|
|
: this.config.actionType;
|
|
this.render();
|
|
}
|
|
}
|
|
|
|
static toggleTagTeamRoll() {
|
|
this.config.tagTeamSelected = !this.config.tagTeamSelected;
|
|
this.render();
|
|
}
|
|
|
|
static async submitRoll() {
|
|
await this.close({ submitted: true });
|
|
}
|
|
|
|
/** @override */
|
|
_onClose(options = {}) {
|
|
if (!options.submitted) this.config = false;
|
|
}
|
|
|
|
static async configure(roll, config = {}, options = {}) {
|
|
return new Promise(resolve => {
|
|
const app = new this(roll, config, options);
|
|
app.addEventListener('close', () => resolve(app.config), { once: true });
|
|
app.render({ force: true });
|
|
});
|
|
}
|
|
}
|