From b5393296622d73bc466caaebfb60f5ef6afe311c Mon Sep 17 00:00:00 2001 From: "Kyle J. Kemp" Date: Thu, 12 Sep 2024 08:32:44 -0500 Subject: [PATCH] don't lowercase types or assume anything about them. fix auto-weapon-skill selector to be lowercase --- src/app/helpers/constants.ts | 48 ++++++++++++++--------------- src/app/helpers/export/item.ts | 6 +--- src/app/helpers/schemas/_helpers.ts | 9 ++++++ src/app/helpers/schemas/item.ts | 8 +++-- src/interfaces/itemtypes.ts | 1 + 5 files changed, 40 insertions(+), 32 deletions(-) diff --git a/src/app/helpers/constants.ts b/src/app/helpers/constants.ts index 4391ca4..0a7b0f9 100644 --- a/src/app/helpers/constants.ts +++ b/src/app/helpers/constants.ts @@ -1,5 +1,5 @@ import { sortBy } from 'lodash'; -import { StatBlock } from '../../interfaces'; +import { SkillType, StatBlock } from '../../interfaces'; export const coreStats = sortBy( [ @@ -276,30 +276,30 @@ export const typePropDefaults: Record< export const typePropPrimarySecondary: Record< string, - { p: string; s?: string } + { p: SkillType; s?: SkillType } > = { - Axe: { p: 'Axe' }, - Blunderbuss: { p: 'Ranged', s: 'Twohanded' }, - Broadsword: { p: 'Sword' }, - Club: { p: 'Mace' }, - Crossbow: { p: 'Ranged' }, - Dagger: { p: 'Dagger' }, - Flail: { p: 'Mace' }, - Greataxe: { p: 'Axe', s: 'Twohanded' }, - Greatmace: { p: 'Mace', s: 'Twohanded' }, - Greatsword: { p: 'Twohanded' }, - Halberd: { p: 'Polearm', s: 'Twohanded' }, - Hammer: { p: 'Mace' }, - Longbow: { p: 'Ranged', s: 'Twohanded' }, - Longsword: { p: 'Sword' }, - Mace: { p: 'Mace' }, - Shield: { p: 'Mace' }, - Shortbow: { p: 'Ranged' }, - Shortsword: { p: 'Shortsword' }, - Spear: { p: 'Staff' }, - Staff: { p: 'Staff' }, - Totem: { p: 'Wand' }, - Wand: { p: 'Wand' }, + Axe: { p: 'axe' }, + Blunderbuss: { p: 'ranged', s: 'twohanded' }, + Broadsword: { p: 'sword' }, + Club: { p: 'mace' }, + Crossbow: { p: 'ranged' }, + Dagger: { p: 'dagger' }, + Flail: { p: 'mace' }, + Greataxe: { p: 'axe', s: 'twohanded' }, + Greatmace: { p: 'mace', s: 'twohanded' }, + Greatsword: { p: 'twohanded' }, + Halberd: { p: 'polearm', s: 'twohanded' }, + Hammer: { p: 'mace' }, + Longbow: { p: 'ranged', s: 'twohanded' }, + Longsword: { p: 'sword' }, + Mace: { p: 'mace' }, + Shield: { p: 'mace' }, + Shortbow: { p: 'ranged' }, + Shortsword: { p: 'shortsword' }, + Spear: { p: 'staff' }, + Staff: { p: 'staff' }, + Totem: { p: 'wand' }, + Wand: { p: 'wand' }, }; itemClasses.forEach((itemType) => { diff --git a/src/app/helpers/export/item.ts b/src/app/helpers/export/item.ts index 6352556..c83d25f 100644 --- a/src/app/helpers/export/item.ts +++ b/src/app/helpers/export/item.ts @@ -1,5 +1,5 @@ import { isNumber, isString, isUndefined } from 'lodash'; -import { IItemDefinition, SkillType } from '../../../interfaces'; +import { IItemDefinition } from '../../../interfaces'; const WeaponClasses = [ 'Axe', @@ -178,10 +178,6 @@ const conditionallyAddInformation = (item: IItemDefinition) => { max: item.randomTrait.level, }; } - - item.type = item.type.toLowerCase() as SkillType; - if (item.secondaryType) - item.secondaryType = item.secondaryType.toLowerCase() as SkillType; }; function fillInItemProperties(itemData: IItemDefinition) { diff --git a/src/app/helpers/schemas/_helpers.ts b/src/app/helpers/schemas/_helpers.ts index 3283c0b..e55180c 100644 --- a/src/app/helpers/schemas/_helpers.ts +++ b/src/app/helpers/schemas/_helpers.ts @@ -11,6 +11,7 @@ import { Allegiance, DamageClass, HasIdentification, + ItemClass, ItemSlot, ITraitTreeRowTrait, QuestRewardType, @@ -123,6 +124,14 @@ export const isPartialReputationObject = isPartialObjectOf( export const isPartialReputationObjectFailure = isPartialObjectOfFailure(Object.values(Allegiance)); +export function isItemClass(val: any): boolean { + return Object.values(ItemClass).includes(val as ItemClass); +} + +export function isSkill(val: any): boolean { + return Object.values(Skill).includes(val as Skill); +} + export function isItemSlot(val: any): boolean { return itemSlots.includes(val as ItemSlot); } diff --git a/src/app/helpers/schemas/item.ts b/src/app/helpers/schemas/item.ts index 401e7a2..9dae3ce 100644 --- a/src/app/helpers/schemas/item.ts +++ b/src/app/helpers/schemas/item.ts @@ -6,6 +6,7 @@ import { isCosmetic, isEffect, isIntegerBetween, + isItemClass, isItemSlot, isObjectWithSome, isObjectWithSomeFailure, @@ -15,6 +16,7 @@ import { isRandomTraitObject, isRequirement, isRollable, + isSkill, isSuccor, isTrait, } from './_helpers'; @@ -25,8 +27,9 @@ export const itemSchema: Schema = [ ['animation', false, isInteger], ['value', true, isInteger], ['desc', true, isString], - ['itemClass', true, isString], - ['type', true, isString], + ['itemClass', true, isItemClass], + ['type', true, isSkill], + ['secondaryType', false, isSkill], ['binds', false, isBoolean], ['tellsBind', false, isBoolean], @@ -34,7 +37,6 @@ export const itemSchema: Schema = [ ['isBeltable', false, isBoolean], ['isSackable', false, isBoolean], ['isHeavy', false, isBoolean], - ['secondaryType', false, isString], ['stats', false, isPartialStatObject, isPartialStatObjectFailure], ['maxUpgrades', false, isInteger], ['canUpgradeWith', false, isBoolean], diff --git a/src/interfaces/itemtypes.ts b/src/interfaces/itemtypes.ts index a444a23..d9fc878 100644 --- a/src/interfaces/itemtypes.ts +++ b/src/interfaces/itemtypes.ts @@ -73,6 +73,7 @@ export enum ArmorClass { } export enum MiscClass { + Abacus = 'Abacus', Book = 'Book', Bottle = 'Bottle', Box = 'Box',