Skip to content

Commit

Permalink
feat: Update Icon Urls
Browse files Browse the repository at this point in the history
  • Loading branch information
Jared-02 committed Nov 21, 2023
1 parent b1b3d5a commit 5af954d
Show file tree
Hide file tree
Showing 10 changed files with 170 additions and 39 deletions.
34 changes: 29 additions & 5 deletions mona_generate/src/gen_meta/gen_artifact_meta.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
use askama::Template;
use std::collections::HashMap;
use mona::artifacts::artifact_trait::ArtifactMetaData;
use mona::artifacts::ArtifactSetName;
use mona::common::item_config_type::ItemConfig;
use crate::gen_meta::gen_locale::get_index_mapping;
use crate::utils::config_to_json;
use crate::utils::icon_hashmap::ICON_HASHMAP;

struct ArtifactMeta {
name_locale: usize,
Expand All @@ -29,6 +31,12 @@ struct ArtifactMeta {
sand_icon: String,
goblet_icon: String,
head_icon: String,

flower_hash: String,
feather_hash: String,
sand_hash: String,
goblet_hash: String,
head_hash: String,
}

#[derive(Template)]
Expand All @@ -37,15 +45,26 @@ struct ArtifactMetaTemplate {
artifacts: Vec<ArtifactMeta>
}

fn get_icon_hash(icon_hashmap: &HashMap<&str, &str>, icon: &str) -> String {
icon_hashmap.get(icon).map_or(String::new(), |&hash| hash.to_string())
}

pub fn gen_artifact_meta_as_js_file() -> String {
let mut data = Vec::new();
let index_map = get_index_mapping();
let icon_hashmap = &ICON_HASHMAP;

for i in 1_usize..ArtifactSetName::LEN {
let e: ArtifactSetName = num::FromPrimitive::from_usize(i).unwrap();
let meta: ArtifactMetaData = e.get_meta();
let config4: Option<&'static [ItemConfig]> = e.get_config4();

let flower_icon: String = if let Some(_) = meta.flower { format!("UI_RelicIcon_{}_4", meta.internal_id) } else { String::new() };
let feather_icon: String = if let Some(_) = meta.feather { format!("UI_RelicIcon_{}_2", meta.internal_id) } else { String::new() };
let sand_icon: String = if let Some(_) = meta.sand { format!("UI_RelicIcon_{}_5", meta.internal_id) } else { String::new() };
let goblet_icon: String = if let Some(_) = meta.goblet { format!("UI_RelicIcon_{}_1", meta.internal_id) } else { String::new() };
let head_icon: String = if let Some(_) = meta.head { format!("UI_RelicIcon_{}_3", meta.internal_id) } else { String::new() };

data.push(ArtifactMeta {
name_locale: *index_map.get(&meta.name_locale).unwrap(),
name: meta.name.to_string(),
Expand All @@ -63,11 +82,16 @@ pub fn gen_artifact_meta_as_js_file() -> String {
sand: if let Some(ref x) = meta.sand { Some(*index_map.get(x).unwrap()) } else { None },
goblet: if let Some(ref x) = meta.goblet { Some(*index_map.get(x).unwrap()) } else { None },
head: if let Some(ref x) = meta.head { Some(*index_map.get(x).unwrap()) } else { None },
flower_icon: if let Some(_) = meta.flower { format!("UI_RelicIcon_{}_4", meta.internal_id) } else { String::new() },
feather_icon: if let Some(_) = meta.feather { format!("UI_RelicIcon_{}_2", meta.internal_id) } else { String::new() },
sand_icon: if let Some(_) = meta.sand { format!("UI_RelicIcon_{}_5", meta.internal_id) } else { String::new() },
goblet_icon: if let Some(_) = meta.goblet { format!("UI_RelicIcon_{}_1", meta.internal_id) } else { String::new() },
head_icon: if let Some(_) = meta.head { format!("UI_RelicIcon_{}_3", meta.internal_id) } else { String::new() }
flower_icon: flower_icon.clone(),
feather_icon: feather_icon.clone(),
sand_icon: sand_icon.clone(),
goblet_icon: goblet_icon.clone(),
head_icon: head_icon.clone(),
flower_hash: get_icon_hash(icon_hashmap, flower_icon.as_str()),
feather_hash: get_icon_hash(icon_hashmap, feather_icon.as_str()),
sand_hash: get_icon_hash(icon_hashmap, sand_icon.as_str()),
goblet_hash: get_icon_hash(icon_hashmap, goblet_icon.as_str()),
head_hash: get_icon_hash(icon_hashmap, head_icon.as_str()),
})
}

Expand Down
7 changes: 7 additions & 0 deletions mona_generate/src/gen_meta/gen_character_meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ use mona::common::item_config_type::ItemConfig;
use lazy_static::lazy_static;
use crate::gen_meta::gen_locale::get_index_mapping;
use crate::utils::config_to_json;
use crate::utils::icon_hashmap::ICON_HASHMAP;

struct CharacterMeta {
name: String,
// name_for_image: String,
internal_name: String,
name_locale: usize,
// icon_name: String,
icon_hash: String,
star: usize,
skill1_name_index: usize,
skill2_name_index: usize,
Expand Down Expand Up @@ -40,6 +42,7 @@ struct CharacterMetaTemplate {
pub fn gen_character_meta_as_js_file() -> String {
let mut data: Vec<CharacterMeta> = Vec::new();
let index_mapping = get_index_mapping();
let icon_hashmap = &ICON_HASHMAP;

for i in 0_usize..CharacterName::LEN {
let name_enum: CharacterName = num::FromPrimitive::from_usize(i).unwrap();
Expand Down Expand Up @@ -93,9 +96,13 @@ pub fn gen_character_meta_as_js_file() -> String {

let name_locale = *index_mapping.get(&meta.name_locale).unwrap();

let icon_hash: String = icon_hashmap.get(meta.internal_name)
.map_or(String::new(), |&hash| hash.to_string());

data.push(CharacterMeta {
name: meta.name.to_string(),
internal_name: String::from(meta.internal_name),
icon_hash,
name_locale,
star: meta.star as usize,
skill1_name_index: *index_mapping.get(&meta.skill_name1).unwrap(),
Expand Down
22 changes: 14 additions & 8 deletions mona_generate/src/gen_meta/gen_tf_meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use mona::target_functions::target_function_meta::{TargetFunctionFor, TargetFunc
use mona::target_functions::TargetFunctionName;
use crate::gen_meta::gen_locale::get_index_mapping;
use crate::utils::config_to_json;
use crate::utils::icon_hashmap::ICON_HASHMAP;

struct TFMeta {
name: String,
Expand All @@ -17,6 +18,7 @@ struct TFMeta {
badge_type: String,
// if badge is character avatar, use mihoyo image url
character_icon_name: String,
icon_hash: String,
config: Vec<String>,
}

Expand Down Expand Up @@ -50,6 +52,7 @@ fn convert_badge_path(p: &TargetFunctionMetaImage, f: &TargetFunctionFor) -> Str
pub fn gen_tf_meta_as_js_file() -> String {
let mut data: Vec<TFMeta> = Vec::new();
let index_map = get_index_mapping();
let icon_hashmap = &ICON_HASHMAP;

for i in 0_usize..TargetFunctionName::LEN {
let e: TargetFunctionName = num::FromPrimitive::from_usize(i).unwrap();
Expand All @@ -61,6 +64,15 @@ pub fn gen_tf_meta_as_js_file() -> String {
Vec::new()
};

let icon_name: String = if let TargetFunctionMetaImage::Avatar = meta.image {
if let TargetFunctionFor::SomeWho(c) = meta.four {
let c_meta: CharacterStaticData = c.get_static_data();
c_meta.internal_name.to_string()
} else { String::new() }
} else { String::new() };
let icon_hash: String = icon_hashmap.get(icon_name.as_str())
.map_or(String::new(), |&hash| hash.to_string());

data.push(TFMeta {
name: meta.name.to_string(),
name_locale: *index_map.get(&meta.name_locale).unwrap(),
Expand All @@ -69,14 +81,8 @@ pub fn gen_tf_meta_as_js_file() -> String {
four: convert_for(&meta.four),
badge_path: convert_badge_path(&meta.image, &meta.four),
badge_type: if let TargetFunctionMetaImage::Avatar = meta.image { String::from("character") } else { String::from("misc") },
character_icon_name: if let TargetFunctionMetaImage::Avatar = meta.image {
if let TargetFunctionFor::SomeWho(c) = meta.four {
let c_meta: CharacterStaticData = c.get_static_data();
format!("UI_AvatarIcon_{}", c_meta.internal_name)
} else {
String::new()
}
} else { String::new() },
character_icon_name: format!("UI_AvatarIcon_{}", icon_name),
icon_hash,
config
})
}
Expand Down
7 changes: 7 additions & 0 deletions mona_generate/src/gen_meta/gen_weapon_meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ use mona::weapon::weapon_name::WeaponName;
use mona::weapon::weapon_static_data::WeaponStaticData;
use crate::gen_meta::gen_locale::get_index_mapping;
use crate::utils::config_to_json;
use crate::utils::icon_hashmap::ICON_HASHMAP;

struct WeaponMetaDataForJS {
name: String,
internal_name: String,
icon_hash: String,
name_index: usize,
star: usize,
t: String,
Expand All @@ -26,6 +28,7 @@ struct WeaponMetaAllForJS {
pub fn gen_weapon_meta_as_js_file() -> String {
let mut data: Vec<WeaponMetaDataForJS> = Vec::new();
let index_map = get_index_mapping();
let icon_hashmap = &ICON_HASHMAP;

for i in 0_usize..WeaponName::LEN {
let weapon_name: WeaponName = num::FromPrimitive::from_usize(i).unwrap();
Expand All @@ -40,10 +43,14 @@ pub fn gen_weapon_meta_as_js_file() -> String {
}
}

let icon_hash: String = icon_hashmap.get(meta_data.internal_name)
.map_or(String::new(), |&hash| hash.to_string());

let my_data = WeaponMetaDataForJS {
name: weapon_name.to_string(),
// internal_name: get_internal_weapon_name(weapon_name),
internal_name: String::from(meta_data.internal_name),
icon_hash,
name_index: *index_map.get(&meta_data.name_locale).unwrap(),
star: meta_data.star,
t: meta_data.weapon_type.to_string(),
Expand Down
50 changes: 50 additions & 0 deletions mona_generate/src/utils/icon_hashmap.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
use std::collections::HashMap;
use lazy_static::lazy_static;

lazy_static! {
pub static ref ICON_HASHMAP: HashMap<&'static str, &'static str> = {
let data = vec![
("Furina", "4da8d9d663e2e59f63c19815074074de"),
("Neuvillette", "965af2f32a5376affcb99afb9915a23d"),
("Wriothesley", "e2ea36ecfdb6f53717b1cadd394fbf49"),
("Lyney", "15c0fae62ec91222148b753e5445c5fe"),
("Charlotte", "99218c303fd1ca9cc53e052ebdd5cbf3"),
("Freminet", "7ca0ad25c2cbb36cd55a8a19c1b2a39f"),
("Lynette", "3163e147dc45dec9944d06355d778879"),
("Momoka", "8e8c8c18039f5441d4f2f43757781ae0"),
("Bow_Pledge", "2b3f4a4eef528e1150893d58c68a5de3"),
("Bow_Ibis", "aef17fddf164e3ea98c4fd073a5f02a3"),
("Bow_Mechanic", "98e0ebb9a9857e2b21deda9d8c574b89"),
("Bow_Gurabad", "1cd241d13f320f3a0fbdfe378f423364"),
("Bow_Vorpal", "d70cf7fcc37cfbce1a07f5f3e214f278"),
("Catalyst_Iudex", "8f34b571d7e2d26e6c2ef2886defa86b"),
("Catalyst_Wheatley", "74712841e6a4cc25e0a2a36874ac71d7"),
("Catalyst_DandelionPoem", "b90f7edc1c4a6c0c132e00da99918d84"),
("Catalyst_Vorpal", "d4f997c8b399ef27d027653ba73645a5"),
("Catalyst_Yue", "93b6d05a8bc54d8eb69e4ed450c981c8"),
("Pole_Shanty", "2dc8e2cc9ab49c1d0ff9f67b3c98a94d"),
("Pole_Mechanic", "3333f73a195e3da1ed9a125658dfcf16"),
("Pole_Vorpal", "6514981aeab437590ebbfe15f5aef671"),
("Sword_Regalis", "1d603d4764cf292a12e268b8d8012688"),
("Sword_Vorpal", "acde24e9fa3f3e8c14f40aa4cd1a9007"),
("Sword_Machination", "b6259f0f93f824b169b50b6bc593dd08"),
("Sword_Purewill", "9c06477c167aadef25d03b4ceb1320ba"),
("Sword_Mechanic", "da80c69eada7e7fb6053b6301a6011ba"),
("Claymore_Mechanic", "6dc1e808543a09ddc1daf1e76721cd3d"),
("Claymore_Vorpal", "a76dd2c45f3bcfaf3f547d5c90bd20e2"),
("Claymore_BeastTamer", "4add4bfe23684d374398998eb5eb247d"),
("UI_RelicIcon_15032_4", "fadbbf8dbba05ad1ce0daeb4ebf89413"),
("UI_RelicIcon_15032_2", "4ca24e57d1adc9f0247c6bffd164d8b7"),
("UI_RelicIcon_15032_5", "9269d47e4a4edd517042c26fe534060e"),
("UI_RelicIcon_15032_1", "4d2b22a334d4237ba2cce56aeb5bd023"),
("UI_RelicIcon_15032_3", "2f69d44e2e79a05adbe0c9fe6391ea33"),
("UI_RelicIcon_15031_4", "9babba990b561f2b031d5db4145c19a9"),
("UI_RelicIcon_15031_2", "819b944729f2d5702f46d1403edba587"),
("UI_RelicIcon_15031_5", "de01dcbf2911968336afbbb61b455831"),
("UI_RelicIcon_15031_1", "b10902ae43e7f6d6619fe560829f7ba3"),
("UI_RelicIcon_15031_3", "1f3958293c20e8a29f51b9f3ed259e12"),
];

data.into_iter().collect()
};
}
2 changes: 2 additions & 0 deletions mona_generate/src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use mona::common::item_config_type::{ItemConfig, ItemConfigType};
use serde_json::json;
use crate::gen_meta::gen_locale::get_index_mapping;

pub mod icon_hashmap;

pub fn config_to_json(config: &ItemConfig) -> String {
let index_map = get_index_mapping();
let name = config.name;
Expand Down
63 changes: 42 additions & 21 deletions mona_generate/templates/artifact_meta_template.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const template = "https://upload-bbs.mihoyo.com/game_record/genshin/equip/#.png"

const newTemplate = "https://act-webstatic.mihoyo.com/hk4e/e20200928calculate/item_icon_uceddf/#.png"
const getIcon = name => template.replace("#", name)
const getHash = md5 => newTemplate.replace("#", md5)

export default {
{% for a in artifacts %}
Expand All @@ -10,52 +11,72 @@ export default {
nameLocale: {{a.name_locale}},
minStar: {{ a.min_star }},
maxStar: {{ a.max_star }},
{% if a.effect1.is_some() %}
{% if a.effect1.is_some() -%}
effect1: {{a.effect1.unwrap()}},
{% endif %}
{% if a.effect2.is_some() %}
{%- endif %}
{% if a.effect2.is_some() -%}
effect2: {{a.effect2.unwrap()}},
{% endif %}
{% if a.effect3.is_some() %}
{%- endif %}
{% if a.effect3.is_some() -%}
effect3: {{a.effect3.unwrap()}},
{% endif %}
{% if a.effect4.is_some() %}
{%- endif %}
{% if a.effect4.is_some() -%}
effect4: {{a.effect4.unwrap()}},
{% endif %}
{% if a.effect5.is_some() %}
{%- endif %}
{% if a.effect5.is_some() -%}
effect5: {{a.effect5.unwrap()}},
{% endif %}
{%- endif %}

{% if a.flower.is_some() %}
{% if a.flower.is_some() -%}
flower: {
text: {{a.flower.unwrap()}},
{% if a.flower_hash == "" -%}
url: getIcon("{{ a.flower_icon }}")
{% else -%}
url: getHash("{{ a.flower_hash }}")
{%- endif -%}
},
{% endif %}
{% if a.feather.is_some() %}
{%- endif %}
{% if a.feather.is_some() -%}
feather: {
text: {{a.feather.unwrap()}},
{% if a.feather_hash == "" -%}
url: getIcon("{{ a.feather_icon }}")
{% else -%}
url: getHash("{{ a.feather_hash }}")
{%- endif -%}
},
{% endif %}
{% if a.sand.is_some() %}
{%- endif %}
{% if a.sand.is_some() -%}
sand: {
text: {{a.sand.unwrap()}},
{% if a.sand_hash == "" -%}
url: getIcon("{{ a.sand_icon }}")
{% else -%}
url: getHash("{{ a.sand_hash }}")
{%- endif -%}
},
{% endif %}
{% if a.goblet.is_some() %}
{%- endif %}
{% if a.goblet.is_some() -%}
cup: {
text: {{a.goblet.unwrap()}},
{% if a.goblet_hash == "" -%}
url: getIcon("{{ a.goblet_icon }}")
{% else -%}
url: getHash("{{ a.goblet_hash }}")
{%- endif -%}
},
{% endif %}
{% if a.head.is_some() %}
{%- endif %}
{% if a.head.is_some() -%}
head: {
text: {{a.head.unwrap()}},
{% if a.head_hash == "" -%}
url: getIcon("{{ a.head_icon }}")
{% else -%}
url: getHash("{{ a.head_hash }}")
{%- endif -%}
},
{% endif %}
{%- endif %}
config4: [
{% for config in a.config4 %}
{{ config|e("none") }},
Expand Down
7 changes: 6 additions & 1 deletion mona_generate/templates/character_meta_template.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import {{ c.name }}_splash from "@image/characters/{{ c.name }}_splash"

// const template = "https://upload-bbs.mihoyo.com/game_record/genshin/character_icon/UI_AvatarIcon_#.png?x-oss-process=image/crop,w_200,h_200,y_5,g_north"
const template = "https://upload-bbs.mihoyo.com/game_record/genshin/character_icon/UI_AvatarIcon_#.png?x-oss-process=image/crop,w_200,h_200,y_5,g_north"

const newTemplate = "https://act-webstatic.mihoyo.com/hk4e/e20200928calculate/item_icon_uceddf/#.png?x-oss-process=image/crop,w_200,h_200,y_5,g_north"
const getName = name => template.replace("#", name)
const getMd5 = md5 => newTemplate.replace("#", md5)

export default {
{% for c in characters %}
Expand All @@ -20,7 +21,11 @@ export default {
star: {{ c.star }},
// card: {{ c.name }}_card,
// avatar: {{ c.name }}_avatar,
{% if c.icon_hash == "" -%}
avatar: getName("{{ c.internal_name }}"),
{% else -%}
avatar: getMd5("{{ c.icon_hash }}"),
{%- endif %}
splash: {{ c.name }}_splash,
skillName1: {{ c.skill1_name_index }},
skillName2: {{ c.skill2_name_index }},
Expand Down
Loading

0 comments on commit 5af954d

Please sign in to comment.