mirror of
https://github.com/RustySamovar/RustySamovar.git
synced 2024-11-22 02:45:34 +00:00
Load info about shops from JSON
This commit is contained in:
parent
00f5685994
commit
9cac1c8d6c
@ -1,10 +1,12 @@
|
||||
use std::fs::read_to_string; // use instead of std::fs::File
|
||||
use std::path::Path;
|
||||
use std::collections::HashMap;
|
||||
use std::collections::{HashMap, BTreeMap};
|
||||
|
||||
use serde::Deserialize;
|
||||
use serde::de::DeserializeOwned;
|
||||
use crate::jsonmanager::gather::Gather;
|
||||
use crate::jsonmanager::shop_goods::ShopGoods;
|
||||
use crate::jsonmanager::shop_rotate::ShopRotate;
|
||||
|
||||
use super::avatar_skill_depot::AvatarSkillDepot;
|
||||
use super::entity_curve::EntityCurve;
|
||||
@ -12,6 +14,18 @@ use super::monster::Monster;
|
||||
use super::world_level::WorldLevel;
|
||||
use super::gadget_prop::GadgetProp;
|
||||
|
||||
fn group_nonconsec_by<A, B, I>(v: I, key: fn (&B) -> A) -> BTreeMap<A, Vec<B>>
|
||||
where
|
||||
A: Ord,
|
||||
I: IntoIterator<Item = B>,
|
||||
{
|
||||
let mut result = BTreeMap::<A, Vec<B>>::new();
|
||||
for e in v {
|
||||
result.entry(key(&e)).or_default().push(e);
|
||||
}
|
||||
result
|
||||
}
|
||||
|
||||
struct JsonReader {
|
||||
base_path: String,
|
||||
}
|
||||
@ -25,6 +39,8 @@ pub struct JsonManager {
|
||||
pub gadget_props: HashMap<u32, GadgetProp>,
|
||||
pub gadget_curves: HashMap<u32,EntityCurve>,
|
||||
pub gathers: HashMap<u32, Gather>,
|
||||
pub shop_goods: HashMap<u32, Vec<ShopGoods>>,
|
||||
pub shop_rotate: HashMap<u32, Vec<ShopRotate>>,
|
||||
}
|
||||
|
||||
impl std::fmt::Debug for JsonManager { // TODO: fucking hack!
|
||||
@ -44,6 +60,8 @@ impl JsonManager {
|
||||
let gadget_props: Vec<GadgetProp> = reader.read_json_list("GadgetProp");
|
||||
let gc: Vec<EntityCurve> = reader.read_json_list("GadgetCurve");
|
||||
let gathers: Vec<Gather> = reader.read_json_list("Gather");
|
||||
let shop_goods: Vec<ShopGoods> = reader.read_json_list("ShopGoods");
|
||||
let shop_rotate: Vec<ShopRotate> = reader.read_json_list("ShopRotate");
|
||||
|
||||
return JsonManager {
|
||||
reader: reader,
|
||||
@ -54,6 +72,10 @@ impl JsonManager {
|
||||
gadget_props: gadget_props.into_iter().map(|gp| (gp.id, gp)).collect(),
|
||||
gadget_curves: gc.into_iter().map(|g| (g.level, g)).collect(),
|
||||
gathers: gathers.into_iter().map(|g| (g.gadget_id, g)).collect(), // TODO: we index it by gadget_id and not by it's id!
|
||||
shop_goods: group_nonconsec_by(shop_goods, |sg| sg.shop_type).into_iter() // TODO: we're grouping by shop_type, not by goods ID!
|
||||
.collect(),
|
||||
shop_rotate: group_nonconsec_by(shop_rotate, |sr| sr.rotate_id).into_iter() // TODO: we're grouping by rotate_id, not by ID!
|
||||
.collect(),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -8,5 +8,8 @@ mod monster;
|
||||
mod world_level;
|
||||
mod gadget_prop;
|
||||
mod gather;
|
||||
mod shop_goods;
|
||||
mod shop_rotate;
|
||||
|
||||
pub use entity_curve::{CurveInfo,EntityCurve};
|
||||
pub use shop_goods::ShopGoods;
|
43
src/jsonmanager/shop_goods.rs
Normal file
43
src/jsonmanager/shop_goods.rs
Normal file
@ -0,0 +1,43 @@
|
||||
use chrono::NaiveDateTime;
|
||||
|
||||
use serde::{Serialize, Deserialize};
|
||||
|
||||
use crate::utils::TimeManager;
|
||||
|
||||
#[derive(Deserialize, Clone)]
|
||||
#[serde(rename_all="PascalCase")]
|
||||
pub struct CostItem {
|
||||
#[serde(default)]
|
||||
pub item_id: u32,
|
||||
#[serde(default)]
|
||||
pub count: u32,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Clone)]
|
||||
#[serde(rename_all="PascalCase")]
|
||||
pub struct ShopGoods {
|
||||
pub goods_id: u32,
|
||||
pub shop_type: u32,
|
||||
pub item_id: Option<u32>,
|
||||
pub rotate_id: Option<u32>,
|
||||
pub item_count: u32,
|
||||
pub cost_items: Vec<CostItem>,
|
||||
pub buy_limit: Option<u32>,
|
||||
|
||||
#[serde(with = "TimeManager")]
|
||||
pub begin_time: Option<NaiveDateTime>,
|
||||
#[serde(with = "TimeManager")]
|
||||
pub end_time: Option<NaiveDateTime>,
|
||||
|
||||
pub min_show_level: u32,
|
||||
pub max_show_level: Option<u32>,
|
||||
pub sort_level: u32,
|
||||
pub platform_type_list: Vec<String>, // TODO: that's probably an enum too!
|
||||
|
||||
pub cost_hcoin: Option<u32>,
|
||||
pub cost_mcoin: Option<u32>,
|
||||
pub cost_scoin: Option<u32>,
|
||||
|
||||
pub precondition_param_list: Vec<String>, // TODO: that's probably an enum!
|
||||
pub precondition: Option<String>, // TODO: that's an enum for sure
|
||||
}
|
10
src/jsonmanager/shop_rotate.rs
Normal file
10
src/jsonmanager/shop_rotate.rs
Normal file
@ -0,0 +1,10 @@
|
||||
use serde::{Serialize, Deserialize};
|
||||
|
||||
#[derive(Deserialize, Clone)]
|
||||
#[serde(rename_all="PascalCase")]
|
||||
pub struct ShopRotate {
|
||||
pub id: u32,
|
||||
pub rotate_id: u32,
|
||||
pub item_id: u32,
|
||||
pub rotate_order: u32,
|
||||
}
|
Loading…
Reference in New Issue
Block a user