mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-04-21 23:13:39 +02:00
Fixed conditional choices resource paths and ResourcesField.getField function
This commit is contained in:
parent
08f3dd04e1
commit
f5e1b45065
3 changed files with 26 additions and 11 deletions
|
|
@ -4,7 +4,8 @@ export default class DhActiveEffectConfig extends foundry.applications.sheets.Ac
|
||||||
constructor(options) {
|
constructor(options) {
|
||||||
super(options);
|
super(options);
|
||||||
|
|
||||||
this.changeChoices = DhActiveEffectConfig.getChangeChoices();
|
this.changeChoices = this.#getChangeChoices();
|
||||||
|
this.conditionalChoices = this.#getChangeChoices({ resourceValuePaths: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
static DEFAULT_OPTIONS = {
|
static DEFAULT_OPTIONS = {
|
||||||
|
|
@ -50,7 +51,7 @@ export default class DhActiveEffectConfig extends foundry.applications.sheets.Ac
|
||||||
* Get ChangeChoices for the changes autocomplete. Static for use in this class aswell as in settings-active-effect-config.mjs
|
* Get ChangeChoices for the changes autocomplete. Static for use in this class aswell as in settings-active-effect-config.mjs
|
||||||
* @returns {ChangeChoice { value: string, label: string, hint: string, group: string }[]}
|
* @returns {ChangeChoice { value: string, label: string, hint: string, group: string }[]}
|
||||||
*/
|
*/
|
||||||
static getChangeChoices() {
|
#getChangeChoices(options = { resourceValuePaths: false }) {
|
||||||
const ignoredActorKeys = ['config', 'DhEnvironment', 'DhParty'];
|
const ignoredActorKeys = ['config', 'DhEnvironment', 'DhParty'];
|
||||||
|
|
||||||
const getAllLeaves = (root, group, parentPath = '') => {
|
const getAllLeaves = (root, group, parentPath = '') => {
|
||||||
|
|
@ -70,6 +71,8 @@ export default class DhActiveEffectConfig extends foundry.applications.sheets.Ac
|
||||||
|
|
||||||
return leaves;
|
return leaves;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const resourcePathEnding = options.resourceValuePaths ? 'value' : 'max';
|
||||||
return Object.keys(game.system.api.models.actors).reduce((acc, key) => {
|
return Object.keys(game.system.api.models.actors).reduce((acc, key) => {
|
||||||
if (ignoredActorKeys.includes(key)) return acc;
|
if (ignoredActorKeys.includes(key)) return acc;
|
||||||
|
|
||||||
|
|
@ -78,11 +81,17 @@ export default class DhActiveEffectConfig extends foundry.applications.sheets.Ac
|
||||||
const attributes = CONFIG.Token.documentClass.getTrackedAttributes(model.metadata.type);
|
const attributes = CONFIG.Token.documentClass.getTrackedAttributes(model.metadata.type);
|
||||||
|
|
||||||
const getTranslations = path => {
|
const getTranslations = path => {
|
||||||
if (path === 'resources.hope.max')
|
if (path === 'resources.hope.max') {
|
||||||
return {
|
return {
|
||||||
label: game.i18n.localize('DAGGERHEART.SETTINGS.Homebrew.FIELDS.maxHope.label'),
|
label: game.i18n.localize('DAGGERHEART.SETTINGS.Homebrew.FIELDS.maxHope.label'),
|
||||||
hint: ''
|
hint: ''
|
||||||
};
|
};
|
||||||
|
} else if (path === 'resources.hope.value') {
|
||||||
|
return {
|
||||||
|
label: game.i18n.localize('DAGGERHEART.GENERAL.hope'),
|
||||||
|
hint: ''
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
const field = model.schema.getField(path);
|
const field = model.schema.getField(path);
|
||||||
return {
|
return {
|
||||||
|
|
@ -92,7 +101,7 @@ export default class DhActiveEffectConfig extends foundry.applications.sheets.Ac
|
||||||
};
|
};
|
||||||
|
|
||||||
const bars = attributes.bar.flatMap(x => {
|
const bars = attributes.bar.flatMap(x => {
|
||||||
const joined = `${x.join('.')}.max`;
|
const joined = `${x.join('.')}.${resourcePathEnding}`;
|
||||||
return { value: joined, ...getTranslations(joined), group };
|
return { value: joined, ...getTranslations(joined), group };
|
||||||
});
|
});
|
||||||
const values = attributes.value.flatMap(x => {
|
const values = attributes.value.flatMap(x => {
|
||||||
|
|
@ -112,16 +121,18 @@ export default class DhActiveEffectConfig extends foundry.applications.sheets.Ac
|
||||||
_attachPartListeners(partId, htmlElement, options) {
|
_attachPartListeners(partId, htmlElement, options) {
|
||||||
super._attachPartListeners(partId, htmlElement, options);
|
super._attachPartListeners(partId, htmlElement, options);
|
||||||
const changeChoices = this.changeChoices;
|
const changeChoices = this.changeChoices;
|
||||||
|
const conditionalChoices = this.conditionalChoices;
|
||||||
|
|
||||||
htmlElement.querySelectorAll('.effect-change-input').forEach(element => {
|
htmlElement.querySelectorAll('.effect-change-input').forEach(element => {
|
||||||
|
const choices = element.classList.contains('conditional-key-input') ? conditionalChoices : changeChoices;
|
||||||
autocomplete({
|
autocomplete({
|
||||||
input: element,
|
input: element,
|
||||||
fetch: function (text, update) {
|
fetch: function (text, update) {
|
||||||
if (!text) {
|
if (!text) {
|
||||||
update(changeChoices);
|
update(choices);
|
||||||
} else {
|
} else {
|
||||||
text = text.toLowerCase();
|
text = text.toLowerCase();
|
||||||
var suggestions = changeChoices.filter(n => n.label.toLowerCase().includes(text));
|
var suggestions = choices.filter(n => n.label.toLowerCase().includes(text));
|
||||||
update(suggestions);
|
update(suggestions);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -89,13 +89,17 @@ class ResourcesField extends fields.TypedObjectField {
|
||||||
*/
|
*/
|
||||||
_getField(path) {
|
_getField(path) {
|
||||||
if (path.length === 0) return this;
|
if (path.length === 0) return this;
|
||||||
const first = path.shift();
|
const first = path.pop();
|
||||||
if (first === this.element.name) return this.element_getField(path);
|
|
||||||
|
|
||||||
const resources = CONFIG.DH.RESOURCE[this.actorType].all;
|
const resources = CONFIG.DH.RESOURCE[this.actorType].all;
|
||||||
if (first in resources) {
|
if (first in resources) {
|
||||||
this.element.label = resources[first].label;
|
const field = this.element._getField(path);
|
||||||
return this.element._getField(path);
|
const resourceName = game.i18n.localize(resources[first].label);
|
||||||
|
field.label =
|
||||||
|
field.name === 'max'
|
||||||
|
? game.i18n.format('DAGGERHEART.GENERAL.maxWithThing', { thing: resourceName })
|
||||||
|
: resources[first].label;
|
||||||
|
return field;
|
||||||
}
|
}
|
||||||
|
|
||||||
return undefined;
|
return undefined;
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@
|
||||||
<label>{{localize "EFFECT.FIELDS.changes.element.key.label"}}</label>
|
<label>{{localize "EFFECT.FIELDS.changes.element.key.label"}}</label>
|
||||||
|
|
||||||
<div class="form-fields">
|
<div class="form-fields">
|
||||||
<input type="text" class="effect-change-input" {{#if (eq conditional.type 'attribute')}}name="{{concat "system.conditionals." index ".key"}}"{{/if}} value="{{conditional.key}}" />
|
<input type="text" class="effect-change-input conditional-key-input" {{#if (eq conditional.type 'attribute')}}name="{{concat "system.conditionals." index ".key"}}"{{/if}} value="{{conditional.key}}" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue