Compare commits

...

2 Commits

Author SHA1 Message Date
yuvlian
89b8e5f0ef default trait because i felt like it 2026-02-21 14:31:55 +07:00
yuvlian
633228af42 anyhow, cargo fmt 2026-02-21 14:25:20 +07:00
11 changed files with 123 additions and 82 deletions

View File

@@ -4,6 +4,7 @@ version = "0.1.0"
edition = "2024" edition = "2024"
[dependencies] [dependencies]
anyhow = "1.0.102"
paste = "1.0.15" paste = "1.0.15"
serde = { version = "1.0.228", features = ["derive"] } serde = { version = "1.0.228", features = ["derive"] }
serde_json = "1.0.149" serde_json = "1.0.149"

View File

@@ -8,4 +8,5 @@ fn main() {
singleton::set_item_search(item_search).ok(); singleton::set_item_search(item_search).ok();
let stellar_jade = singleton::get_item_mini_by_id(&1).unwrap(); let stellar_jade = singleton::get_item_mini_by_id(&1).unwrap();
dbg!(stellar_jade); dbg!(stellar_jade);
println!("{}", res_parser::common::Hash::from_str("HelLONi1"));
} }

View File

@@ -2,13 +2,13 @@ use serde::{Deserialize, Serialize};
#[derive(Default, Debug, Clone, Copy, Serialize, Deserialize)] #[derive(Default, Debug, Clone, Copy, Serialize, Deserialize)]
pub struct Hash { pub struct Hash {
pub Hash: i32, #[serde(rename = "Hash")]
pub hash: i32,
} }
impl Hash { impl Hash {
pub const fn get_i32(s: &str) -> i32 { pub const fn from_str(s: &str) -> i32 {
let mut hash1: i32 = 5381; let mut hash1 @ mut hash2 = 5381i32;
let mut hash2: i32 = hash1;
let bytes = s.as_bytes(); let bytes = s.as_bytes();
let length = bytes.len(); let length = bytes.len();
@@ -16,11 +16,9 @@ impl Hash {
let mut i = 0; let mut i = 0;
while i < length { while i < length {
hash1 = ((hash1 << 5).wrapping_add(hash1)) ^ (bytes[i] as i32); hash1 = ((hash1 << 5).wrapping_add(hash1)) ^ (bytes[i] as i32);
if i + 1 < length { if i + 1 < length {
hash2 = ((hash2 << 5).wrapping_add(hash2)) ^ (bytes[i + 1] as i32); hash2 = ((hash2 << 5).wrapping_add(hash2)) ^ (bytes[i + 1] as i32);
} }
i += 2; i += 2;
} }

View File

@@ -1,36 +1,50 @@
use serde::{Deserialize, Serialize};
use super::common::Hash; use super::common::Hash;
use super::text_map::TextMaps; use super::text_map::TextMaps;
use std::collections::BTreeMap;
use crate::types::common::Image; use crate::types::common::Image;
use crate::types::item::{ItemSearch, ItemMini}; use crate::types::item::{ItemMini, ItemSearch};
use anyhow::{Context, Result};
use serde::{Deserialize, Serialize};
use std::collections::BTreeMap;
// C:\Users\yuvlian\Downloads\git\others\srwk\Resources-DUMP\ExcelOutput\ItemConfig.json #[derive(Default, Debug, Clone, Serialize, Deserialize)]
// pub struct ItemSearch(pub BTreeMap<Id, ItemMini>);
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ItemConfigs(pub Vec<ItemConfig>); pub struct ItemConfigs(pub Vec<ItemConfig>);
impl ItemConfigs { impl ItemConfigs {
pub fn parse_to_api_type(tm: &TextMaps) -> Result<ItemSearch, String> { pub fn parse_to_api_type(tm: &TextMaps) -> Result<ItemSearch> {
let file = std::fs::read_to_string("../Resources-DUMP/ExcelOutput/ItemConfig.json").unwrap(); let path = "../Resources-DUMP/ExcelOutput/ItemConfig.json";
let cfg: Vec<ItemConfig> = serde_json::from_str(&file).unwrap(); let file = std::fs::File::open(path).with_context(|| format!("Failed to open {}", path))?;
let cfg = ItemConfigs(cfg); let reader = std::io::BufReader::new(file);
let mut item_search = BTreeMap::new(); let cfg: Vec<ItemConfig> =
for item in cfg.0.iter() { serde_json::from_reader(reader).with_context(|| format!("Failed to parse {}", path))?;
let id = item.ID;
// println!("{}", id); let item_search = cfg
let name = tm.get_by_hash(item.ItemName).unwrap_or_default(); .into_iter()
let img = Image { path: String::new(), filename: String::new(), author_info: None }; .map(|item| {
item_search.insert(id, ItemMini { name: name.Text.clone(), image: img}); let id = item.id;
} let name = tm.get_by_hash(item.item_name).unwrap_or_default();
let img = Image {
path: String::new(),
filename: String::new(),
author_info: None,
};
(
id,
ItemMini {
name: name.text.clone(),
image: img,
},
)
})
.collect();
Ok(ItemSearch(item_search)) Ok(ItemSearch(item_search))
} }
} }
#[derive(Debug, Clone, Serialize, Deserialize)] #[derive(Default, Debug, Clone, Serialize, Deserialize)]
pub struct ItemConfig { pub struct ItemConfig {
pub ID: i32, #[serde(rename = "ID")]
pub ItemName: Hash, pub id: i32,
#[serde(rename = "ItemName")]
pub item_name: Hash,
} }

View File

@@ -1,5 +1,3 @@
#![allow(non_snake_case)]
pub mod common; pub mod common;
pub mod item; pub mod item;
pub mod text_map; pub mod text_map;

View File

@@ -1,45 +1,48 @@
use serde::{Deserialize, Serialize};
use super::common::Hash; use super::common::Hash;
use anyhow::{Context, Result};
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::fs::File;
use std::io::BufReader;
// C:\Users\yuvlian\Downloads\git\others\srwk\Resources-DUMP\TextMap\TextMapEN.json #[derive(Default, Debug, Clone, Serialize, Deserialize)]
pub struct TextMaps(HashMap<i32, TextMap>);
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TextMaps(pub Vec<TextMap>);
impl TextMaps { impl TextMaps {
pub fn parse() -> Result<Self, String> { pub fn parse() -> Result<Self> {
let file = std::fs::read_to_string("../Resources-DUMP/TextMap/TextMapEN.json").unwrap(); let path = "../Resources-DUMP/TextMap/TextMapEN.json";
let v: Vec<TextMap> = serde_json::from_str(&file).unwrap(); let file = File::open(path).with_context(|| format!("Failed to open {}", path))?;
Ok(TextMaps(v)) let reader = BufReader::new(file);
} let v: Vec<TextMap> =
serde_json::from_reader(reader).with_context(|| format!("Failed to parse {}", path))?;
pub fn get_by_i32(&self, i: i32) -> Option<TextMap> { let map = v.into_iter().map(|t| (t.id.hash, t)).collect();
self.get_by_hash(Hash { Hash: i }) Ok(TextMaps(map))
} }
pub fn get_by_str(&self, s: &str) -> Option<TextMap> { pub fn get_by_str(&self, s: &str) -> Option<TextMap> {
let hash = Hash::get_i32(s); let hash = Hash::from_str(s);
self.get_by_hash(Hash { Hash: hash }) self.get_by_i32(hash)
}
pub fn get_by_i32(&self, i: i32) -> Option<TextMap> {
self.get_by_hash(Hash { hash: i })
} }
pub fn get_by_hash(&self, h: Hash) -> Option<TextMap> { pub fn get_by_hash(&self, h: Hash) -> Option<TextMap> {
let mut m = None; if h.hash == 0 {
if h.Hash == 0 { return None;
return m;
} }
for t in self.0.iter() { self.0.get(&h.hash).cloned()
if t.ID.Hash == h.Hash {
m = Some(t.clone());
break;
}
}
m
} }
} }
#[derive(Default, Debug, Clone, Serialize, Deserialize)] #[derive(Default, Debug, Clone, Serialize, Deserialize)]
pub struct TextMap { pub struct TextMap {
pub ID: Hash, #[serde(rename = "ID")]
pub Text: String, pub id: Hash,
pub HasParam: bool, #[serde(rename = "Text")]
pub text: String,
#[serde(rename = "HasParam")]
pub has_param: bool,
} }

View File

@@ -1,21 +1,21 @@
use super::common::{ use super::common::{
Ascension, Count, Desc, Element, Id, Level, Path, Rarity, StatType, StatValue, Image, Ascension, Count, Desc, Element, Id, Image, Level, Path, Rarity, StatType, StatValue,
}; };
use super::item::ItemMini; use super::item::ItemMini;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::collections::{BTreeMap, HashMap}; use std::collections::{BTreeMap, HashMap};
#[derive(Debug, Clone, Serialize, Deserialize)] #[derive(Default, Debug, Clone, Serialize, Deserialize)]
pub struct Eidolon { pub struct Eidolon {
pub name: String, pub name: String,
pub desc: Desc, pub desc: Desc,
pub image: Image, pub image: Image,
} }
#[derive(Debug, Clone, Serialize, Deserialize)] #[derive(Default, Debug, Clone, Serialize, Deserialize)]
pub struct CharacterSearch(pub BTreeMap<Id, CharacterMini>); pub struct CharacterSearch(pub BTreeMap<Id, CharacterMini>);
#[derive(Debug, Clone, Serialize, Deserialize)] #[derive(Default, Debug, Clone, Serialize, Deserialize)]
pub struct CharacterMini { pub struct CharacterMini {
pub name: String, pub name: String,
pub path: Path, pub path: Path,
@@ -24,10 +24,10 @@ pub struct CharacterMini {
pub image: Image, pub image: Image,
} }
#[derive(Debug, Clone, Serialize, Deserialize)] #[derive(Default, Debug, Clone, Serialize, Deserialize)]
pub struct CharacterDetail(pub HashMap<Id, CharacterFull>); pub struct CharacterDetail(pub HashMap<Id, CharacterFull>);
#[derive(Debug, Clone, Serialize, Deserialize)] #[derive(Default, Debug, Clone, Serialize, Deserialize)]
pub struct CharacterFull { pub struct CharacterFull {
pub name: String, pub name: String,
pub path: Path, pub path: Path,

View File

@@ -5,22 +5,28 @@ pub type Level = i32;
pub type Count = i32; pub type Count = i32;
pub type Desc = String; pub type Desc = String;
#[derive(Debug, Clone, Serialize, Deserialize)] #[derive(Default, Debug, Clone, Serialize, Deserialize)]
pub struct Image { pub struct Image {
pub path: String, pub path: String,
pub filename: String, pub filename: String,
pub author_info: Option<String>, pub author_info: Option<String>,
} }
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq)] #[derive(Default, Debug, Clone, Copy, Serialize, Deserialize, PartialEq)]
pub enum StatValue { pub enum StatValue {
#[default]
NoneType,
Flat(f32), Flat(f32),
Percent(f32), Percent(f32),
} }
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash)] #[derive(
Default, Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash,
)]
#[repr(u8)] #[repr(u8)]
pub enum StatType { pub enum StatType {
#[default]
NoneType = 0,
Aggro = 1, Aggro = 1,
AtkFlat = 2, AtkFlat = 2,
AtkPercent = 3, AtkPercent = 3,
@@ -48,17 +54,25 @@ pub enum StatType {
Vulnerability = 25, Vulnerability = 25,
} }
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash)] #[derive(
Default, Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash,
)]
#[repr(u8)] #[repr(u8)]
pub enum Ascension { pub enum Ascension {
#[default]
NoneType = 0,
A2 = 1, A2 = 1,
A4 = 2, A4 = 2,
A6 = 3, A6 = 3,
} }
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash)] #[derive(
Default, Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash,
)]
#[repr(u8)] #[repr(u8)]
pub enum Path { pub enum Path {
#[default]
NoneType = 0,
Destruction = 1, Destruction = 1,
Hunt = 2, Hunt = 2,
Erudition = 3, Erudition = 3,
@@ -70,17 +84,25 @@ pub enum Path {
Elation = 9, Elation = 9,
} }
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash)] #[derive(
Default, Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash,
)]
#[repr(u8)] #[repr(u8)]
pub enum Rarity { pub enum Rarity {
#[default]
NoneType = 0,
ThreeStar = 3, ThreeStar = 3,
FourStar = 4, FourStar = 4,
FiveStar = 5, FiveStar = 5,
} }
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash)] #[derive(
Default, Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash,
)]
#[repr(u8)] #[repr(u8)]
pub enum Element { pub enum Element {
#[default]
NoneType = 0,
Physical = 1, Physical = 1,
Fire = 2, Fire = 2,
Ice = 3, Ice = 3,
@@ -90,9 +112,13 @@ pub enum Element {
Imaginary = 7, Imaginary = 7,
} }
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash)] #[derive(
Default, Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash,
)]
#[repr(u8)] #[repr(u8)]
pub enum RelicType { pub enum RelicType {
#[default]
NoneType = 0,
Relic = 1, Relic = 1,
Planar = 2, Planar = 2,
} }

View File

@@ -2,10 +2,10 @@ use super::common::{Id, Image};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::collections::BTreeMap; use std::collections::BTreeMap;
#[derive(Debug, Clone, Serialize, Deserialize)] #[derive(Default, Debug, Clone, Serialize, Deserialize)]
pub struct ItemSearch(pub BTreeMap<Id, ItemMini>); pub struct ItemSearch(pub BTreeMap<Id, ItemMini>);
#[derive(Debug, Clone, Serialize, Deserialize)] #[derive(Default, Debug, Clone, Serialize, Deserialize)]
pub struct ItemMini { pub struct ItemMini {
pub name: String, pub name: String,
pub image: Image, pub image: Image,

View File

@@ -1,12 +1,12 @@
use super::common::{Count, Desc, Id, Level, Path, Rarity, StatValue, Image}; use super::common::{Count, Desc, Id, Image, Level, Path, Rarity, StatValue};
use super::item::ItemMini; use super::item::ItemMini;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::collections::{BTreeMap, HashMap}; use std::collections::{BTreeMap, HashMap};
#[derive(Debug, Clone, Serialize, Deserialize)] #[derive(Default, Debug, Clone, Serialize, Deserialize)]
pub struct LightconeSearch(pub BTreeMap<Id, LightconeMini>); pub struct LightconeSearch(pub BTreeMap<Id, LightconeMini>);
#[derive(Debug, Clone, Serialize, Deserialize)] #[derive(Default, Debug, Clone, Serialize, Deserialize)]
pub struct LightconeMini { pub struct LightconeMini {
pub name: String, pub name: String,
pub path: Path, pub path: Path,
@@ -14,10 +14,10 @@ pub struct LightconeMini {
pub image: Image, pub image: Image,
} }
#[derive(Debug, Clone, Serialize, Deserialize)] #[derive(Default, Debug, Clone, Serialize, Deserialize)]
pub struct LightconeDetail(pub HashMap<Id, LightconeFull>); pub struct LightconeDetail(pub HashMap<Id, LightconeFull>);
#[derive(Debug, Clone, Serialize, Deserialize)] #[derive(Default, Debug, Clone, Serialize, Deserialize)]
pub struct LightconeFull { pub struct LightconeFull {
pub name: String, pub name: String,
pub path: Path, pub path: Path,

View File

@@ -1,11 +1,11 @@
use super::common::{Desc, Id, RelicType, Image}; use super::common::{Desc, Id, Image, RelicType};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::collections::{BTreeMap, HashMap}; use std::collections::{BTreeMap, HashMap};
#[derive(Debug, Clone, Serialize, Deserialize)] #[derive(Default, Debug, Clone, Serialize, Deserialize)]
pub struct RelicSearch(pub BTreeMap<Id, RelicMini>); pub struct RelicSearch(pub BTreeMap<Id, RelicMini>);
#[derive(Debug, Clone, Serialize, Deserialize)] #[derive(Default, Debug, Clone, Serialize, Deserialize)]
pub struct RelicMini { pub struct RelicMini {
pub name: String, pub name: String,
pub r#type: RelicType, pub r#type: RelicType,