Added action tokens and Request functionality

This commit is contained in:
WBHarry 2025-06-06 21:09:14 +02:00
parent 0f77697614
commit 0ca0ab360e
14 changed files with 340 additions and 28 deletions

View file

@ -1,5 +1,7 @@
import DhAppearance from '../data/settings/Appearance.mjs';
import DHAppearanceSettings from './settings/appearanceSettings.mjs';
import DhVariantRules from '../data/settings/VariantRules.mjs';
import DHVariantRuleSettings from './settings/variantRuleSettings.mjs';
class DhpAutomationSettings extends FormApplication {
constructor(object = {}, options = {}) {
@ -181,7 +183,8 @@ export const registerDHSettings = () => {
type: Number,
default: 0,
onChange: () => {
if(ui.resources) ui.resources.render({force: true});
if (ui.resources) ui.resources.render({ force: true });
ui.combat.render({ force: true });
}
});
@ -193,7 +196,7 @@ export const registerDHSettings = () => {
type: Number,
default: 12,
onChange: () => {
if(ui.resources) ui.resources.render({force: true});
if (ui.resources) ui.resources.render({ force: true });
}
});
@ -204,15 +207,15 @@ export const registerDHSettings = () => {
config: true,
type: String,
choices: {
'token': 'Tokens',
'bar': 'Bar',
'hide': 'Hide'
token: 'Tokens',
bar: 'Bar',
hide: 'Hide'
},
default: 'token',
onChange: value => {
if(ui.resources) {
if(value === 'hide') ui.resources.close({allowed: true});
else ui.resources.render({force: true});
if (ui.resources) {
if (value === 'hide') ui.resources.close({ allowed: true });
else ui.resources.render({ force: true });
}
}
});
@ -251,6 +254,13 @@ export const registerDHSettings = () => {
}
});
game.settings.register(SYSTEM.id, SYSTEM.SETTINGS.gameSettings.variantRules, {
scope: 'world',
config: false,
type: DhVariantRules,
default: DhVariantRules.defaultSchema
});
game.settings.register(SYSTEM.id, SYSTEM.SETTINGS.gameSettings.appearance, {
scope: 'client',
config: false,
@ -291,4 +301,13 @@ export const registerDHSettings = () => {
type: DHAppearanceSettings,
restricted: false
});
game.settings.registerMenu(SYSTEM.id, SYSTEM.SETTINGS.menu.VariantRules.Name, {
name: game.i18n.localize('DAGGERHEART.Settings.Menu.VariantRules.title'),
label: game.i18n.localize('DAGGERHEART.Settings.Menu.VariantRules.label'),
hint: game.i18n.localize('DAGGERHEART.Settings.Menu.VariantRules.hint'),
icon: SYSTEM.SETTINGS.menu.VariantRules.Icon,
type: DHVariantRuleSettings,
restricted: false
});
};

View file

@ -0,0 +1,59 @@
import DhVariantRules from '../../data/settings/VariantRules.mjs';
const { HandlebarsApplicationMixin, ApplicationV2 } = foundry.applications.api;
export default class DHVariantRuleSettings extends HandlebarsApplicationMixin(ApplicationV2) {
constructor() {
super({});
this.settings = new DhVariantRules(
game.settings.get(SYSTEM.id, SYSTEM.SETTINGS.gameSettings.variantRules).toObject()
);
}
get title() {
return game.i18n.localize('DAGGERHEART.Settings.Menu.VariantRules.name');
}
static DEFAULT_OPTIONS = {
tag: 'form',
id: 'daggerheart-appearance-settings',
classes: ['daggerheart', 'setting', 'dh-style'],
position: { width: '600', height: 'auto' },
actions: {
reset: this.reset,
save: this.save
},
form: { handler: this.updateData, submitOnChange: true }
};
static PARTS = {
main: {
template: 'systems/daggerheart/templates/settings/variant-rules.hbs'
}
};
async _prepareContext(_options) {
const context = await super._prepareContext(_options);
context.settingFields = this.settings;
return context;
}
static async updateData(event, element, formData) {
const updatedSettings = foundry.utils.expandObject(formData.object);
await this.settings.updateSource(updatedSettings);
this.render();
}
static async reset() {
this.settings = new DhVariantRules();
this.render();
}
static async save() {
await game.settings.set(SYSTEM.id, SYSTEM.SETTINGS.gameSettings.variantRules, this.settings.toObject());
this.close();
}
}

View file

