test messy res -> types::item

This commit is contained in:
yuvlian
2026-02-21 14:06:28 +07:00
parent cac15def52
commit 603ebb826c
7 changed files with 122 additions and 2 deletions

View 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,
}