mirror of
https://github.com/Melledy/Grasscutter.git
synced 2024-11-23 11:26:07 +00:00
Fix data parsing with CSVs
This commit is contained in:
parent
5fe304d2e8
commit
44b90612f2
@ -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
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -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"
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user