@ -10,6 +10,10 @@ export const menu = {
Range: {
Name: 'GameSettingsRange',
Icon: 'fa-solid fa-ruler'
},
VariantRules: {
Name: 'GameSettingsVariantrules',
Icon: 'fa-solid fa-scale-balanced'
}
};
@ -27,5 +31,6 @@ export const gameSettings = {
AbilityArray: 'AbilityArray',
RangeMeasurement: 'RangeMeasurement'
},
appearance: 'Appearance'
appearance: 'Appearance',
variantRules: 'VariantRules'
};

View file

@ -2,7 +2,10 @@ export default class DhCombatant extends foundry.abstract.TypeDataModel {
static defineSchema() {
const fields = foundry.data.fields;
return {
active: new fields.BooleanField({ initial: false }),
spotlight: new fields.SchemaField({
requesting: new fields.BooleanField({ required: true, initial: false }),
active: new fields.BooleanField({ required: true, initial: false })
}),
actionTokens: new fields.NumberField({ required: true, integer: true, initial: 3 })
};
}

View file

@ -0,0 +1,13 @@
export default class DhVariantRules extends foundry.abstract.DataModel {
static defineSchema() {
const fields = foundry.data.fields;
return {
actionTokens: new fields.SchemaField({
enabled: new fields.BooleanField({ required: true, initial: false }),
tokens: new fields.NumberField({ required: true, integer: true, initial: 3 })
})
};
}
static defaultSchema = {};
}

View file

@ -1,6 +1,6 @@
export default class DhpCombat extends Combat {
get combatant() {
return this.combatants.contents.find(x => x.system.active) ?? null;
return this.combatants.contents.find(x => x.system.spotlight.active) ?? null;
}
async startCombat() {

View file

@ -1,7 +1,9 @@
export default class DhCombatTracker extends foundry.applications.sidebar.tabs.CombatTracker {
static DEFAULT_OPTIONS = {
actions: {
takeSpotlight: this.takeSpotlight
requestSpotlight: this.requestSpotlight,
toggleSpotlight: this.toggleSpotlight,
setActionTokens: this.setActionTokens
}
};
@ -17,6 +19,27 @@ export default class DhCombatTracker extends foundry.applications.sidebar.tabs.C
}
};
async _prepareCombatContext(context, options) {
await super._prepareCombatContext(context, options);
Object.assign(context, {
fear: game.settings.get(SYSTEM.id, SYSTEM.SETTINGS.gameSettings.Resources.Fear)
});
}
async _prepareTrackerContext(context, options) {
await super._prepareTrackerContext(context, options);
Object.assign(context, {
actionTokens: game.settings.get(SYSTEM.id, SYSTEM.SETTINGS.gameSettings.variantRules).actionTokens
});
}
async _prepareTurnContext(combat, combatant, index) {
const turn = await super._prepareTurnContext(combat, combatant, index);
return { ...turn, system: combatant.system.toObject() };
}
_getCombatContextOptions() {
return [
{
@ -34,12 +57,40 @@ export default class DhCombatTracker extends foundry.applications.sidebar.tabs.C
];
}
static async takeSpotlight(_, target) {
static async requestSpotlight(_, target) {
const { combatantId } = target.closest('[data-combatant-id]')?.dataset ?? {};
for (var combatant of this.viewed.combatants) {
await combatant.update({ 'system.active': combatantId === combatant.id ? true : false });
}
const combatant = this.viewed.combatants.get(combatantId);
await combatant.update({
'system.spotlight': {
requesting: !combatant.system.spotlight.requesting
}
});
this.render();
}
static async toggleSpotlight(_, target) {
const { combatantId } = target.closest('[data-combatant-id]')?.dataset ?? {};
for (var combatant of this.viewed.combatants) {
const giveSpotlight = combatant.id === combatantId;
await combatant.update({
'system.spotlight': {
requesting: giveSpotlight ? false : combatant.system.spotlight.requesting,
active: giveSpotlight ? !combatant.system.spotlight.active : false
}
});
}
}
static async setActionTokens(_, target) {
const { combatantId, tokenIndex } = target.closest('[data-combatant-id]')?.dataset ?? {};
const combatant = this.viewed.combatants.get(combatantId);
const changeIndex = Number(tokenIndex);
const newIndex = combatant.system.actionTokens > changeIndex ? changeIndex : changeIndex + 1;
await combatant.update({ 'system.actionTokens': newIndex });
this.render();
}
}