Compendium filter

This commit is contained in:
Litasa
2025-02-16 13:24:03 +00:00
committed by Vlyan
parent 257a736c83
commit b0bc91393a
60 changed files with 2408 additions and 1287 deletions

View File

@@ -0,0 +1,47 @@
import { HTML_l5r5e_MultiSelectElement } from "../misc/l5r5e-multiselect.js";
/**
* A subclass of [ArrayField]{@link ArrayField} which supports a set of contained elements.
* Elements in this set are treated as fungible and may be represented in any order or discarded if invalid.
*/
export class l5r5e_SetField extends foundry.data.fields.SetField {
// We don't get the options we expect when we convert this to input,
// So store them here
#savedOptions;
constructor(options={}, context={}) {
super(new foundry.data.fields.StringField({
choices: options.options.map((option) => option.value)
}), options, context);
this.#savedOptions = options;
}
/** @override */
initialize(value, model, options={}) {
if ( !value ) return value;
return new Set(super.initialize(value, model, options));
}
/** @override */
toObject(value) {
if ( !value ) return value;
return Array.from(value).map(v => this.element.toObject(v));
}
/* -------------------------------------------- */
/* Form Field Integration */
/* -------------------------------------------- */
/** @override */
_toInput(config) {
const e = this.element;
return HTML_l5r5e_MultiSelectElement.create({
name: config.name,
options: this.#savedOptions.options,
groups: this.#savedOptions.groups,
value: config.value,
localize: config.localize
});
}
}