mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-04-21 23:13:39 +02:00
[Feature] Custom Resources (#1714)
* Initial * . * Fixed positioning * . * Only showing the menu if there are extra resources * Improved resourceManager clickable * . * Changed variable name * Refactor resources selection and data prep (#1721) * Move resources select to scrolly text and accept actor object * Convert isReversed to prepared data and add label * Removed unused imports --------- Co-authored-by: WBHarry <williambjrklund@gmail.com> * Naming * [Feature] Custom Homebrew Resources (#1718) * Added resources to the Homebrew Menu * Fixed translations * . * Inverted from isImage to isIcon. Should be more logical for users * Removed testing resources * Refactor resource settings to not be a method (#1723) * Fix editing homebrew resources with a custom ResourcesField * Fix removing homebrew resources * Remove vestigial code * Use custom config for module data instead of including in all (#1724) * Use custom config for module data instead of including in all * More simple * base highest priority --------- Co-authored-by: Carlos Fernandez <CarlosFdez@users.noreply.github.com> Co-authored-by: Carlos Fernandez <cfern1990@gmail.com>
This commit is contained in:
parent
af04fb33d0
commit
552c62adc1
32 changed files with 970 additions and 189 deletions
|
|
@ -145,6 +145,16 @@ export default class DhHomebrew extends foundry.abstract.DataModel {
|
|||
description: new fields.StringField()
|
||||
})
|
||||
),
|
||||
resources: new fields.TypedObjectField(
|
||||
new fields.SchemaField({
|
||||
resources: new fields.TypedObjectField(new fields.EmbeddedDataField(Resource))
|
||||
}),
|
||||
{
|
||||
initial: {
|
||||
character: { resources: {} }
|
||||
}
|
||||
}
|
||||
),
|
||||
itemFeatures: new fields.SchemaField({
|
||||
weaponFeatures: new fields.TypedObjectField(
|
||||
new fields.SchemaField({
|
||||
|
|
@ -185,4 +195,117 @@ export default class DhHomebrew extends foundry.abstract.DataModel {
|
|||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
/** Invoked by the setting when data changes */
|
||||
handleChange() {
|
||||
if (this.maxFear) {
|
||||
if (ui.resources) ui.resources.render({ force: true });
|
||||
}
|
||||
|
||||
this.refreshConfig();
|
||||
this.#resetActors();
|
||||
}
|
||||
|
||||
/** Update config values based on homebrew data. Make sure the references don't change */
|
||||
refreshConfig() {
|
||||
for (const [actorType, actorData] of Object.entries(this.resources)) {
|
||||
const config = CONFIG.DH.RESOURCE[actorType];
|
||||
for (const key of Object.keys(config.all)) {
|
||||
delete config.all[key];
|
||||
}
|
||||
Object.assign(config.all, {
|
||||
...Object.entries(actorData.resources).reduce((result, [key, value]) => {
|
||||
result[key] = value.toObject();
|
||||
result[key].id = key;
|
||||
return result;
|
||||
}, {}),
|
||||
...config.custom,
|
||||
...config.base,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Triggers a reset and non-forced re-render on all given actors (if given)
|
||||
* or all world actors and actors in all scenes to show immediate results for a changed setting.
|
||||
*/
|
||||
#resetActors() {
|
||||
const actors = new Set(
|
||||
[
|
||||
game.actors.contents,
|
||||
game.scenes.contents.flatMap(s => s.tokens.contents).flatMap(t => t.actor ?? [])
|
||||
].flat()
|
||||
);
|
||||
for (const actor of actors) {
|
||||
for (const app of Object.values(actor.apps)) {
|
||||
for (const element of app.element?.querySelectorAll('prose-mirror.active')) {
|
||||
element.open = false; // This triggers a save
|
||||
}
|
||||
}
|
||||
|
||||
actor.reset();
|
||||
actor.render();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export class Resource extends foundry.abstract.DataModel {
|
||||
static defineSchema() {
|
||||
const fields = foundry.data.fields;
|
||||
return {
|
||||
initial: new fields.NumberField({
|
||||
required: true,
|
||||
integer: true,
|
||||
initial: 0,
|
||||
min: 0,
|
||||
label: 'DAGGERHEART.GENERAL.initial'
|
||||
}),
|
||||
max: new fields.NumberField({
|
||||
nullable: true,
|
||||
initial: null,
|
||||
min: 0,
|
||||
label: 'DAGGERHEART.GENERAL.max'
|
||||
}),
|
||||
label: new fields.StringField({ label: 'DAGGERHEART.GENERAL.label' }),
|
||||
images: new fields.SchemaField({
|
||||
full: imageIconField('fa solid fa-circle'),
|
||||
empty: imageIconField('fa-regular fa-circle')
|
||||
})
|
||||
};
|
||||
}
|
||||
|
||||
static getDefaultResourceData = label => {
|
||||
const images = Resource.schema.fields.images.getInitialValue();
|
||||
return {
|
||||
initial: 0,
|
||||
max: 0,
|
||||
label: label ?? '',
|
||||
images
|
||||
};
|
||||
};
|
||||
|
||||
static getDefaultImageData = imageKey => {
|
||||
return Resource.schema.fields.images.fields[imageKey].getInitialValue();
|
||||
};
|
||||
}
|
||||
|
||||
const imageIconField = defaultValue =>
|
||||
new foundry.data.fields.SchemaField(
|
||||
{
|
||||
value: new foundry.data.fields.StringField({
|
||||
initial: defaultValue,
|
||||
label: 'DAGGERHEART.SETTINGS.Homebrew.FIELDS.resources.resources.value.label'
|
||||
}),
|
||||
isIcon: new foundry.data.fields.BooleanField({
|
||||
required: true,
|
||||
initial: true,
|
||||
label: 'DAGGERHEART.SETTINGS.Homebrew.FIELDS.resources.resources.isIcon.label'
|
||||
}),
|
||||
noColorFilter: new foundry.data.fields.BooleanField({
|
||||
required: true,
|
||||
initial: false,
|
||||
label: 'DAGGERHEART.SETTINGS.Homebrew.FIELDS.resources.resources.noColorFilter.label'
|
||||
})
|
||||
},
|
||||
{ required: true }
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue