Skip to content

Commit

Permalink
add RelicType class
Browse files Browse the repository at this point in the history
  • Loading branch information
yuko1101 committed Jun 17, 2023
1 parent d3691fd commit 31c5d49
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# 0.4.2
- Renamed StatProperty#statPropertyType to StatProperty#type.
- Renamed typedef RelicType to RelicTypeId, and added RelicType class.
- Changed type of RelicData#type to RelicType (class).
# 0.4.1
- Changed type of CharacterStats#overallStats to OverlayStatList. (forgot updating)
# 0.4.0
Expand Down
8 changes: 8 additions & 0 deletions src/client/CachedAssetsManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ const contents = [
"RelicSubAffixConfig", // Relic Sub Stats
"RelicSetConfig", // Relic Sets
"RelicSetSkillConfig", // Relic Set Bonus
"RelicBaseType", // Relic Types
"AvatarPropertyConfig", // StatProperty
"AvatarPlayerIcon", // Character Icon for a player
"PlayerIcon", // Other Icon for a player
Expand Down Expand Up @@ -532,6 +533,13 @@ class CachedAssetsManager {
});
});

Object.values(data["RelicBaseType"]).forEach(t => {
const json = new JsonReader(t);
push(
json.getAsNumber("BaseTypeText", "Hash"),
);
});

Object.values(data["AvatarPropertyConfig"]).forEach(s => {
const json = new JsonReader(s);
push(
Expand Down
4 changes: 3 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import RelicMainStatGroup from "./models/relic/RelicMainStatGroup";
import RelicSet from "./models/relic/RelicSet";
import RelicSetBonus from "./models/relic/RelicSetBonus";
import RelicSubStatGroup from "./models/relic/RelicSubStatGroup";
import RelicType from "./models/relic/RelicType";
import CombatType from "./models/CombatType";
import Path from "./models/Path";
import StatProperty, { StatPropertyValue } from "./models/StatProperty";
Expand Down Expand Up @@ -63,6 +64,7 @@ export {
RelicSet,
RelicSetBonus,
RelicSubStatGroup,
RelicType,
CombatType,
Path,
StatProperty,
Expand All @@ -76,10 +78,10 @@ export { ClientOptions } from "./client/StarRail";
export { ImageBaseUrl } from "./models/assets/ImageAssets";
export { AttackType, EffectType } from "./models/character/skill/Skill";
export { LightConeLevel } from "./models/light_cone/LightConeExpType";
export { RelicType } from "./models/relic/RelicData";
export { RelicLevel } from "./models/relic/RelicExpType";
export { RelicMainStatData } from "./models/relic/RelicMainStatGroup";
export { RelicSubStatData } from "./models/relic/RelicSubStatGroup";
export { RelicTypeId } from "./models/relic/RelicType";
export { CombatTypeId } from "./models/CombatType";
export { PathId } from "./models/Path";
export { StatPropertyType, OtherStatPropertyType } from "./models/StatProperty";
Expand Down
6 changes: 2 additions & 4 deletions src/models/relic/RelicData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ import RelicSubStatGroup from "./RelicSubStatGroup";
import RelicSet from "./RelicSet";
import TextAssets from "../assets/TextAssets";
import ImageAssets from "../assets/ImageAssets";

/** @typedef */
export type RelicType = "HEAD" | "HAND" | "BODY" | "FOOT" | "OBJECT" | "NECK";
import RelicType, { RelicTypeId } from "./RelicType";

/**
* @en RelicData
Expand Down Expand Up @@ -72,7 +70,7 @@ class RelicData {
this.name = new TextAssets(itemJson.getAsNumber("ItemName", "Hash"), this.client);
this.description = new TextAssets(itemJson.getAsNumber("ItemBGDesc", "Hash"), this.client);

this.type = json.getAsString("Type") as RelicType;
this.type = new RelicType(json.getAsString("Type") as RelicTypeId, this.client);

this.stars = Number(json.getAsString("Rarity").slice(-1));

Expand Down
56 changes: 56 additions & 0 deletions src/models/relic/RelicType.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { JsonObject, JsonReader } from "config_file.js";
import StarRail from "../../client/StarRail";
import AssetsNotFoundError from "../../errors/AssetsNotFoundError";
import TextAssets from "../assets/TextAssets";
import ImageAssets from "../assets/ImageAssets";

/**
* @typedef
* @example
* |RelicTypeId|In-game Name|
* |---|---|
* |HEAD|Head|
* |HAND|Hands|
* |BODY|Body|
* |FOOT|Feet|
* |OBJECT|Link Rope|
* |NECK|Planar Sphere|
*/
export type RelicTypeId = "HEAD" | "HAND" | "BODY" | "FOOT" | "OBJECT" | "NECK";

/**
* @en RelicType
*/
class RelicType {
/** */
readonly id: RelicTypeId;
/** */
readonly client: StarRail;

/** */
readonly name: TextAssets;
/** */
readonly icon: ImageAssets;

readonly _data: JsonObject;

/**
* @param id
* @param client
*/
constructor(id: RelicTypeId, client: StarRail) {
this.id = id;
this.client = client;

const _data = client.cachedAssetsManager.getStarRailCacheData("RelicBaseType")[this.id];
if (!_data) throw new AssetsNotFoundError("RelicType", this.id);
this._data = _data;

const json = new JsonReader(this._data);

this.name = new TextAssets(json.getAsNumber("BaseTypeText", "Hash"), this.client);
this.icon = new ImageAssets(json.getAsString("BaseTypeIconPath"), this.client);
}
}

export default RelicType;

1 comment on commit 31c5d49

@vercel
Copy link

@vercel vercel bot commented on 31c5d49 Jun 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

starrail – ./

starrail.vercel.app
starrail-git-main-yuko1101.vercel.app
starrail-yuko1101.vercel.app

Please sign in to comment.