diff --git a/src/jsonmanager/json_manager.rs b/src/jsonmanager/json_manager.rs
index 517b7c5..cf2a906 100644
--- a/src/jsonmanager/json_manager.rs
+++ b/src/jsonmanager/json_manager.rs
@@ -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(v: I, key: fn (&B) -> A) -> BTreeMap>
+ where
+ A: Ord,
+ I: IntoIterator- ,
+{
+ let mut result = BTreeMap::>::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,
pub gadget_curves: HashMap,
pub gathers: HashMap,
+ pub shop_goods: HashMap>,
+ pub shop_rotate: HashMap>,
}
impl std::fmt::Debug for JsonManager { // TODO: fucking hack!
@@ -44,6 +60,8 @@ impl JsonManager {
let gadget_props: Vec = reader.read_json_list("GadgetProp");
let gc: Vec = reader.read_json_list("GadgetCurve");
let gathers: Vec = reader.read_json_list("Gather");
+ let shop_goods: Vec = reader.read_json_list("ShopGoods");
+ let shop_rotate: Vec = 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(),
};
}
}
diff --git a/src/jsonmanager/mod.rs b/src/jsonmanager/mod.rs
index cc1b50c..b4f9b01 100644
--- a/src/jsonmanager/mod.rs
+++ b/src/jsonmanager/mod.rs
@@ -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};
\ No newline at end of file
+pub use entity_curve::{CurveInfo,EntityCurve};
+pub use shop_goods::ShopGoods;
\ No newline at end of file
diff --git a/src/jsonmanager/shop_goods.rs b/src/jsonmanager/shop_goods.rs
new file mode 100644
index 0000000..fc89bcc
--- /dev/null
+++ b/src/jsonmanager/shop_goods.rs
@@ -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,
+ pub rotate_id: Option,
+ pub item_count: u32,
+ pub cost_items: Vec,
+ pub buy_limit: Option,
+
+ #[serde(with = "TimeManager")]
+ pub begin_time: Option,
+ #[serde(with = "TimeManager")]
+ pub end_time: Option,
+
+ pub min_show_level: u32,
+ pub max_show_level: Option,
+ pub sort_level: u32,
+ pub platform_type_list: Vec, // TODO: that's probably an enum too!
+
+ pub cost_hcoin: Option,
+ pub cost_mcoin: Option,
+ pub cost_scoin: Option,
+
+ pub precondition_param_list: Vec, // TODO: that's probably an enum!
+ pub precondition: Option, // TODO: that's an enum for sure
+}
\ No newline at end of file
diff --git a/src/jsonmanager/shop_rotate.rs b/src/jsonmanager/shop_rotate.rs
new file mode 100644
index 0000000..e97f0be
--- /dev/null
+++ b/src/jsonmanager/shop_rotate.rs
@@ -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,
+}
\ No newline at end of file