Add a prompt for equipping an item on drag and drop
This commit is contained in:
parent
dfc8964296
commit
f29ab8bdaa
2 changed files with 65 additions and 35 deletions
|
|
@ -4,12 +4,13 @@ import { localizer } from "../../utils/Localizer.mjs";
|
|||
import { Logger } from "../../utils/Logger.mjs";
|
||||
import { requiredInteger } from "../helpers.mjs";
|
||||
|
||||
const { diffObject, getProperty, setProperty } = foundry.utils;
|
||||
const { DialogV2 } = foundry.applications.api;
|
||||
const { fields } = foundry.data;
|
||||
const { getProperty, diffObject, mergeObject } = foundry.utils;
|
||||
|
||||
/** Used for Armour and Shields */
|
||||
export class ArmourData extends CommonItemData {
|
||||
// MARK: Schema
|
||||
// #region Schema
|
||||
static defineSchema() {
|
||||
return {
|
||||
...super.defineSchema(),
|
||||
|
|
@ -39,20 +40,22 @@ export class ArmourData extends CommonItemData {
|
|||
}),
|
||||
};
|
||||
};
|
||||
|
||||
// MARK: Base Data
|
||||
prepareBaseData() {
|
||||
super.prepareBaseData();
|
||||
};
|
||||
|
||||
// MARK: Derived Data
|
||||
prepareDerivedData() {
|
||||
super.prepareDerivedData();
|
||||
};
|
||||
// #endregion Schema
|
||||
|
||||
// #region Lifecycle
|
||||
async _preCreate(item) {
|
||||
if (this.parent.isEmbedded && this._canEquip()) {
|
||||
const shouldEquip = await DialogV2.confirm({
|
||||
window: { title: `Equip Item?` },
|
||||
content: `Do you want to equip ${item.name}?`,
|
||||
});
|
||||
if (shouldEquip) {
|
||||
this.updateSource({ "equipped": true });
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
async _preUpdate(changes, options, user) {
|
||||
// return false
|
||||
if (options.force && game.settings.get(`ripcrypt`, `devMode`)) { return };
|
||||
|
||||
// Ensure changes is a diffed object
|
||||
|
|
@ -69,9 +72,7 @@ export class ArmourData extends CommonItemData {
|
|||
);
|
||||
|
||||
// Don't stop the update, but don't allow changing the equipped status
|
||||
mergeObject(changes, {
|
||||
"system.equipped": false,
|
||||
});
|
||||
setProperty(changes, `system.equipped`, false);
|
||||
|
||||
// Set a flag so that we can tell the sheet that it needs to rerender
|
||||
this.forceRerender = true;
|
||||
|
|
@ -79,7 +80,9 @@ export class ArmourData extends CommonItemData {
|
|||
|
||||
return valid;
|
||||
};
|
||||
// #endregion Lifecycle
|
||||
|
||||
// #region Helpers
|
||||
/**
|
||||
* Used to tell the preUpdate logic whether or not to prevent the item from
|
||||
* being equipped or not.
|
||||
|
|
@ -106,11 +109,9 @@ export class ArmourData extends CommonItemData {
|
|||
};
|
||||
return true;
|
||||
};
|
||||
// #endregion
|
||||
|
||||
// #region Getters
|
||||
get locationString() {
|
||||
return [...this.location].join(`, `);
|
||||
};
|
||||
// #endregion
|
||||
// #endregion Helpers
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue