Skip to content

Commit

Permalink
don't lowercase types or assume anything about them. fix auto-weapon-…
Browse files Browse the repository at this point in the history
…skill selector to be lowercase
  • Loading branch information
seiyria committed Sep 12, 2024
1 parent a297551 commit b539329
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 32 deletions.
48 changes: 24 additions & 24 deletions src/app/helpers/constants.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { sortBy } from 'lodash';
import { StatBlock } from '../../interfaces';
import { SkillType, StatBlock } from '../../interfaces';

export const coreStats = sortBy(
[
Expand Down Expand Up @@ -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) => {
Expand Down
6 changes: 1 addition & 5 deletions src/app/helpers/export/item.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { isNumber, isString, isUndefined } from 'lodash';
import { IItemDefinition, SkillType } from '../../../interfaces';
import { IItemDefinition } from '../../../interfaces';

const WeaponClasses = [
'Axe',
Expand Down Expand Up @@ -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) {
Expand Down
9 changes: 9 additions & 0 deletions src/app/helpers/schemas/_helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
Allegiance,
DamageClass,
HasIdentification,
ItemClass,
ItemSlot,
ITraitTreeRowTrait,
QuestRewardType,
Expand Down Expand Up @@ -123,6 +124,14 @@ export const isPartialReputationObject = isPartialObjectOf<Allegiance>(
export const isPartialReputationObjectFailure =
isPartialObjectOfFailure<Allegiance>(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);
}
Expand Down
8 changes: 5 additions & 3 deletions src/app/helpers/schemas/item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
isCosmetic,
isEffect,
isIntegerBetween,
isItemClass,
isItemSlot,
isObjectWithSome,
isObjectWithSomeFailure,
Expand All @@ -15,6 +16,7 @@ import {
isRandomTraitObject,
isRequirement,
isRollable,
isSkill,
isSuccor,
isTrait,
} from './_helpers';
Expand All @@ -25,16 +27,16 @@ 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],
['extendedDesc', false, isString],
['isBeltable', false, isBoolean],
['isSackable', false, isBoolean],
['isHeavy', false, isBoolean],
['secondaryType', false, isString],
['stats', false, isPartialStatObject, isPartialStatObjectFailure],
['maxUpgrades', false, isInteger],
['canUpgradeWith', false, isBoolean],
Expand Down
1 change: 1 addition & 0 deletions src/interfaces/itemtypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export enum ArmorClass {
}

export enum MiscClass {
Abacus = 'Abacus',
Book = 'Book',
Bottle = 'Bottle',
Box = 'Box',
Expand Down

0 comments on commit b539329

Please sign in to comment.