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

@ -96,7 +96,7 @@ export class HeroSkillsCardV1 extends GenericAppMixin(HandlebarsApplicationMixin
ctx.gear.push({
index: ctx.gear.length,
uuid: item.uuid,
name: item.name,
name: item.quantifiedName,
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 { requiredInteger } from "../helpers.mjs";
const { fields } = foundry.data;
/** Used for Armour and Shields */
export class ProtectorData extends foundry.abstract.TypeDataModel {
export class ProtectorData extends CommonItemData {
// MARK: Schema
static defineSchema() {
return {
...super.defineSchema(),
protection: requiredInteger({ min: 0, initial: 1 }),
location: new fields.SetField(
new fields.StringField({
@ -48,6 +50,14 @@ export class ProtectorData extends foundry.abstract.TypeDataModel {
// #region Sheet Data
getFormFields(_ctx) {
const fields = [
{
id: `quantity`,
type: `integer`,
label: `RipCrypt.Apps.quantity`,
path: `system.quantity`,
value: this.quantity,
min: 0,
},
{
id: `location`,
type: `string-set`,

View file

@ -1,12 +1,14 @@
import { barAttribute, optionalInteger, requiredInteger } from "../helpers.mjs";
import { CommonItemData } from "./Common.mjs";
import { gameTerms } from "../../gameTerms.mjs";
const { fields } = foundry.data;
export class WeaponData extends foundry.abstract.TypeDataModel {
export class WeaponData extends CommonItemData {
// MARK: Schema
static defineSchema() {
return {
...super.defineSchema(),
traits: new fields.SetField(
new fields.StringField({
blank: false,
@ -59,6 +61,14 @@ export class WeaponData extends foundry.abstract.TypeDataModel {
// #region Sheet Data
getFormFields(_ctx) {
const fields = [
{
id: `quantity`,
type: `integer`,
label: `RipCrypt.common.quantity`,
path: `system.quantity`,
value: this.quantity,
min: 0,
},
{
id: `traits`,
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
import { CryptDie } from "../dice/CryptDie.mjs";
// Documents
import { RipCryptItem } from "../documents/item.mjs";
// Misc
import helpers from "../handlebarHelpers/_index.mjs";
import { Logger } from "../utils/Logger.mjs";
@ -37,6 +40,7 @@ Hooks.once(`init`, () => {
// #endregion
// #region Class Changes
CONFIG.Item.documentClass = RipCryptItem;
CONFIG.Dice.terms.d = CryptDie;
// #endregion