-
Notifications
You must be signed in to change notification settings - Fork 7
/
Element.ts
43 lines (34 loc) · 1.29 KB
/
Element.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import { JsonObject, JsonReader } from "config_file.js";
import { EnkaClient } from "../client/EnkaClient";
import { AssetsNotFoundError } from "../errors/AssetsNotFoundError";
import { TextAssets } from "./assets/TextAssets";
export class Element {
readonly id: ElementType;
readonly enka: EnkaClient;
readonly name: TextAssets;
readonly _data: JsonObject;
constructor(data: JsonObject, enka: EnkaClient) {
this._data = data;
this.enka = enka;
const json = new JsonReader(this._data);
this.id = json.getAsString("textMapId") as ElementType;
this.name = new TextAssets(json.getAsNumber("textMapContentTextMapHash"), enka);
}
static getByElementType(elementType: ElementType, enka: EnkaClient): Element {
const json = enka.cachedAssetsManager.getGenshinCacheData("ManualTextMapConfigData").findArray((_, p) => p.getAsString("textMapId") === elementType)?.[1];
if (!json) throw new AssetsNotFoundError("Element", elementType);
return new Element(json.getAsJsonObject(), enka);
}
}
/**
* ElementType|In-game Name
* ---|---
* Wind|Anemo
* Rock|Geo
* Electric|Electro
* Grass|Dendro
* Water|Hydro
* Fire|Pyro
* Ice|Cryo
*/
export type ElementType = "Wind" | "Rock" | "Electric" | "Grass" | "Water" | "Fire" | "Ice";