test messy res -> types::item
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,2 +1,3 @@
|
|||||||
**/target
|
**/target
|
||||||
**/*.lock
|
**/*.lock
|
||||||
|
Resources-DUMP
|
||||||
|
|||||||
@@ -6,3 +6,4 @@ edition = "2024"
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
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"
|
||||||
|
|||||||
@@ -3,5 +3,9 @@ mod singleton;
|
|||||||
mod types;
|
mod types;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
println!("Hello, world!");
|
let tm = res_parser::text_map::TextMaps::parse().unwrap();
|
||||||
|
let item_search = res_parser::item::ItemConfigs::parse_to_api_type(&tm).unwrap();
|
||||||
|
singleton::set_item_search(item_search).ok();
|
||||||
|
let stellar_jade = singleton::get_item_mini_by_id(&1).unwrap();
|
||||||
|
dbg!(stellar_jade);
|
||||||
}
|
}
|
||||||
|
|||||||
29
resource_api/src/res_parser/common.rs
Normal file
29
resource_api/src/res_parser/common.rs
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
#[derive(Default, Debug, Clone, Copy, Serialize, Deserialize)]
|
||||||
|
pub struct Hash {
|
||||||
|
pub Hash: i32,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Hash {
|
||||||
|
pub const fn get_i32(s: &str) -> i32 {
|
||||||
|
let mut hash1: i32 = 5381;
|
||||||
|
let mut hash2: i32 = hash1;
|
||||||
|
|
||||||
|
let bytes = s.as_bytes();
|
||||||
|
let length = bytes.len();
|
||||||
|
|
||||||
|
let mut i = 0;
|
||||||
|
while i < length {
|
||||||
|
hash1 = ((hash1 << 5).wrapping_add(hash1)) ^ (bytes[i] as i32);
|
||||||
|
|
||||||
|
if i + 1 < length {
|
||||||
|
hash2 = ((hash2 << 5).wrapping_add(hash2)) ^ (bytes[i + 1] as i32);
|
||||||
|
}
|
||||||
|
|
||||||
|
i += 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
hash1.wrapping_add(hash2.wrapping_mul(1566083941))
|
||||||
|
}
|
||||||
|
}
|
||||||
36
resource_api/src/res_parser/item.rs
Normal file
36
resource_api/src/res_parser/item.rs
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
use super::common::Hash;
|
||||||
|
use super::text_map::TextMaps;
|
||||||
|
use std::collections::BTreeMap;
|
||||||
|
use crate::types::common::Image;
|
||||||
|
use crate::types::item::{ItemSearch, ItemMini};
|
||||||
|
|
||||||
|
// C:\Users\yuvlian\Downloads\git\others\srwk\Resources-DUMP\ExcelOutput\ItemConfig.json
|
||||||
|
// pub struct ItemSearch(pub BTreeMap<Id, ItemMini>);
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
|
pub struct ItemConfigs(pub Vec<ItemConfig>);
|
||||||
|
|
||||||
|
impl ItemConfigs {
|
||||||
|
pub fn parse_to_api_type(tm: &TextMaps) -> Result<ItemSearch, String> {
|
||||||
|
let file = std::fs::read_to_string("../Resources-DUMP/ExcelOutput/ItemConfig.json").unwrap();
|
||||||
|
let cfg: Vec<ItemConfig> = serde_json::from_str(&file).unwrap();
|
||||||
|
let cfg = ItemConfigs(cfg);
|
||||||
|
let mut item_search = BTreeMap::new();
|
||||||
|
for item in cfg.0.iter() {
|
||||||
|
let id = item.ID;
|
||||||
|
// println!("{}", id);
|
||||||
|
let name = tm.get_by_hash(item.ItemName).unwrap_or_default();
|
||||||
|
let img = Image { path: String::new(), filename: String::new(), author_info: None };
|
||||||
|
item_search.insert(id, ItemMini { name: name.Text.clone(), image: img});
|
||||||
|
}
|
||||||
|
Ok(ItemSearch(item_search))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
|
pub struct ItemConfig {
|
||||||
|
pub ID: i32,
|
||||||
|
pub ItemName: Hash,
|
||||||
|
}
|
||||||
|
|
||||||
@@ -1 +1,5 @@
|
|||||||
// TODO
|
#![allow(non_snake_case)]
|
||||||
|
|
||||||
|
pub mod common;
|
||||||
|
pub mod item;
|
||||||
|
pub mod text_map;
|
||||||
|
|||||||
45
resource_api/src/res_parser/text_map.rs
Normal file
45
resource_api/src/res_parser/text_map.rs
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
use super::common::Hash;
|
||||||
|
|
||||||
|
// C:\Users\yuvlian\Downloads\git\others\srwk\Resources-DUMP\TextMap\TextMapEN.json
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
|
pub struct TextMaps(pub Vec<TextMap>);
|
||||||
|
|
||||||
|
impl TextMaps {
|
||||||
|
pub fn parse() -> Result<Self, String> {
|
||||||
|
let file = std::fs::read_to_string("../Resources-DUMP/TextMap/TextMapEN.json").unwrap();
|
||||||
|
let v: Vec<TextMap> = serde_json::from_str(&file).unwrap();
|
||||||
|
Ok(TextMaps(v))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_by_i32(&self, i: i32) -> Option<TextMap> {
|
||||||
|
self.get_by_hash(Hash { Hash: i })
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_by_str(&self, s: &str) -> Option<TextMap> {
|
||||||
|
let hash = Hash::get_i32(s);
|
||||||
|
self.get_by_hash(Hash { Hash: hash })
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_by_hash(&self, h: Hash) -> Option<TextMap> {
|
||||||
|
let mut m = None;
|
||||||
|
if h.Hash == 0 {
|
||||||
|
return m;
|
||||||
|
}
|
||||||
|
for t in self.0.iter() {
|
||||||
|
if t.ID.Hash == h.Hash {
|
||||||
|
m = Some(t.clone());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
m
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
|
||||||
|
pub struct TextMap {
|
||||||
|
pub ID: Hash,
|
||||||
|
pub Text: String,
|
||||||
|
pub HasParam: bool,
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user