anyhow, cargo fmt
This commit is contained in:
@@ -1,36 +1,50 @@
|
||||
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>);
|
||||
use crate::types::item::{ItemMini, ItemSearch};
|
||||
use anyhow::{Context, Result};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
#[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});
|
||||
}
|
||||
pub fn parse_to_api_type(tm: &TextMaps) -> Result<ItemSearch> {
|
||||
let path = "../Resources-DUMP/ExcelOutput/ItemConfig.json";
|
||||
let file = std::fs::File::open(path).with_context(|| format!("Failed to open {}", path))?;
|
||||
let reader = std::io::BufReader::new(file);
|
||||
let cfg: Vec<ItemConfig> =
|
||||
serde_json::from_reader(reader).with_context(|| format!("Failed to parse {}", path))?;
|
||||
|
||||
let item_search = cfg
|
||||
.into_iter()
|
||||
.map(|item| {
|
||||
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))
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct ItemConfig {
|
||||
pub ID: i32,
|
||||
pub ItemName: Hash,
|
||||
#[serde(rename = "ID")]
|
||||
pub id: i32,
|
||||
#[serde(rename = "ItemName")]
|
||||
pub item_name: Hash,
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user