Skip to content

Commit

Permalink
added some props to StarRailUser & type changes
Browse files Browse the repository at this point in the history
  • Loading branch information
yuko1101 committed May 8, 2024
1 parent b038fe5 commit 24751d2
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 11 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
@@ -1,5 +1,12 @@
# 1.5.1
# 1.6.0
**This version includes Breaking Changes**
- Added StarRailUser#bookCount, StarRailUser#relicCount, and StarRailUser#musicCount.
- Added StarRailUser#isDisplayAvatar.
- Added StarRailUser#enkaProfile.
- Added StarRailUser#pureFiction.
- Added CharacterData#getBaseAggro(number).
- Renamed StarRailUser#achievements to StarRailUser#achievementCount.
- Changed structure of ForgottenHallInfo.
# 1.5.0
- Added caching for fetching user data by uid (StarRail#fetchUser).
# 1.4.1
Expand Down
41 changes: 31 additions & 10 deletions src/models/StarRailUser.ts
@@ -1,5 +1,5 @@
import { JsonObject, JsonReader } from "config_file.js";
import { User } from "enka-system";
import { EnkaProfile, User } from "enka-system";
import StarRail from "../client/StarRail";
import Character from "./character/Character";
import UserIcon from "./UserIcon";
Expand All @@ -19,9 +19,14 @@ export const platformMap: { [key: number]: Platform } = {
};

export interface ForgottenHallInfo {
memory: number;
memoryOfChaos: number;
memoryOfChaosId: number | null;
memory: {
maxLevel: number,
}
}

export interface PureFictionInfo {
level: number,
stars: number,
}

class StarRailUser extends User {
Expand All @@ -38,15 +43,22 @@ class StarRailUser extends User {
readonly equilibriumLevel: number;
readonly platform: Platform | null;
readonly friends: number;
readonly achievements: number;
readonly achievementCount: number;
readonly characterCount: number;
readonly lightConeCount: number;
readonly bookCount: number;
readonly relicCount: number;
readonly musicCount: number;
/** This will be null if the user has not yet unlocked Forgotten Hall. */
readonly forgottenHall: ForgottenHallInfo | null;
readonly pureFiction: PureFictionInfo | null;
readonly simulatedUniverse: number;
/** Whether the user displays characters in their showcase. */
readonly isDisplayCharacter: boolean;
readonly supportCharacters: Character[];
/** Characters on the user's display. Characters that are also in [supportCharacter](#supportCharacter) are omitted if you use Enka.Network API. */
readonly starfaringCompanions: Character[];
readonly enkaProfile: EnkaProfile | null;
readonly enkaUserHash: string | null;

constructor(data: JsonObject, client: StarRail) {
Expand All @@ -73,19 +85,28 @@ class StarRailUser extends User {

const recordInfo = detailInfo.get("recordInfo");

this.achievements = recordInfo.getAsNumberWithDefault(0, "achievementCount");
this.achievementCount = recordInfo.getAsNumberWithDefault(0, "achievementCount");
this.characterCount = recordInfo.getAsNumber("avatarCount");
this.lightConeCount = recordInfo.getAsNumberWithDefault(0, "equipmentCount");
this.bookCount = recordInfo.getAsNumberWithDefault(0, "bookCount");
this.relicCount = recordInfo.getAsNumberWithDefault(0, "relicCount");
this.musicCount = recordInfo.getAsNumberWithDefault(0, "musicCount");

const challengeInfo = recordInfo.get("challengeInfo");
this.forgottenHall = {
memory: challengeInfo.getAsNumberWithDefault(0, "scheduleMaxLevel"),
memoryOfChaos: challengeInfo.getAsNumberWithDefault(0, "noneScheduleMaxLevel"),
memoryOfChaosId: challengeInfo.getAsNumberWithDefault(null, "scheduleGroupId"),
memory: {
maxLevel: challengeInfo.getAsNumberWithDefault(0, "noneScheduleMaxLevel"),
},
};
this.pureFiction = {
level: challengeInfo.getAsNumberWithDefault(0, "abyssLevel"),
stars: challengeInfo.getAsNumberWithDefault(0, "abyssStarCount"),
};

this.simulatedUniverse = recordInfo.getAsNumberWithDefault(0, "maxRogueChallengeScore");

this.isDisplayCharacter = detailInfo.getAsBoolean("isDisplayAvatar");

const avatarDetailList = detailInfo.getAsJsonArrayWithDefault([], "avatarDetailList");
this.starfaringCompanions = avatarDetailList.filter(c => !(c as JsonObject)["_assist"]).map(c => new Character(c as JsonObject, this.client));
this.supportCharacters = (() => {
Expand All @@ -97,7 +118,7 @@ class StarRailUser extends User {
})();

this.enkaUserHash = json.getAsStringWithDefault(null, "owner", "hash");

this.enkaProfile = json.has("owner") ? new EnkaProfile(client.options.enkaSystem, json.getAsJsonObject("owner")) : null;
}

/**
Expand Down

0 comments on commit 24751d2

Please sign in to comment.