Skip to content

Commit

Permalink
added Character#costume
Browse files Browse the repository at this point in the history
  • Loading branch information
yuko1101 committed Jan 16, 2025
1 parent 0e8a539 commit 73ff6e4
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# 1.7.5
- Added Character#costume.
# 1.7.4
- Fixed a parsing error with servant skills in HSR v3.0.
- Added Skill#isServant.
Expand Down
8 changes: 8 additions & 0 deletions src/client/CachedAssetsManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export const excelKeyMap = {
"AvatarSkillTreeConfig": ["PointID", "Level"], // Character Skill Trees
"AvatarRankConfig": ["RankID"], // Character Eidolons
"AvatarPromotionConfig": ["AvatarID", ["Promotion", 0]], // Character Promotions and Character Basic Stats.
"AvatarSkin": ["ID"], // Costumes

"EquipmentConfig": ["EquipmentID"], // Light Cones
"ItemConfigEquipment": ["ID"], // Light Cones as Items
Expand Down Expand Up @@ -492,6 +493,13 @@ export class CachedAssetsManager {
);
});

Object.values(data["AvatarSkin"]).forEach(s => {
const json = new JsonReader(s);
push(
json.getAsNumber("AvatarSkinName", "Hash"),
);
});

Object.values(data["EquipmentConfig"]).forEach(l => {
const json = new JsonReader(l);
push(
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export * from "./models/character/skill/SkillTreeNode";
export * from "./models/character/Character";
export * from "./models/character/CharacterData";
export * from "./models/character/CharacterStats";
export * from "./models/character/Costume";
export * from "./models/character/Eidolon";
export * from "./models/enka/StarRailCharacterBuild";
export * from "./models/light_cone/LightCone";
Expand Down
4 changes: 4 additions & 0 deletions src/models/character/Character.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { CharacterStats } from "./CharacterStats";
import { LeveledSkill } from "./skill/Skill";
import { SkillLevel } from "./skill/SkillLevel";
import { nonNullable } from "../../utils/ts_utils";
import { Costume } from "./Costume";

export class Character {
readonly client: StarRail;
Expand All @@ -20,6 +21,7 @@ export class Character {
readonly exp: number;
readonly ascension: number;
readonly eidolons: number;
readonly costume: Costume | null;
readonly skillTreeNodes: LeveledSkillTreeNode[];
readonly skills: LeveledSkill[];
readonly basicStats: StatPropertyValue[];
Expand All @@ -43,6 +45,8 @@ export class Character {
this.ascension = json.getAsNumberWithDefault(0, "promotion");
this.eidolons = json.getAsNumberWithDefault(0, "rank");

this.costume = json.has("dressedSkinId") ? new Costume(json.getAsNumber("dressedSkinId"), this.client) : null;

const unlockedEidolons = this.characterData.eidolons.slice(0, this.eidolons);

this.skillTreeNodes = json.get("skillTreeList").mapArray((_, skill) => {
Expand Down
29 changes: 29 additions & 0 deletions src/models/character/Costume.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { JsonObject, JsonReader } from "config_file.js";
import { StarRail } from "../../client/StarRail";
import { AssetsNotFoundError } from "../../errors/AssetsNotFoundError";
import { TextAssets } from "../assets/TextAssets";

export class Costume {
readonly id: number;
readonly client: StarRail;

readonly name: TextAssets;
readonly characterId: number;

readonly _data: JsonObject;

constructor(id: number, client: StarRail) {
this.id = id;
this.client = client;

const _data = client.cachedAssetsManager.getExcelData("AvatarSkin", this.id);
if (!_data) throw new AssetsNotFoundError("Costume", this.id);
this._data = _data;

const json = new JsonReader(this._data);

this.name = new TextAssets(json.getAsNumber("AvatarSkinName", "Hash"), this.client);
this.characterId = json.getAsNumber("AvatarID");

}
}

0 comments on commit 73ff6e4

Please sign in to comment.