diff --git a/src/handbook/src/backend/data.ts b/src/handbook/src/backend/data.ts index 97a7e80fa..49de2f7b4 100644 --- a/src/handbook/src/backend/data.ts +++ b/src/handbook/src/backend/data.ts @@ -2,8 +2,11 @@ import commands from "@data/commands.json"; import avatars from "@data/avatars.csv"; import items from "@data/items.csv"; +import { Quality, ItemType } from "@backend/types"; import type { Command, Avatar, Item } from "@backend/types"; +type AvatarDump = { [key: number]: Avatar }; + /** * Fetches and casts all commands in the file. */ @@ -14,8 +17,19 @@ export function getCommands(): { [key: string]: Command } { /** * Fetches and casts all avatars in the file. */ -export function getAvatars(): { [key: number]: Avatar } { - return avatars as { [key: number] : Avatar }; +export function getAvatars(): AvatarDump { + const map: AvatarDump = {}; avatars.forEach(avatar => { + const values = Object.values(avatar) as + [string, string, string]; + const id = parseInt(values[0]); + map[id] = { + id, + name: values[1], + quality: values[2] as Quality + }; + }); + + return map; } /** @@ -23,11 +37,14 @@ export function getAvatars(): { [key: number]: Avatar } { */ export function getItems(): Item[] { return items.map(item => { + const values = Object.values(item) as + [string, string, string, string]; + const id = parseInt(values[0]); return { - id: item[0], - name: item[1], - quality: item[2], - type: item[3] - }; + id, + name: values[1], + type: values[2] as ItemType, + quality: values[3] as Quality + } }); } diff --git a/src/handbook/src/backend/types.ts b/src/handbook/src/backend/types.ts index d1be6ae03..35b9bc9c0 100644 --- a/src/handbook/src/backend/types.ts +++ b/src/handbook/src/backend/types.ts @@ -38,13 +38,13 @@ export enum Quality { } export enum ItemType { - None = 0, - Virtual = 1, - Material = 2, - Reliquary = 3, - Weapon = 4, - Display = 5, - Furniture = 6 + None = "ITEM_NONE", + Virtual = "ITEM_VIRTUAL", + Material = "ITEM_MATERIAL", + Reliquary = "ITEM_RELIQUARY", + Weapon = "ITEM_WEAPON", + Display = "ITEM_DISPLAY", + Furniture = "ITEM_FURNITURE" } /**