From e42d53925f1cb856067428db976e41c923b8c26c Mon Sep 17 00:00:00 2001 From: Kyle Kemp Date: Sat, 17 Aug 2024 06:32:03 -0500 Subject: [PATCH] closes #48 --- src/app/helpers/constants.ts | 2 +- src/app/helpers/schemas/_helpers.ts | 22 ++++++++------- src/app/helpers/schemas/item.ts | 19 +++++++++++-- .../items-editor/items-editor.component.html | 27 +++++++++++++++++++ .../items-editor/items-editor.component.ts | 20 ++++++++++++++ 5 files changed, 78 insertions(+), 12 deletions(-) diff --git a/src/app/helpers/constants.ts b/src/app/helpers/constants.ts index 6e0b2a9..4391ca4 100644 --- a/src/app/helpers/constants.ts +++ b/src/app/helpers/constants.ts @@ -269,7 +269,7 @@ export const typePropDefaults: Record< Bottle: { ounces: 1 }, Food: { ounces: 1 }, Gem: {}, - Book: { bookPages: [], bookItemFilter: '', bookFindablePages: '' }, + Book: { bookPages: [], bookItemFilter: '', bookFindablePages: 0 }, Trap: { trapUses: 1 }, Twig: { type: 'Staff' }, }; diff --git a/src/app/helpers/schemas/_helpers.ts b/src/app/helpers/schemas/_helpers.ts index f0c9eed..9d3d944 100644 --- a/src/app/helpers/schemas/_helpers.ts +++ b/src/app/helpers/schemas/_helpers.ts @@ -94,11 +94,17 @@ export const isPartialSkillObjectFailure = isPartialObjectOfFailure( Object.values(Skill) ); -export const isPartialEquipmentObject = isPartialObjectOf( - Object.values(ItemSlot) -); +export const isPartialEquipmentObject = isPartialObjectOf([ + 'weapon', + 'armor', + ...Object.values(ItemSlot), +] as ItemSlot[]); export const isPartialEquipmentObjectFailure = - isPartialObjectOfFailure(Object.values(ItemSlot)); + isPartialObjectOfFailure([ + 'weapon', + 'armor', + ...Object.values(ItemSlot), + ] as ItemSlot[]); export const isPartialReputationObject = isPartialObjectOf( Object.values(Allegiance) @@ -107,7 +113,9 @@ export const isPartialReputationObjectFailure = isPartialObjectOfFailure(Object.values(Allegiance)); export function isItemSlot(val: any): boolean { - return Object.values(ItemSlot).includes(val as ItemSlot); + return ( + ['weapon', 'armor', ...Object.values(ItemSlot)] as ItemSlot[] + ).includes(val as ItemSlot); } export function isTraitObject(val: any): boolean { @@ -204,10 +212,6 @@ export function isEffect(eff: any): boolean { return eff.name && isNumber(eff.potency); } -export function isEncrust(enc: any): boolean { - return !!(enc.stats || enc.equipEffect || enc.strikeEffect); -} - export function isBookPage(val: any): boolean { return val.id === '' && isString(val.text); } diff --git a/src/app/helpers/schemas/item.ts b/src/app/helpers/schemas/item.ts index 5719a50..e8c6f0c 100644 --- a/src/app/helpers/schemas/item.ts +++ b/src/app/helpers/schemas/item.ts @@ -5,8 +5,10 @@ import { isBookPage, isCosmetic, isEffect, - isEncrust, isIntegerBetween, + isItemSlot, + isObjectWithSome, + isObjectWithSomeFailure, isPartialStatObject, isPartialStatObjectFailure, isRandomStatObject, @@ -81,7 +83,20 @@ export const itemSchema: Schema = [ ['breakEffect.name', false, isString], ['breakEffect.potency', false, isInteger], - ['encrustGive', false, isEncrust], + [ + 'encrustGive', + false, + isObjectWithSome(['slots', 'stats', 'strikeEffect']), + isObjectWithSomeFailure(['slots', 'stats', 'strikeEffect']), + ], + ['encrustGive.slots', false, isArrayOf(isItemSlot)], + ['encrustGive.stats', false, isPartialStatObject, isPartialStatObjectFailure], + ['encrustGive.strikeEffect', false, isEffect], + ['encrustGive.strikeEffect.name', false, isString], + ['encrustGive.strikeEffect.potency', false, isInteger], + ['encrustGive.strikeEffect.chance', false, isIntegerBetween(0, 100)], + ['encrustGive.strikeEffect.duration', false, isInteger], + ['encrustGive.strikeEffect.range', false, isIntegerBetween(0, 5)], ['tier', false, isInteger], ['destroyOnDrop', false, isBoolean], diff --git a/src/app/tabs/items/items-editor/items-editor.component.html b/src/app/tabs/items/items-editor/items-editor.component.html index ddac15e..5222ab7 100644 --- a/src/app/tabs/items/items-editor/items-editor.component.html +++ b/src/app/tabs/items/items-editor/items-editor.component.html @@ -319,6 +319,33 @@ } + @case('bookPages') { +
+ +
+ + @for(item of editingData.bookPages; track item) { +
+
+
+ Page Text + +
+
+ +
+
+ +
+
+
+ } + } + @default { {{ prop }} ({{ propTypes[prop] }}) has no editor. } diff --git a/src/app/tabs/items/items-editor/items-editor.component.ts b/src/app/tabs/items/items-editor/items-editor.component.ts index 5f27a06..e1c820d 100644 --- a/src/app/tabs/items/items-editor/items-editor.component.ts +++ b/src/app/tabs/items/items-editor/items-editor.component.ts @@ -182,6 +182,8 @@ export class ItemsEditorComponent chance: 0, }; + item.bookPages ??= []; + this.editing.set(item); } @@ -505,6 +507,10 @@ export class ItemsEditorComponent delete item.encrustGive; } } + + if (!item.bookPages?.length) { + delete item.bookPages; + } } changeTraitTab(newTraitSetting: TraitSetting) { @@ -549,6 +555,20 @@ export class ItemsEditorComponent this.editing.set(item); } + public addBookPage() { + const item = this.editing(); + item.bookPages?.push({ id: '', text: '' }); + + this.editing.set(item); + } + + public removeBookPage(index: number) { + const item = this.editing(); + item.bookPages?.splice(index, 1); + + this.editing.set(item); + } + public doSave() { const item = this.editing(); this.assignStats(item);