summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/components/ear.rs42
-rw-r--r--src/worldmessages.rs4
2 files changed, 26 insertions, 20 deletions
diff --git a/src/components/ear.rs b/src/components/ear.rs
index 4aafa72..6b723b0 100644
--- a/src/components/ear.rs
+++ b/src/components/ear.rs
@@ -1,4 +1,5 @@
+use serde_json::{json, Value};
use specs::{
HashMapStorage,
Component,
@@ -62,32 +63,37 @@ impl Notification {
}).to_string()
}
- pub fn as_message(&self) -> (String, String) {
- let body = match self {
- Sound{source, text} => {
+ pub fn as_message(&self) -> (String, String, Value) {
+ let (body, payload) = match self {
+ Sound{source, text} => {(
if let Some(name) = &source {
format!("{}: {}", name, &text)
} else {
text.clone()
- }
- }
- Health{actor, target, amount, typ} => {
+ },
+ json!({"source": source, "text": text})
+ )}
+ Health{actor, target, amount, typ} => {(
match typ {
Attack | Damage => format!("{} attacks {} for {} damage", actor, target, amount),
Heal => format!("{} heals {} for {} health", actor, target, amount)
- }
- },
- Kill{actor, target} => {
- format!("{} kills {}", actor, target)
- },
- Die{actor, target} => {
- format!("{} was killed by {}", target, actor)
- },
- Options{description, options} => {
- format!("{}. Options: {}", description, options.iter().map(|(command, desc)| format!("'{}': {};", command, desc)).collect::<Vec<String>>().join(" "))
- }
+ },
+ json!({"actor": actor.clone(), "target": target.clone(), "amount": amount})
+ )},
+ Kill{actor, target} => {(
+ format!("{} kills {}", actor, target),
+ json!({"actor": actor.clone(), "target": target.clone()})
+ )},
+ Die{actor, target} => {(
+ format!("{} was killed by {}", target, actor),
+ json!({"actor": actor.clone(), "target": target.clone()})
+ )},
+ Options{description, options} => {(
+ format!("{}. Options: {}", description, options.iter().map(|(command, desc)| format!("'{}': {};", command, desc)).collect::<Vec<String>>().join(" ")),
+ json!({"description": description.clone(), "options": options.clone()})
+ )}
};
- (self.type_name(), body)
+ (self.type_name(), body, payload)
}
}
diff --git a/src/worldmessages.rs b/src/worldmessages.rs
index 7dd05ec..979faa8 100644
--- a/src/worldmessages.rs
+++ b/src/worldmessages.rs
@@ -11,7 +11,7 @@ use crate::{
macro_rules! worldmessages {
($($name: ident, $typ: ident, $strname: expr, $filter: expr);*;) => {
- #[derive(Debug, Clone, Default, PartialEq, Eq)]
+ #[derive(Debug, Clone, Default, PartialEq)]
pub struct WorldMessage {
$(
pub $name: Option<$typ>,
@@ -68,7 +68,7 @@ pub type ChangeMessage = Vec<(Pos, Vec<Sprite>)>;
pub type HealthMessage = (i64, i64);
pub type InventoryMessage = Vec<(String, bool)>;
pub type GroundMessage = Vec<String>;
-pub type SoundMessage = Vec<(String, String)>;
+pub type SoundMessage = Vec<(String, String, Value)>;
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize)]
pub struct FieldMessage {