Reduced backend resposibility to emmit game events, whole addon logic implemented in python side

This commit is contained in:
Wiktor Mazur
2020-02-18 16:55:33 +01:00
parent d73f34a33b
commit 133975cd77
78 changed files with 3203 additions and 1331 deletions
+65
View File
@@ -0,0 +1,65 @@
//! Translates photon packets into game messages
//! Generated messages based on assets/messages.json
//! See build.rs
pub mod messages;
/// generated from assets/item_ids.txt
/// See build.rs
mod itemdb;
use itemdb::ITEMDB;
use std::convert::From;
pub use messages::Message;
pub use messages::into_game_message;
/// Player inventory items
#[derive(Debug, Clone, PartialEq, Default)]
pub struct Items {
pub weapon: Option<String>,
pub offhand: Option<String>,
pub helmet: Option<String>,
pub armor: Option<String>,
pub boots: Option<String>,
pub bag: Option<String>,
pub cape: Option<String>,
pub mount: Option<String>,
pub potion: Option<String>,
pub food: Option<String>,
}
impl From<std::vec::Vec<u32>> for Items {
fn from(item_array: std::vec::Vec<u32>) -> Self {
macro_rules! extract {
($id:expr) => {
item_array
.get($id)
.iter()
.filter(|id| **id != &0u32)
.map(|code| ITEMDB.get(code).map(|s| s.to_string()))
.filter_map(|o| o)
.next()
};
}
Self{
weapon: extract!(0),
offhand: extract!(1),
helmet: extract!(2),
armor: extract!(3),
boots: extract!(4),
bag: extract!(5),
cape: extract!(6),
mount: extract!(7),
potion: extract!(8),
food: extract!(9),
}
}
}
#[test]
fn test_itemdb_generation() {
assert_eq!(ITEMDB.get(&0), Some(&"UNIQUE_HIDEOUT"));
}