RC-98 | Add quantity to items

This commit is contained in:
Oliver-Akins 2025-01-26 14:17:56 -07:00
parent aa05cdde46
commit 3cff9fda7d
8 changed files with 57 additions and 4 deletions

View file

@ -17,6 +17,7 @@
"HeroSkillsCardV1": "Hero Skill Card" "HeroSkillsCardV1": "Hero Skill Card"
}, },
"common": { "common": {
"quantity": "Quantity",
"equipped": "Equipped", "equipped": "Equipped",
"edit": "Edit", "edit": "Edit",
"delete": "Delete", "delete": "Delete",

View file

@ -96,7 +96,7 @@ export class HeroSkillsCardV1 extends GenericAppMixin(HandlebarsApplicationMixin
ctx.gear.push({ ctx.gear.push({
index: ctx.gear.length, index: ctx.gear.length,
uuid: item.uuid, uuid: item.uuid,
name: item.name, name: item.quantifiedName,
empty: false, empty: false,
}); });

View file

@ -0,0 +1,20 @@
import { requiredInteger } from "../helpers.mjs";
export class CommonItemData extends foundry.abstract.TypeDataModel {
// MARK: Schema
static defineSchema() {
return {
quantity: requiredInteger({ min: 0, initial: 1 }),
};
};
// MARK: Base Data
prepareBaseData() {
super.prepareBaseData();
};
// MARK: Derived Data
prepareDerivedData() {
super.prepareDerivedData();
};
};

View file

@ -1,13 +1,15 @@
import { CommonItemData } from "./Common.mjs";
import { gameTerms } from "../../gameTerms.mjs"; import { gameTerms } from "../../gameTerms.mjs";
import { requiredInteger } from "../helpers.mjs"; import { requiredInteger } from "../helpers.mjs";
const { fields } = foundry.data; const { fields } = foundry.data;
/** Used for Armour and Shields */ /** Used for Armour and Shields */
export class ProtectorData extends foundry.abstract.TypeDataModel { export class ProtectorData extends CommonItemData {
// MARK: Schema // MARK: Schema
static defineSchema() { static defineSchema() {
return { return {
...super.defineSchema(),
protection: requiredInteger({ min: 0, initial: 1 }), protection: requiredInteger({ min: 0, initial: 1 }),
location: new fields.SetField( location: new fields.SetField(
new fields.StringField({ new fields.StringField({
@ -48,6 +50,14 @@ export class ProtectorData extends foundry.abstract.TypeDataModel {
// #region Sheet Data // #region Sheet Data
getFormFields(_ctx) { getFormFields(_ctx) {
const fields = [ const fields = [
{
id: `quantity`,
type: `integer`,
label: `RipCrypt.Apps.quantity`,
path: `system.quantity`,
value: this.quantity,
min: 0,
},
{ {
id: `location`, id: `location`,
type: `string-set`, type: `string-set`,

View file

@ -1,12 +1,14 @@
import { barAttribute, optionalInteger, requiredInteger } from "../helpers.mjs"; import { barAttribute, optionalInteger, requiredInteger } from "../helpers.mjs";
import { CommonItemData } from "./Common.mjs";
import { gameTerms } from "../../gameTerms.mjs"; import { gameTerms } from "../../gameTerms.mjs";
const { fields } = foundry.data; const { fields } = foundry.data;
export class WeaponData extends foundry.abstract.TypeDataModel { export class WeaponData extends CommonItemData {
// MARK: Schema // MARK: Schema
static defineSchema() { static defineSchema() {
return { return {
...super.defineSchema(),
traits: new fields.SetField( traits: new fields.SetField(
new fields.StringField({ new fields.StringField({
blank: false, blank: false,
@ -59,6 +61,14 @@ export class WeaponData extends foundry.abstract.TypeDataModel {
// #region Sheet Data // #region Sheet Data
getFormFields(_ctx) { getFormFields(_ctx) {
const fields = [ const fields = [
{
id: `quantity`,
type: `integer`,
label: `RipCrypt.common.quantity`,
path: `system.quantity`,
value: this.quantity,
min: 0,
},
{ {
id: `traits`, id: `traits`,
type: `string-set`, type: `string-set`,

View file

@ -0,0 +1,8 @@
export class RipCryptItem extends Item {
get quantifiedName() {
if (this.system.quantity != null && this.system.quantity !== 1) {
return `${this.name} (${this.system.quantity})`;
}
return this.name;
};
};

View file

@ -12,6 +12,9 @@ import { WeaponData } from "../data/Item/Weapon.mjs";
// Class Overrides // Class Overrides
import { CryptDie } from "../dice/CryptDie.mjs"; import { CryptDie } from "../dice/CryptDie.mjs";
// Documents
import { RipCryptItem } from "../documents/item.mjs";
// Misc // Misc
import helpers from "../handlebarHelpers/_index.mjs"; import helpers from "../handlebarHelpers/_index.mjs";
import { Logger } from "../utils/Logger.mjs"; import { Logger } from "../utils/Logger.mjs";
@ -37,6 +40,7 @@ Hooks.once(`init`, () => {
// #endregion // #endregion
// #region Class Changes // #region Class Changes
CONFIG.Item.documentClass = RipCryptItem;
CONFIG.Dice.terms.d = CryptDie; CONFIG.Dice.terms.d = CryptDie;
// #endregion // #endregion

View file

@ -230,7 +230,7 @@
data-action="editItem" data-action="editItem"
></rc-icon> --}} ></rc-icon> --}}
<span class="ellipses"> <span class="ellipses">
{{ slot.data.name }} {{ slot.data.quantifiedName }}
</span> </span>
</td> </td>
<td> <td>