mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2025-02-05 07:02:53 +08:00
Sort item data
This commit is contained in:
parent
74cff61824
commit
181eb56471
@ -2,11 +2,48 @@ import commands from "@data/commands.json";
|
|||||||
import avatars from "@data/avatars.csv";
|
import avatars from "@data/avatars.csv";
|
||||||
import items from "@data/items.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 type { Command, Avatar, Item } from "@backend/types";
|
||||||
|
|
||||||
|
import { inRange } from "@app/utils";
|
||||||
|
|
||||||
type AvatarDump = { [key: number]: Avatar };
|
type AvatarDump = { [key: number]: Avatar };
|
||||||
type CommandDump = { [key: string]: Command };
|
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.
|
* Fetches and casts all commands in the file.
|
||||||
|
@ -47,6 +47,15 @@ export enum ItemType {
|
|||||||
Furniture = "ITEM_FURNITURE"
|
Furniture = "ITEM_FURNITURE"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export enum ItemCategory {
|
||||||
|
Constellation,
|
||||||
|
Weapon,
|
||||||
|
Artifact,
|
||||||
|
Furniture,
|
||||||
|
Material,
|
||||||
|
Miscellaneous
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if a string is a page.
|
* Checks if a string is a page.
|
||||||
*
|
*
|
||||||
|
@ -1,11 +1,13 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import { createRoot } from "react-dom/client";
|
import { createRoot } from "react-dom/client";
|
||||||
|
|
||||||
|
import * as data from "@backend/data";
|
||||||
import * as events from "@backend/events";
|
import * as events from "@backend/events";
|
||||||
|
|
||||||
import App from "@components/App";
|
import App from "@ui/App";
|
||||||
|
|
||||||
// Call initial setup functions.
|
// Call initial setup functions.
|
||||||
|
data.setup();
|
||||||
events.setup();
|
events.setup();
|
||||||
|
|
||||||
// Render the application.
|
// Render the application.
|
||||||
|
@ -21,3 +21,14 @@ export function colorFor(quality: Quality): string {
|
|||||||
return "--unknown-color";
|
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;
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user