Skip to content

Commit

Permalink
added some icons and cdns
Browse files Browse the repository at this point in the history
  • Loading branch information
yuko1101 committed Feb 7, 2024
1 parent 84643bb commit 09f3729
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 1.4.1
- Added Path#smallIcon.
- Added CombatType#bigIcon.
- Added some CDN urls.
# 1.4.0
**This version includes Breaking Changes**
- Renamed StarRailUser#supportCharacter to supportCharacters and its type to Character[].
Expand Down
55 changes: 50 additions & 5 deletions src/client/StarRail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,27 @@ import { EnkaLibrary, EnkaSystem, InvalidUidFormatError, EnkaNetworkError, UserN
import StarRailCharacterBuild from "../models/enka/StarRailCharacterBuild";
import { Overwrite } from "../utils/ts_utils";

const starRialResMap = {
const starRailResMap = {
"SpriteOutput/AvatarIcon": "icon/character",
"SpriteOutput/ItemIcon": "icon/item",
"SpriteOutput/UI/Avatar/Icon": "icon/property",
"SpriteOutput/UI/Nature/IconAttributeMiddle": "icon/element",
} as const;

const yattaMap = {
"SpriteOutput/AvatarDrawCard": "avatar/large/{fileName}.sm",
"SpriteOutput/AvatarRoundIcon": "avatar/round/{fileName}",
// some shop icons are 2px height smaller than the original
"SpriteOutput/AvatarShopIcon": "avatar/medium/{fileName}",
"SpriteOutput/ProfessionIconSmall": "profession/{fileName}",
"SpriteOutput/UI/Nature/IconAttribute": "attribute/{fileName}",
"SpriteOutput/SkillIcons": "skill/{fileName}",
"SpriteOutput/ItemIcon": "item/{fileName}",
"SpriteOutput/UI/Avatar/Icon": "status/{fileName}",
"SpriteOutput/ItemIcon/RelicIcons": "relic/{fileName}",
"SpriteOutput/UI/Avatar/Relic": "relic/white/{fileName}",
} as const;

const defaultImageBaseUrls: (ImageBaseUrl | CustomImageBaseUrl)[] = [
{
filePath: "UPPER_CAMEL_CASE",
Expand All @@ -32,16 +46,25 @@ const defaultImageBaseUrls: (ImageBaseUrl | CustomImageBaseUrl)[] = [
customParser: (path: string) => path.replace(/(?<=^SpriteOutput\/SkillIcons\/)\d+\//, ""),
},
{
filePath: "UPPER_CAMEL_CASE",
filePath: "LOWER_CASE",
priority: 4,
format: "PNG",
regexList: Object.keys(starRialResMap).map((key) => new RegExp(`^${key}/([^/]+)$`)),
regexList: [
/^SpriteOutput\/(.+)/,
],
url: "https://raw.githubusercontent.com/FortOfFans/HSR/main",
},
{
filePath: "UPPER_CAMEL_CASE",
priority: 3,
format: "PNG",
regexList: Object.keys(starRailResMap).map((key) => new RegExp(`^${key}/([^/]+)$`)),
url: "https://raw.githubusercontent.com/Mar-7th/StarRailRes/master",
customParser: (path: string) => {
const split = path.split("/");
const fileName = split.pop() as string;
const dir = split.join("/");
const value = starRialResMap[dir as keyof typeof starRialResMap];
const value = starRailResMap[dir as keyof typeof starRailResMap];

switch (value) {
case "icon/character":
Expand All @@ -53,9 +76,31 @@ const defaultImageBaseUrls: (ImageBaseUrl | CustomImageBaseUrl)[] = [
}
},
},
{
filePath: "UPPER_CAMEL_CASE",
priority: 2,
format: "PNG",
regexList: Object.keys(yattaMap).map((key) => new RegExp(`^${key}/([^/]+)$`)),
url: "https://api.yatta.top/hsr/assets/UI",
customParser: (path: string) => {
const split = path.split("/");

// without extension
const fileName = (split.pop() as string).split(".").slice(0, -1).join(".");
// dir without numbered directory
let dir = split.filter(d => !/\d+/.test(d)).join("/") as keyof typeof yattaMap;
if (dir === "SpriteOutput/ItemIcon" && fileName.length === 5 && fileName.startsWith("71")) {
dir = "SpriteOutput/ItemIcon/RelicIcons";
}
const value = yattaMap[dir];


return value.replace(/{fileName}/g, fileName) + ".png";
},
},
{
filePath: "LOWER_CASE",
priority: 3,
priority: 1,
format: "WEBP",
regexList: [
/^SpriteOutput\/(AvatarShopIcon|AvatarRoundIcon|AvatarDrawCard|RelicFigures|ItemFigures|LightConeMaxFigures|LightConeMediumIcon)\/(.+)/,
Expand Down
6 changes: 5 additions & 1 deletion src/models/CombatType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ class CombatType {
readonly iconColor: number;
/** Icon for the CombatType. Also you can use svg files [here](https://cdn.discordapp.com/attachments/885221800882098197/1118292606384873625/hsr.zip). */
readonly icon: ImageAssets;
/** */
readonly bigIcon: ImageAssets;

readonly _data: JsonObject;

Expand All @@ -62,8 +64,10 @@ class CombatType {

this.iconColor = combatTypeIconColors[this.id];

this.icon = new ImageAssets(json.getAsString("DamageTypeIconPath"), this.client);
// use MazeEnterBattleWeakIconPath instead of DamageTypeIconPath as the former is bigger
this.icon = new ImageAssets(json.getAsString("MazeEnterBattleWeakIconPath"), this.client);
this.bigIcon = new ImageAssets(json.getAsString("MazeEnterBattleWeakIconPath"), this.client);

}
}

Expand Down
3 changes: 3 additions & 0 deletions src/models/Path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ class Path {
readonly description: TextAssets;
/** Icon for the Path. Also you can use svg files [here](https://cdn.discordapp.com/attachments/885221800882098197/1118292606384873625/hsr.zip). */
readonly icon: ImageAssets;
/** */
readonly smallIcon: ImageAssets;

readonly _data: JsonObject;

Expand All @@ -65,6 +67,7 @@ class Path {
this.name = new TextAssets(json.getAsNumber("BaseTypeText", "Hash"), this.client);
this.description = new TextAssets(json.getAsNumber("BaseTypeDesc", "Hash"), this.client);
this.icon = new ImageAssets(json.getAsString("BaseTypeIcon"), this.client);
this.smallIcon = new ImageAssets(json.getAsString("BaseTypeIconSmall"), this.client);
}
}

Expand Down

0 comments on commit 09f3729

Please sign in to comment.