Add header control for adding an embedded item into an actor.
This commit is contained in:
parent
380ed3fe15
commit
fc24caf08a
3 changed files with 51 additions and 14 deletions
|
|
@ -84,6 +84,7 @@
|
||||||
},
|
},
|
||||||
"PlayerSheet": {
|
"PlayerSheet": {
|
||||||
"manage-attributes": "Manage Attributes",
|
"manage-attributes": "Manage Attributes",
|
||||||
|
"create-item": "Create Embedded Item",
|
||||||
"current-value": "Current value",
|
"current-value": "Current value",
|
||||||
"max-value": "Maximum value",
|
"max-value": "Maximum value",
|
||||||
"carry-capacity-used": "({percent}% Used)",
|
"carry-capacity-used": "({percent}% Used)",
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,7 @@ export class PlayerSheet extends
|
||||||
closeOnSubmit: false,
|
closeOnSubmit: false,
|
||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
|
createEmbeddedItem: this.#createEmbeddedItem,
|
||||||
manageAttributes: this.#manageAttributes,
|
manageAttributes: this.#manageAttributes,
|
||||||
configureSheet: this.#configureSheet,
|
configureSheet: this.#configureSheet,
|
||||||
toggleExpand: this.#toggleExpand,
|
toggleExpand: this.#toggleExpand,
|
||||||
|
|
@ -132,17 +133,27 @@ export class PlayerSheet extends
|
||||||
_getHeaderControls() {
|
_getHeaderControls() {
|
||||||
const controls = super._getHeaderControls();
|
const controls = super._getHeaderControls();
|
||||||
|
|
||||||
controls.push({
|
controls.push(
|
||||||
icon: `fa-solid fa-at`,
|
{
|
||||||
label: `taf.Apps.PlayerSheet.manage-attributes`,
|
icon: `fa-solid fa-at`,
|
||||||
action: `manageAttributes`,
|
label: `taf.Apps.PlayerSheet.manage-attributes`,
|
||||||
visible: () => {
|
action: `manageAttributes`,
|
||||||
const isGM = game.user.isGM;
|
visible: () => {
|
||||||
const allowPlayerEdits = game.settings.get(__ID__, `canPlayersManageAttributes`);
|
const isGM = game.user.isGM;
|
||||||
const editable = this.isEditable;
|
const allowPlayerEdits = game.settings.get(__ID__, `canPlayersManageAttributes`);
|
||||||
return isGM || (allowPlayerEdits && editable);
|
const editable = this.isEditable;
|
||||||
|
return isGM || (allowPlayerEdits && editable);
|
||||||
|
},
|
||||||
},
|
},
|
||||||
});
|
{
|
||||||
|
icon: `fa-solid fa-suitcase`,
|
||||||
|
label: `taf.Apps.PlayerSheet.create-item`,
|
||||||
|
action: `createEmbeddedItem`,
|
||||||
|
visible: () => {
|
||||||
|
return this.isEditable;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
return controls;
|
return controls;
|
||||||
};
|
};
|
||||||
|
|
@ -158,7 +169,7 @@ export class PlayerSheet extends
|
||||||
label: _loc(`taf.misc.edit`),
|
label: _loc(`taf.misc.edit`),
|
||||||
condition: (el) => {
|
condition: (el) => {
|
||||||
const itemUuid = el.dataset.itemUuid;
|
const itemUuid = el.dataset.itemUuid;
|
||||||
const itemExists = itemUuid != null && itemUuid !== "";
|
const itemExists = itemUuid != null && itemUuid !== ``;
|
||||||
return this.isEditable && itemExists;
|
return this.isEditable && itemExists;
|
||||||
},
|
},
|
||||||
onClick: editItemFromElement,
|
onClick: editItemFromElement,
|
||||||
|
|
@ -167,13 +178,13 @@ export class PlayerSheet extends
|
||||||
label: _loc(`taf.misc.delete`),
|
label: _loc(`taf.misc.delete`),
|
||||||
condition: (el) => {
|
condition: (el) => {
|
||||||
const itemUuid = el.dataset.itemUuid;
|
const itemUuid = el.dataset.itemUuid;
|
||||||
const itemExists = itemUuid != null && itemUuid !== "";
|
const itemExists = itemUuid != null && itemUuid !== ``;
|
||||||
return this.isEditable && itemExists;
|
return this.isEditable && itemExists;
|
||||||
},
|
},
|
||||||
onClick: deleteItemFromElement,
|
onClick: deleteItemFromElement,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
{ jQuery: false, fixed: true, },
|
{ jQuery: false, fixed: true },
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -364,5 +375,30 @@ export class PlayerSheet extends
|
||||||
el.dataset.expanded = newExpanded;
|
el.dataset.expanded = newExpanded;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used by the sheet in order to create embedded items without needing to have
|
||||||
|
* equivalent World Items or Compendiums initially.
|
||||||
|
*
|
||||||
|
* @this {PlayerSheet}
|
||||||
|
*/
|
||||||
|
static async #createEmbeddedItem(event, target) {
|
||||||
|
let { itemGroup } = target.dataset ?? {};
|
||||||
|
if (itemGroup === `Items`) { itemGroup = undefined };
|
||||||
|
|
||||||
|
const data = {
|
||||||
|
name: Item.defaultName({
|
||||||
|
type: `generic`,
|
||||||
|
parent: this.actor,
|
||||||
|
}),
|
||||||
|
type: `generic`,
|
||||||
|
system: {
|
||||||
|
group: itemGroup,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const item = await Item.create(data, { parent: this.actor });
|
||||||
|
item?.sheet?.render({ force: true });
|
||||||
|
};
|
||||||
// #endregion Actions
|
// #endregion Actions
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ export class GenericItemData extends foundry.abstract.TypeDataModel {
|
||||||
* rounds the number to the nearest 2 decimal places.
|
* rounds the number to the nearest 2 decimal places.
|
||||||
*/
|
*/
|
||||||
get quantifiedWeight() {
|
get quantifiedWeight() {
|
||||||
const value = this.weight * this.quantity
|
const value = this.weight * this.quantity;
|
||||||
return toPrecision(Math.max(value, 0), 2);
|
return toPrecision(Math.max(value, 0), 2);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue