51 lines
1.6 KiB
Rust
51 lines
1.6 KiB
Rust
use super::common::Hash;
|
|
use super::text_map::TextMaps;
|
|
use crate::types::common::Image;
|
|
use crate::types::item::{ItemMini, ItemSearch};
|
|
use anyhow::{Context, Result};
|
|
use serde::{Deserialize, Serialize};
|
|
use std::collections::BTreeMap;
|
|
|
|
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
|
|
pub struct ItemConfigs(pub Vec<ItemConfig>);
|
|
|
|
impl ItemConfigs {
|
|
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(Default, Debug, Clone, Serialize, Deserialize)]
|
|
pub struct ItemConfig {
|
|
#[serde(rename = "ID")]
|
|
pub id: i32,
|
|
#[serde(rename = "ItemName")]
|
|
pub item_name: Hash,
|
|
}
|