mirror of
https://git.ethanthesleepy.one/ethanaobrien/ew
synced 2026-07-12 08:42:20 +08:00
Redo databases module to pull information from masterdata csv files
This commit is contained in:
@@ -1,320 +1,245 @@
|
||||
use jzon::{array, object, JsonValue};
|
||||
use lazy_static::lazy_static;
|
||||
|
||||
use crate::include_file;
|
||||
pub mod csv;
|
||||
|
||||
use csv::Region;
|
||||
|
||||
fn t(name: &str) -> JsonValue { csv::table(Region::Jp, name) }
|
||||
fn g(name: &str) -> JsonValue { csv::table(Region::En, name) }
|
||||
|
||||
fn index_by(items: &JsonValue, key: &str) -> JsonValue {
|
||||
let mut info = object! {};
|
||||
for data in items.members() {
|
||||
info[data[key].to_string()] = data.clone();
|
||||
}
|
||||
info
|
||||
}
|
||||
|
||||
lazy_static! {
|
||||
pub static ref STORY: JsonValue = {
|
||||
let mut info = object!{};
|
||||
let items = jzon::parse(&include_file!("src/router/databases/json/story_part.json")).unwrap();
|
||||
for data in items.members() {
|
||||
info[data["id"].to_string()] = data.clone();
|
||||
}
|
||||
info
|
||||
};
|
||||
pub static ref LOGIN_REWARDS: JsonValue = {
|
||||
let mut info = object!{};
|
||||
let items = jzon::parse(&include_file!("src/router/databases/json/login_bonus_reward.json")).unwrap();
|
||||
for data in items.members() {
|
||||
info[data["id"].to_string()] = data.clone();
|
||||
}
|
||||
info
|
||||
};
|
||||
pub static ref SHOP_INFO: JsonValue = {
|
||||
let mut info = object!{};
|
||||
let items = jzon::parse(&include_file!("src/router/databases/json/shop_item.json")).unwrap();
|
||||
for data in items.members() {
|
||||
info[data["id"].to_string()] = data.clone();
|
||||
}
|
||||
info
|
||||
};
|
||||
pub static ref STORY: JsonValue = index_by(&t("story_part"), "id");
|
||||
|
||||
pub static ref LOGIN_REWARDS: JsonValue = index_by(&t("login_bonus_reward"), "id");
|
||||
|
||||
pub static ref SHOP_INFO: JsonValue = index_by(&t("shop_item"), "id");
|
||||
|
||||
pub static ref CHATS: JsonValue = {
|
||||
let mut chats = object!{};
|
||||
let items = jzon::parse(&include_file!("src/router/databases/json/chat_room.json")).unwrap();
|
||||
for data in items.members() {
|
||||
if chats[data["masterChatId"].to_string()].is_null() {
|
||||
chats[data["masterChatId"].to_string()] = object!{};
|
||||
let mut chats = object! {};
|
||||
for data in t("chat_room").members() {
|
||||
let chat_id = data["masterChatId"].to_string();
|
||||
if chats[&chat_id].is_null() {
|
||||
chats[&chat_id] = object! {};
|
||||
}
|
||||
chats[data["masterChatId"].to_string()][data["roomId"].to_string()] = data.clone();
|
||||
chats[&chat_id][data["roomId"].to_string()] = data.clone();
|
||||
}
|
||||
chats
|
||||
};
|
||||
|
||||
pub static ref CHAPTERS: JsonValue = {
|
||||
let mut chats = object!{};
|
||||
let items = jzon::parse(&include_file!("src/router/databases/json/chat_chapter.json")).unwrap();
|
||||
for data in items.members() {
|
||||
if chats[data["masterChatId"].to_string()].is_null() {
|
||||
chats[data["masterChatId"].to_string()] = object!{};
|
||||
let mut chats = object! {};
|
||||
for data in t("chat_chapter").members() {
|
||||
let chat_id = data["masterChatId"].to_string();
|
||||
if chats[&chat_id].is_null() {
|
||||
chats[&chat_id] = object! {};
|
||||
}
|
||||
chats[data["masterChatId"].to_string()][data["roomId"].to_string()] = data.clone();
|
||||
chats[&chat_id][data["roomId"].to_string()] = data.clone();
|
||||
}
|
||||
chats
|
||||
};
|
||||
pub static ref CHAPTERS_MASTER: JsonValue = {
|
||||
let mut chats = object!{};
|
||||
let items = jzon::parse(&include_file!("src/router/databases/json/chat_chapter.json")).unwrap();
|
||||
for data in items.members() {
|
||||
chats[data["chapterId"].to_string()] = data.clone();
|
||||
}
|
||||
chats
|
||||
};
|
||||
pub static ref EXCHANGE_LIST: JsonValue = {
|
||||
let mut info = object!{};
|
||||
let items = jzon::parse(&include_file!("src/router/databases/json/exchange_item.json")).unwrap();
|
||||
for data in items.members() {
|
||||
info[data["id"].to_string()] = data.clone();
|
||||
}
|
||||
info
|
||||
};
|
||||
pub static ref EXCHANGE_REWARD: JsonValue = {
|
||||
let mut info = object!{};
|
||||
let items = jzon::parse(&include_file!("src/router/databases/json/exchange_item_reward.json")).unwrap();
|
||||
for data in items.members() {
|
||||
info[data["id"].to_string()] = data.clone();
|
||||
}
|
||||
info
|
||||
};
|
||||
pub static ref LIVE_LIST: JsonValue = {
|
||||
let mut info = object!{};
|
||||
let items = jzon::parse(&include_file!("src/router/databases/json/live.json")).unwrap();
|
||||
for data in items.members() {
|
||||
info[data["id"].to_string()] = data.clone();
|
||||
}
|
||||
info
|
||||
};
|
||||
pub static ref LIVES: JsonValue = {
|
||||
jzon::parse(&include_file!("src/router/databases/json/live.json")).unwrap()
|
||||
};
|
||||
pub static ref MISSION_DATA: JsonValue = {
|
||||
jzon::parse(&include_file!("src/router/databases/json/live_mission.json")).unwrap()
|
||||
};
|
||||
pub static ref MISSION_COMBO_DATA: JsonValue = {
|
||||
let mut info = object!{};
|
||||
let items = jzon::parse(&include_file!("src/router/databases/json/live_mission_combo.json")).unwrap();
|
||||
for data in items.members() {
|
||||
info[data["masterMusicId"].to_string()] = data.clone();
|
||||
}
|
||||
info
|
||||
};
|
||||
pub static ref MISSION_REWARD_DATA: JsonValue = {
|
||||
let mut info = object!{};
|
||||
let items = jzon::parse(&include_file!("src/router/databases/json/live_mission_reward.json")).unwrap();
|
||||
for data in items.members() {
|
||||
info[data["id"].to_string()] = data.clone();
|
||||
}
|
||||
info
|
||||
};
|
||||
pub static ref CARD_LIST: JsonValue = {
|
||||
let mut info = object!{};
|
||||
let items = jzon::parse(&include_file!("src/router/databases/json/card.json")).unwrap();
|
||||
for data in items.members() {
|
||||
info[data["id"].to_string()] = data.clone();
|
||||
}
|
||||
info
|
||||
};
|
||||
|
||||
pub static ref CHAPTERS_MASTER: JsonValue = index_by(&t("chat_chapter"), "chapterId");
|
||||
|
||||
pub static ref EXCHANGE_LIST: JsonValue = index_by(&t("exchange_item"), "id");
|
||||
|
||||
pub static ref EXCHANGE_REWARD: JsonValue = index_by(&t("exchange_item_reward"), "id");
|
||||
|
||||
pub static ref LIVE_LIST: JsonValue = index_by(&t("live"), "id");
|
||||
|
||||
pub static ref LIVES: JsonValue = t("live");
|
||||
|
||||
pub static ref MISSION_DATA: JsonValue = t("live_mission");
|
||||
|
||||
pub static ref MISSION_COMBO_DATA: JsonValue =
|
||||
index_by(&t("live_mission_combo"), "masterMusicId");
|
||||
|
||||
pub static ref MISSION_REWARD_DATA: JsonValue =
|
||||
index_by(&t("live_mission_reward"), "id");
|
||||
|
||||
pub static ref CARD_LIST: JsonValue = index_by(&t("card"), "id");
|
||||
|
||||
pub static ref LOTTERY_INFO: JsonValue = {
|
||||
let mut info = object!{};
|
||||
let items = jzon::parse(&include_file!("src/router/databases/json/login_bonus.json")).unwrap();
|
||||
for data in items.members() {
|
||||
if info[data["id"].to_string()].is_null() {
|
||||
info[data["id"].to_string()] = object!{
|
||||
info: data.clone(),
|
||||
days: []
|
||||
};
|
||||
let mut info = object! {};
|
||||
for data in t("login_bonus").members() {
|
||||
let id = data["id"].to_string();
|
||||
if info[&id].is_null() {
|
||||
info[&id] = object! { info: data.clone(), days: [] };
|
||||
}
|
||||
}
|
||||
let days = jzon::parse(&include_file!("src/router/databases/json/login_bonus_reward_setting.json")).unwrap();
|
||||
for data in days.members() {
|
||||
if info[data["masterLoginBonusId"].to_string()].is_null() {
|
||||
for data in t("login_bonus_reward_setting").members() {
|
||||
let id = data["masterLoginBonusId"].to_string();
|
||||
if info[&id].is_null() {
|
||||
continue;
|
||||
}
|
||||
info[data["masterLoginBonusId"].to_string()]["days"].push(data.clone()).unwrap();
|
||||
info[&id]["days"].push(data.clone()).unwrap();
|
||||
}
|
||||
let mut real_info = object!{};
|
||||
for data in info.entries() {
|
||||
real_info[data.1["info"]["id"].to_string()] = data.1.clone();
|
||||
let mut real_info = object! {};
|
||||
for entry in info.entries() {
|
||||
real_info[entry.1["info"]["id"].to_string()] = entry.1.clone();
|
||||
}
|
||||
real_info
|
||||
};
|
||||
|
||||
pub static ref CARDS: JsonValue = {
|
||||
let mut cardz = object!{};
|
||||
let items = jzon::parse(&include_file!("src/router/databases/json/lottery_item.json")).unwrap();
|
||||
let items_global = jzon::parse(&include_file!("src/router/databases/json/global/lottery_item.json")).unwrap();
|
||||
for data in items.members() {
|
||||
if cardz[data["id"].to_string()].is_null() {
|
||||
cardz[data["id"].to_string()] = object!{};
|
||||
}
|
||||
cardz[data["id"].to_string()][data["number"].to_string()] = data.clone();
|
||||
let mut cardz = object! {};
|
||||
for data in t("lottery_item").members() {
|
||||
let id = data["id"].to_string();
|
||||
if cardz[&id].is_null() { cardz[&id] = object! {}; }
|
||||
cardz[&id][data["number"].to_string()] = data.clone();
|
||||
}
|
||||
for data in items_global.members() {
|
||||
if cardz[data["id"].to_string()].is_null() {
|
||||
cardz[data["id"].to_string()] = object!{};
|
||||
}
|
||||
if cardz[data["id"].to_string()][data["number"].to_string()].is_null() {
|
||||
cardz[data["id"].to_string()][data["number"].to_string()] = data.clone();
|
||||
for data in g("lottery_item").members() {
|
||||
let id = data["id"].to_string();
|
||||
if cardz[&id].is_null() { cardz[&id] = object! {}; }
|
||||
let num = data["number"].to_string();
|
||||
if cardz[&id][&num].is_null() {
|
||||
cardz[&id][&num] = data.clone();
|
||||
}
|
||||
}
|
||||
cardz
|
||||
};
|
||||
|
||||
pub static ref POOL: JsonValue = {
|
||||
let mut cardz = object!{};
|
||||
let mut i2 = array![];
|
||||
let items = jzon::parse(&include_file!("src/router/databases/json/lottery_item.json")).unwrap();
|
||||
let items_global = jzon::parse(&include_file!("src/router/databases/json/global/lottery_item.json")).unwrap();
|
||||
for data in items.members() {
|
||||
if cardz[data["id"].to_string()].is_null() {
|
||||
cardz[data["id"].to_string()] = array![];
|
||||
i2.push(data["id"].to_string()).unwrap();
|
||||
let mut cardz = object! {};
|
||||
let mut seen_ids = array![];
|
||||
for data in t("lottery_item").members() {
|
||||
let id = data["id"].to_string();
|
||||
if cardz[&id].is_null() {
|
||||
cardz[&id] = array![];
|
||||
seen_ids.push(id.clone()).unwrap();
|
||||
}
|
||||
cardz[data["id"].to_string()].push(data["number"].clone()).unwrap();
|
||||
cardz[&id].push(data["number"].clone()).unwrap();
|
||||
}
|
||||
for data in items_global.members() {
|
||||
if i2.contains(data["id"].to_string()) {
|
||||
continue;
|
||||
}
|
||||
if cardz[data["id"].to_string()].is_null() {
|
||||
cardz[data["id"].to_string()] = array![];
|
||||
}
|
||||
cardz[data["id"].to_string()].push(data["number"].clone()).unwrap();
|
||||
for data in g("lottery_item").members() {
|
||||
let id = data["id"].to_string();
|
||||
if seen_ids.contains(id.as_str()) { continue; }
|
||||
if cardz[&id].is_null() { cardz[&id] = array![]; }
|
||||
cardz[&id].push(data["number"].clone()).unwrap();
|
||||
}
|
||||
cardz
|
||||
};
|
||||
|
||||
pub static ref RARITY: JsonValue = {
|
||||
let mut cardz = object!{};
|
||||
let mut i2 = array![];
|
||||
let items = jzon::parse(&include_file!("src/router/databases/json/lottery_rarity.json")).unwrap();
|
||||
let items_global = jzon::parse(&include_file!("src/router/databases/json/global/lottery_rarity.json")).unwrap();
|
||||
for data in items.members() {
|
||||
if cardz[data["id"].to_string()].is_null() {
|
||||
cardz[data["id"].to_string()] = array![];
|
||||
i2.push(data["id"].to_string()).unwrap();
|
||||
let mut cardz = object! {};
|
||||
let mut seen_ids = array![];
|
||||
for data in t("lottery_rarity").members() {
|
||||
let id = data["id"].to_string();
|
||||
if cardz[&id].is_null() {
|
||||
cardz[&id] = array![];
|
||||
seen_ids.push(id.clone()).unwrap();
|
||||
}
|
||||
cardz[data["id"].to_string()].push(data.clone()).unwrap();
|
||||
cardz[&id].push(data.clone()).unwrap();
|
||||
}
|
||||
for data in items_global.members() {
|
||||
if i2.contains(data["id"].to_string()) {
|
||||
continue;
|
||||
}
|
||||
if cardz[data["id"].to_string()].is_null() {
|
||||
cardz[data["id"].to_string()] = array![];
|
||||
}
|
||||
cardz[data["id"].to_string()].push(data.clone()).unwrap();
|
||||
for data in g("lottery_rarity").members() {
|
||||
let id = data["id"].to_string();
|
||||
if seen_ids.contains(id.as_str()) { continue; }
|
||||
if cardz[&id].is_null() { cardz[&id] = array![]; }
|
||||
cardz[&id].push(data.clone()).unwrap();
|
||||
}
|
||||
cardz
|
||||
};
|
||||
|
||||
pub static ref LOTTERY: JsonValue = {
|
||||
let mut cardz = object!{};
|
||||
let items = jzon::parse(&include_file!("src/router/databases/json/lottery.json")).unwrap();
|
||||
let items_global = jzon::parse(&include_file!("src/router/databases/json/global/lottery.json")).unwrap();
|
||||
for data in items.members() {
|
||||
let mut cardz = object! {};
|
||||
for data in t("lottery").members() {
|
||||
cardz[data["id"].to_string()] = data.clone();
|
||||
}
|
||||
for data in items_global.members() {
|
||||
if cardz[data["id"].to_string()].is_null() {
|
||||
cardz[data["id"].to_string()] = data.clone();
|
||||
for data in g("lottery").members() {
|
||||
let id = data["id"].to_string();
|
||||
if cardz[&id].is_null() {
|
||||
cardz[&id] = data.clone();
|
||||
}
|
||||
}
|
||||
cardz
|
||||
};
|
||||
|
||||
pub static ref PRICE: JsonValue = {
|
||||
let mut cardz = object!{};
|
||||
let items = jzon::parse(&include_file!("src/router/databases/json/lottery_price.json")).unwrap();
|
||||
let items_global = jzon::parse(&include_file!("src/router/databases/json/global/lottery_price.json")).unwrap();
|
||||
for data in items.members() {
|
||||
if cardz[data["id"].to_string()].is_null() {
|
||||
cardz[data["id"].to_string()] = object!{};
|
||||
}
|
||||
cardz[data["id"].to_string()][data["number"].to_string()] = data.clone();
|
||||
let mut cardz = object! {};
|
||||
for data in t("lottery_price").members() {
|
||||
let id = data["id"].to_string();
|
||||
if cardz[&id].is_null() { cardz[&id] = object! {}; }
|
||||
cardz[&id][data["number"].to_string()] = data.clone();
|
||||
}
|
||||
for data in items_global.members() {
|
||||
if cardz[data["id"].to_string()].is_null() {
|
||||
cardz[data["id"].to_string()] = object!{};
|
||||
}
|
||||
if cardz[data["id"].to_string()][data["number"].to_string()].is_null() {
|
||||
cardz[data["id"].to_string()][data["number"].to_string()] = data.clone();
|
||||
for data in g("lottery_price").members() {
|
||||
let id = data["id"].to_string();
|
||||
if cardz[&id].is_null() { cardz[&id] = object! {}; }
|
||||
let num = data["number"].to_string();
|
||||
if cardz[&id][&num].is_null() {
|
||||
cardz[&id][&num] = data.clone();
|
||||
}
|
||||
}
|
||||
cardz
|
||||
};
|
||||
pub static ref MISSION_LIST: JsonValue = {
|
||||
let mut info = object!{};
|
||||
let items = jzon::parse(&include_file!("src/router/databases/json/mission.json")).unwrap();
|
||||
for data in items.members() {
|
||||
info[data["id"].to_string()] = data.clone();
|
||||
}
|
||||
info
|
||||
};
|
||||
|
||||
pub static ref MISSION_LIST: JsonValue = index_by(&t("mission"), "id");
|
||||
|
||||
pub static ref CHARACTER_CHATS: JsonValue = {
|
||||
let mut info = object!{};
|
||||
let items = jzon::parse(&include_file!("src/router/databases/json/mission.json")).unwrap();
|
||||
for data in items.members() {
|
||||
if data["conditionValues"].len() != 1 || (data["conditionType"] != 50 && data["conditionType"] != 51) {
|
||||
let mut info = object! {};
|
||||
for data in t("mission").members() {
|
||||
if data["conditionValues"].len() != 1
|
||||
|| (data["conditionType"] != 50 && data["conditionType"] != 51)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if info[data["conditionValues"].to_string()].is_null() {
|
||||
info[data["conditionValues"].to_string()] = object!{};
|
||||
}
|
||||
info[data["conditionValues"][0].to_string()][data["conditionType"].to_string()] = array![data["masterMissionRewardId"].clone(), data["id"].clone()];
|
||||
}
|
||||
info
|
||||
};
|
||||
pub static ref MISSION_REWARD: JsonValue = {
|
||||
let mut info = object!{};
|
||||
let items = jzon::parse(&include_file!("src/router/databases/json/mission_reward.json")).unwrap();
|
||||
for data in items.members() {
|
||||
info[data["id"].to_string()] = data.clone();
|
||||
}
|
||||
info
|
||||
};
|
||||
pub static ref ITEM_INFO: JsonValue = {
|
||||
let mut info = object!{};
|
||||
let items = jzon::parse(&include_file!("src/router/databases/json/item.json")).unwrap();
|
||||
for data in items.members() {
|
||||
info[data["id"].to_string()] = data.clone();
|
||||
let cv0 = data["conditionValues"][0].to_string();
|
||||
if info[&cv0].is_null() { info[&cv0] = object! {}; }
|
||||
info[&cv0][data["conditionType"].to_string()] = array![
|
||||
data["masterMissionRewardId"].clone(),
|
||||
data["id"].clone()
|
||||
];
|
||||
}
|
||||
info
|
||||
};
|
||||
|
||||
pub static ref MISSION_REWARD: JsonValue = index_by(&t("mission_reward"), "id");
|
||||
|
||||
pub static ref ITEM_INFO: JsonValue = index_by(&t("item"), "id");
|
||||
|
||||
pub static ref MUSIC: JsonValue = {
|
||||
let mut info = object!{};
|
||||
let items = jzon::parse(&include_file!("src/router/databases/json/music.json")).unwrap();
|
||||
let music = t("music");
|
||||
let mut info = object! {};
|
||||
for live in LIVE_LIST.entries() {
|
||||
info[live.1["id"].to_string()] = loop {
|
||||
let mut val = object!{};
|
||||
for data in items.members() {
|
||||
if live.1["masterMusicId"] == data["id"] {
|
||||
val = data.clone();
|
||||
break;
|
||||
}
|
||||
let mut val = object! {};
|
||||
for data in music.members() {
|
||||
if live.1["masterMusicId"] == data["id"] {
|
||||
val = data.clone();
|
||||
break;
|
||||
}
|
||||
break val;
|
||||
};
|
||||
};
|
||||
}
|
||||
info[live.1["id"].to_string()] = val;
|
||||
}
|
||||
info
|
||||
};
|
||||
|
||||
pub static ref MUSIC_EN: JsonValue = {
|
||||
let mut info = object!{};
|
||||
let items = jzon::parse(&include_file!("src/router/databases/json/global/music.json")).unwrap();
|
||||
let music = g("music");
|
||||
let mut info = object! {};
|
||||
for live in LIVE_LIST.entries() {
|
||||
info[live.1["id"].to_string()] = loop {
|
||||
let mut val = object!{};
|
||||
for data in items.members() {
|
||||
if live.1["masterMusicId"] == data["id"] {
|
||||
val = data.clone();
|
||||
break;
|
||||
}
|
||||
let mut val = object! {};
|
||||
for data in music.members() {
|
||||
if live.1["masterMusicId"] == data["id"] {
|
||||
val = data.clone();
|
||||
break;
|
||||
}
|
||||
break val;
|
||||
};
|
||||
};
|
||||
}
|
||||
info[live.1["id"].to_string()] = val;
|
||||
}
|
||||
info
|
||||
};
|
||||
pub static ref RANKS: JsonValue = {
|
||||
jzon::parse(&include_file!("src/router/databases/json/user_rank.json")).unwrap()
|
||||
};
|
||||
|
||||
pub static ref RANKS: JsonValue = t("user_rank");
|
||||
|
||||
pub static ref EVOLVE_COST: JsonValue = {
|
||||
let mut info = object!{};
|
||||
let items = jzon::parse(&include_file!("src/router/databases/json/card_evolve.json")).unwrap();
|
||||
for data in items.members() {
|
||||
let mut info = object! {};
|
||||
for data in t("card_evolve").members() {
|
||||
info[data["rarity"].to_string()] = data["price"].clone();
|
||||
}
|
||||
info
|
||||
|
||||
Reference in New Issue
Block a user