Sort item data

This commit is contained in:
KingRainbow44 2023-04-08 00:18:06 -04:00
parent 74cff61824
commit 181eb56471
No known key found for this signature in database
GPG Key ID: FC2CB64B00D257BE
4 changed files with 61 additions and 2 deletions

View File

@ -2,11 +2,48 @@ 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 { Quality, ItemType, ItemCategory } from "@backend/types";
import type { Command, Avatar, Item } from "@backend/types";
import { inRange } from "@app/utils";
type AvatarDump = { [key: number]: Avatar };
type CommandDump = { [key: string]: Command };
type TaggedItems = { [key: number]: Item[] }
/*
* Notes on artifacts:
* TODO: Figure out what suffix is for which artifact type.
*/
const sortedItems: TaggedItems = {
[ItemCategory.Constellation]: [], // Range: 1102 - 11xx
[ItemCategory.Weapon]: [],
[ItemCategory.Artifact]: [],
[ItemCategory.Furniture]: [],
[ItemCategory.Material]: [],
[ItemCategory.Miscellaneous]: []
};
/**
* Setup function for this file.
* Sorts all items into their respective categories.
*/
export function setup(): void {
getItems().forEach(item => {
switch (item.type) {
case ItemType.Weapon: sortedItems[ItemCategory.Weapon].push(item); break;
case ItemType.Material: sortedItems[ItemCategory.Material].push(item); break;
case ItemType.Furniture: sortedItems[ItemCategory.Furniture].push(item); break;
case ItemType.Reliquary: sortedItems[ItemCategory.Artifact].push(item); break;
}
// Sort constellations.
if (inRange(item.id, 1102, 1199)) {
sortedItems[ItemCategory.Constellation].push(item);
}
});
}
/**
* Fetches and casts all commands in the file.

View File

@ -47,6 +47,15 @@ export enum ItemType {
Furniture = "ITEM_FURNITURE"
}
export enum ItemCategory {
Constellation,
Weapon,
Artifact,
Furniture,
Material,
Miscellaneous
}
/**
* Checks if a string is a page.
*

View File

@ -1,11 +1,13 @@
import React from "react";
import { createRoot } from "react-dom/client";
import * as data from "@backend/data";
import * as events from "@backend/events";
import App from "@components/App";
import App from "@ui/App";
// Call initial setup functions.
data.setup();
events.setup();
// Render the application.

View File

@ -21,3 +21,14 @@ export function colorFor(quality: Quality): string {
return "--unknown-color";
}
}
/**
* Checks if a value is between two numbers.
*
* @param value The value to check.
* @param min The minimum value.
* @param max The maximum value.
*/
export function inRange(value: number, min: number, max: number): boolean {
return value >= min && value <= max;
}