mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-17 23:49:02 +01:00
Fixed translation of TrackedAttributeChoices
This commit is contained in:
parent
a768b1dfdb
commit
ad9a72d494
18 changed files with 410 additions and 91 deletions
|
|
@ -1,4 +1,44 @@
|
|||
import autocomplete from 'autocompleter';
|
||||
|
||||
export default class DhActiveEffectConfig extends foundry.applications.sheets.ActiveEffectConfig {
|
||||
constructor(options) {
|
||||
super(options);
|
||||
|
||||
const ignoredActorKeys = ['config', 'DhEnvironment'];
|
||||
const actorAttributes = Object.keys(game.system.api.models.actors).reduce((acc, key) => {
|
||||
if (!ignoredActorKeys.includes(key)) {
|
||||
const model = game.system.api.models.actors[key];
|
||||
const attributes = CONFIG.Token.documentClass.getTrackedAttributes(model);
|
||||
acc[game.i18n.localize(model.metadata.label)] = CONFIG.Token.documentClass.getTrackedAttributeChoices(
|
||||
attributes,
|
||||
model
|
||||
);
|
||||
}
|
||||
return acc;
|
||||
}, {});
|
||||
console.log(actorAttributes);
|
||||
|
||||
// const allowedItemKeys = ['DHArmor'];
|
||||
// const itemAttributes = Object.keys(game.system.api.models.items).reduce((acc, key) => {
|
||||
// if(allowedItemKeys.includes(key)) {
|
||||
// const model = game.system.api.models.items[key];
|
||||
// acc[game.i18n.localize(model.metadata.label)] = CONFIG.Token.documentClass.getTrackedAttributes(model);
|
||||
// }
|
||||
// return acc;
|
||||
// }, {});
|
||||
|
||||
// this.selectChoices = [
|
||||
// ...Object.keys(actorAttributes).flatMap(name => {
|
||||
// const attribute = actorAttributes[name];
|
||||
// return { group: name, label: attribute, value: attribute };
|
||||
// }),
|
||||
// ...Object.keys(itemAttributes).flatMap(name => {
|
||||
// const attribute = itemAttributes[name];
|
||||
// return { group: name, label: attribute, value: attribute };
|
||||
// })
|
||||
// ];
|
||||
}
|
||||
|
||||
static DEFAULT_OPTIONS = {
|
||||
classes: ['daggerheart', 'sheet', 'dh-style']
|
||||
};
|
||||
|
|
@ -27,36 +67,61 @@ export default class DhActiveEffectConfig extends foundry.applications.sheets.Ac
|
|||
}
|
||||
};
|
||||
|
||||
_attachPartListeners(partId, htmlElement, options) {
|
||||
super._attachPartListeners(partId, htmlElement, options);
|
||||
const selectChoices = this.selectChoices;
|
||||
|
||||
htmlElement.querySelectorAll('.effect-change-input').forEach(element => {
|
||||
autocomplete({
|
||||
input: element,
|
||||
fetch: function (text, update) {
|
||||
if (!text) {
|
||||
update(selectChoices);
|
||||
} else {
|
||||
text = text.toLowerCase();
|
||||
var suggestions = selectChoices.filter(n => n.label.toLowerCase().includes(text));
|
||||
update(suggestions);
|
||||
}
|
||||
},
|
||||
render: function (item, search) {
|
||||
const label = game.i18n.localize(item.label);
|
||||
const matchIndex = label.toLowerCase().indexOf(search);
|
||||
|
||||
const base = document.createElement('div');
|
||||
base.textContent = label.slice(0, matchIndex);
|
||||
|
||||
const matchText = document.createElement('div');
|
||||
matchText.textContent = label.slice(matchIndex, matchIndex + search.length);
|
||||
matchText.classList.add('matched');
|
||||
|
||||
const after = document.createElement('div');
|
||||
after.textContent = label.slice(matchIndex + search.length, label.length);
|
||||
|
||||
base.insertAdjacentElement('beforeend', matchText);
|
||||
base.insertAdjacentElement('beforeend', after);
|
||||
return base;
|
||||
},
|
||||
renderGroup: function (label) {
|
||||
const itemElement = document.createElement('div');
|
||||
itemElement.textContent = game.i18n.localize(label);
|
||||
return itemElement;
|
||||
},
|
||||
onSelect: function (item) {
|
||||
element.value = item.value;
|
||||
},
|
||||
click: e => e.fetch(),
|
||||
minLength: 0
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
async _preparePartContext(partId, context) {
|
||||
const partContext = await super._preparePartContext(partId, context);
|
||||
switch (partId) {
|
||||
case 'changes':
|
||||
const fieldPaths = [];
|
||||
const validFieldPath = fieldPath => this.validFieldPath(fieldPath, this.#unapplicablePaths);
|
||||
context.document.parent.system.schema.apply(function () {
|
||||
if (!(this instanceof foundry.data.fields.SchemaField)) {
|
||||
if (validFieldPath(this.fieldPath)) {
|
||||
fieldPaths.push(this.fieldPath);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
context.fieldPaths = fieldPaths;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
return partContext;
|
||||
}
|
||||
|
||||
#unapplicablePaths = ['story', 'pronouns', 'description'];
|
||||
validFieldPath(fieldPath, unapplicablePaths) {
|
||||
const splitPath = fieldPath.split('.');
|
||||
if (splitPath.length > 1 && unapplicablePaths.includes(splitPath[1])) return false;
|
||||
|
||||
/* The current value of a resource should not be modified */
|
||||
if (new RegExp(/resources.*\.value/).exec(fieldPath)) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue