Add a group property on the Item data model
This commit is contained in:
parent
c6ec60b5bf
commit
ce81212bbe
4 changed files with 58 additions and 1 deletions
|
|
@ -59,7 +59,8 @@
|
||||||
"item": {
|
"item": {
|
||||||
"weight": "Weight",
|
"weight": "Weight",
|
||||||
"quantity": "Quantity",
|
"quantity": "Quantity",
|
||||||
"equipped": "Equipped"
|
"equipped": "Equipped",
|
||||||
|
"group": "Group"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"Apps": {
|
"Apps": {
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,12 @@ export class GenericItemData extends foundry.abstract.TypeDataModel {
|
||||||
static defineSchema() {
|
static defineSchema() {
|
||||||
const fields = foundry.data.fields;
|
const fields = foundry.data.fields;
|
||||||
return {
|
return {
|
||||||
|
group: new fields.StringField({
|
||||||
|
blank: false,
|
||||||
|
trim: true,
|
||||||
|
initial: null,
|
||||||
|
nullable: true,
|
||||||
|
}),
|
||||||
weight: new fields.NumberField({
|
weight: new fields.NumberField({
|
||||||
min: 0,
|
min: 0,
|
||||||
initial: 0,
|
initial: 0,
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,11 @@ const { hasProperty } = foundry.utils;
|
||||||
export class TAFActor extends Actor {
|
export class TAFActor extends Actor {
|
||||||
|
|
||||||
// #region Lifecycle
|
// #region Lifecycle
|
||||||
|
/**
|
||||||
|
* This makes sure that the actor gets created with the global attributes if
|
||||||
|
* they exist, while still allowing programmatic creation through the API with
|
||||||
|
* specific attributes.
|
||||||
|
*/
|
||||||
async _preCreate(data, options, user) {
|
async _preCreate(data, options, user) {
|
||||||
|
|
||||||
// Assign the defaults from the world setting if they exist
|
// Assign the defaults from the world setting if they exist
|
||||||
|
|
@ -17,8 +22,19 @@ export class TAFActor extends Actor {
|
||||||
|
|
||||||
return super._preCreate(data, options, user);
|
return super._preCreate(data, options, user);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This resets the cache of the item groupings whenever a descedant document
|
||||||
|
* gets changed (created, updated, deleted) so that we keep the cache as close
|
||||||
|
* to accurate as can be possible.
|
||||||
|
*/
|
||||||
|
_onEmbeddedDocumentChange(...args) {
|
||||||
|
super._onEmbeddedDocumentChange(...args);
|
||||||
|
this.#sortedTypes = null;
|
||||||
|
};
|
||||||
// #endregion Lifecycle
|
// #endregion Lifecycle
|
||||||
|
|
||||||
|
// #region Token Attributes
|
||||||
async modifyTokenAttribute(attribute, value, isDelta = false, isBar = true) {
|
async modifyTokenAttribute(attribute, value, isDelta = false, isBar = true) {
|
||||||
const attr = foundry.utils.getProperty(this.system, attribute);
|
const attr = foundry.utils.getProperty(this.system, attribute);
|
||||||
const current = isBar ? attr.value : attr;
|
const current = isBar ? attr.value : attr;
|
||||||
|
|
@ -40,7 +56,9 @@ export class TAFActor extends Actor {
|
||||||
|
|
||||||
return allowed !== false ? this.update(updates) : this;
|
return allowed !== false ? this.update(updates) : this;
|
||||||
};
|
};
|
||||||
|
// #endregion Token Attributes
|
||||||
|
|
||||||
|
// #region Roll Data
|
||||||
getRollData() {
|
getRollData() {
|
||||||
/*
|
/*
|
||||||
All properties assigned during this phase of the roll data prep can potentially
|
All properties assigned during this phase of the roll data prep can potentially
|
||||||
|
|
@ -67,4 +85,24 @@ export class TAFActor extends Actor {
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
};
|
};
|
||||||
|
// #endregion Roll Data
|
||||||
|
|
||||||
|
// #region Getters
|
||||||
|
#sortedTypes = null;
|
||||||
|
get itemTypes() {
|
||||||
|
if (this.#sortedTypes) return this.#sortedTypes;
|
||||||
|
const types = {};
|
||||||
|
for (const item of this.items) {
|
||||||
|
if (item.type !== `generic`) {
|
||||||
|
types[item.type] ??= [];
|
||||||
|
types[item.type].push(item);
|
||||||
|
} else {
|
||||||
|
const group = item.system.group ?? `Items`;
|
||||||
|
types[group] ??= [];
|
||||||
|
types[group].push(item);
|
||||||
|
};
|
||||||
|
};
|
||||||
|
return this.#sortedTypes = types;
|
||||||
|
};
|
||||||
|
// #endregion Getters
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,18 @@
|
||||||
{{disabled (not meta.editable)}}
|
{{disabled (not meta.editable)}}
|
||||||
>
|
>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="property">
|
||||||
|
<label for="{{meta.idp}}-group">
|
||||||
|
{{localize "taf.misc.item.group"}}
|
||||||
|
</label>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
id="{{meta.idp}}-group"
|
||||||
|
name="system.group"
|
||||||
|
value="{{system.group}}"
|
||||||
|
{{disabled (not meta.editable)}}
|
||||||
|
>
|
||||||
|
</div>
|
||||||
<div class="property">
|
<div class="property">
|
||||||
<label for="{{meta.idp}}-equipped">
|
<label for="{{meta.idp}}-equipped">
|
||||||
{{localize "taf.misc.item.equipped"}}
|
{{localize "taf.misc.item.equipped"}}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue