Update the ArmourSheets to allow for the equipped toggle to be present and work
This commit is contained in:
parent
b72c9d9739
commit
3c582c77bb
4 changed files with 45 additions and 6 deletions
|
|
@ -5,6 +5,7 @@ import { Logger } from "../../utils/Logger.mjs";
|
|||
|
||||
const { HandlebarsApplicationMixin } = foundry.applications.api;
|
||||
const { ItemSheetV2 } = foundry.applications.sheets;
|
||||
const { getProperty, hasProperty, setProperty } = foundry.utils;
|
||||
|
||||
export class ArmourSheet extends GenericAppMixin(HandlebarsApplicationMixin(ItemSheetV2)) {
|
||||
|
||||
|
|
@ -58,6 +59,27 @@ export class ArmourSheet extends GenericAppMixin(HandlebarsApplicationMixin(Item
|
|||
await this.render(false);
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Customize how form data is extracted into an expanded object.
|
||||
* @param {SubmitEvent|null} event The originating form submission event
|
||||
* @param {HTMLFormElement} form The form element that was submitted
|
||||
* @param {FormDataExtended} formData Processed data for the submitted form
|
||||
* @returns {object} An expanded object of processed form data
|
||||
* @throws {Error} Subclasses may throw validation errors here to prevent form submission
|
||||
* @protected
|
||||
*/
|
||||
_processFormData(event, form, formData) {
|
||||
const data = super._processFormData(event, form, formData);
|
||||
|
||||
if (hasProperty(data, `system.location`)) {
|
||||
let locations = getProperty(data, `system.location`);
|
||||
locations = locations.filter(value => value != null);
|
||||
setProperty(data, `system.location`, locations);
|
||||
};
|
||||
|
||||
return data;
|
||||
};
|
||||
// #endregion
|
||||
|
||||
// #region Data Prep
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import { Logger } from "../../utils/Logger.mjs";
|
|||
import { requiredInteger } from "../helpers.mjs";
|
||||
|
||||
const { fields } = foundry.data;
|
||||
const { hasProperty, diffObject, mergeObject } = foundry.utils;
|
||||
const { getProperty, diffObject, mergeObject } = foundry.utils;
|
||||
|
||||
/** Used for Armour and Shields */
|
||||
export class ArmourData extends CommonItemData {
|
||||
|
|
@ -19,16 +19,16 @@ export class ArmourData extends CommonItemData {
|
|||
blank: false,
|
||||
trim: true,
|
||||
nullable: false,
|
||||
required: true,
|
||||
options: Object.values(gameTerms.Anatomy),
|
||||
}),
|
||||
{
|
||||
nullable: false,
|
||||
required: true,
|
||||
initial: [],
|
||||
},
|
||||
),
|
||||
equipped: new fields.BooleanField({
|
||||
initial: false,
|
||||
required: true,
|
||||
nullable: false,
|
||||
}),
|
||||
weight: new fields.StringField({
|
||||
|
|
@ -59,7 +59,7 @@ export class ArmourData extends CommonItemData {
|
|||
const diff = diffObject(this.parent._source, changes);
|
||||
let valid = await super._preUpdate(changes, options, user);
|
||||
|
||||
if (hasProperty(diff, `system.equipped`) && !this._canEquip()) {
|
||||
if (getProperty(diff, `system.equipped`) && !this._canEquip()) {
|
||||
ui.notifications.error(
|
||||
localizer(
|
||||
`RipCrypt.notifs.error.cannot-equip`,
|
||||
|
|
@ -80,7 +80,10 @@ export class ArmourData extends CommonItemData {
|
|||
return valid;
|
||||
};
|
||||
|
||||
/** Used to tell the preUpdate logic whether or not to prevent the */
|
||||
/**
|
||||
* Used to tell the preUpdate logic whether or not to prevent the item from
|
||||
* being equipped or not.
|
||||
*/
|
||||
_canEquip() {
|
||||
const parent = this.parent;
|
||||
if (!parent.isEmbedded || !(parent.parent instanceof Actor)) {
|
||||
|
|
|
|||
|
|
@ -12,7 +12,17 @@
|
|||
<select name="system.weight" id="">
|
||||
{{ rc-options system.weight weights localize=true }}
|
||||
</select>
|
||||
{{!-- TODO: Add equipped boolean control --}}
|
||||
{{#if meta.embedded}}
|
||||
<label for="{{meta.idp}}-equipped">
|
||||
Equipped?
|
||||
</label>
|
||||
<input
|
||||
type="checkbox"
|
||||
id="{{meta.idp}}-equipped"
|
||||
name="system.equipped"
|
||||
{{ checked system.equipped }}
|
||||
>
|
||||
{{/if}}
|
||||
<rc-border
|
||||
var:border-color="var(--accent-1)"
|
||||
>
|
||||
|
|
|
|||
|
|
@ -57,6 +57,10 @@
|
|||
border-radius: 4px;
|
||||
padding: 2px 4px;
|
||||
}
|
||||
input[type="checkbox"] {
|
||||
justify-self: end;
|
||||
padding: 0;
|
||||
}
|
||||
.value {
|
||||
border: 2px solid var(--accent-2);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue