From 09306cb76c6e1eabb4082a985a0a0fa335bda5c1 Mon Sep 17 00:00:00 2001 From: troido Date: Fri, 25 Sep 2020 08:54:20 +0200 Subject: proper serialisation for playerstate; strum for old-style enums --- src/components/messages.rs | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) (limited to 'src/components/messages.rs') diff --git a/src/components/messages.rs b/src/components/messages.rs index 5e27cc6..f815ab5 100644 --- a/src/components/messages.rs +++ b/src/components/messages.rs @@ -1,6 +1,7 @@ use std::collections::HashMap; use std::any::Any; +use strum_macros::{EnumString, Display}; use specs::{ Component, DenseVecStorage, @@ -84,7 +85,8 @@ pub type AttackInbox = Inbox; -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, EnumString, Display)] +#[strum(serialize_all="snake_case")] pub enum Trigger { // basic triggers Loot, @@ -96,20 +98,6 @@ pub enum Trigger { Change // Remove + Build } -impl Trigger { - pub fn from_str(txt: &str) -> Option { - Some(match txt { - "loot" => Self::Loot, - "remove" => Self::Remove, - "build" => Self::Build, - "spawn" => Self::Spawn, - "die" => Self::Die, - "change" => Self::Change, - _ => {return None} - }) - } -} - impl Message for Trigger {} pub type TriggerBox = Inbox; -- cgit