Parse data into types

This commit is contained in:
Magix 2023-04-06 22:13:17 +00:00
parent a12bcef065
commit 4664a21fab
2 changed files with 76 additions and 1 deletions

View File

@ -2,4 +2,32 @@ import avatars from "@data/avatars.json";
import commands from "@data/commands.json";
import items from "@data/items.csv";
console.log(avatars, commands, items);
import type { Command, Avatar, Item } from "@backend/types";
/**
* Fetches and casts all commands in the file.
*/
export function getCommands(): { [key: string]: Command } {
return commands as { [key: string]: Command };
}
/**
* Fetches and casts all avatars in the file.
*/
export function getAvatars(): { [key: number]: Avatar } {
return avatars as { [key: number] : Avatar };
}
/**
* Fetches and casts all items in the file.
*/
export function getItems(): Item[] {
return items.map(item => {
return {
id: item[0],
name: item[1],
quality: item[2],
type: item[3]
};
});
}

View File

@ -1,5 +1,52 @@
export type Page = "Home" | "Commands";
export type Command = {
name: string[];
description: string;
usage: string[];
permission: string[];
target: Target;
};
export type Avatar = {
name: string;
quality: Quality;
id: number;
};
export type Item = {
id: number;
name: string;
quality: Quality;
type: ItemType;
}
export enum Target {
None = "NONE",
Offline = "OFFLINE",
Player = "PLAYER",
Online = "ONLINE"
}
export enum Quality {
Legendary = "LEGENDARY",
Epic = "EPIC",
Rare = "RARE",
Uncommon = "UNCOMMON",
Common = "COMMON",
Unknown = "UNKNOWN"
}
export enum ItemType {
None = 0,
Virtual = 1,
Material = 2,
Reliquary = 3,
Weapon = 4,
Display = 5,
Furniture = 6
}
/**
* Checks if a string is a page.
*