diff --git a/common/src/cmd.rs b/common/src/cmd.rs index c9991a74c2..a7b8ca6670 100644 --- a/common/src/cmd.rs +++ b/common/src/cmd.rs @@ -218,9 +218,8 @@ lazy_static! { buff_pack }; - static ref BLOCK_KINDS: Vec = terrain::block::BLOCK_KINDS - .keys() - .cloned() + static ref BLOCK_KINDS: Vec = terrain::block::BlockKind::iter() + .map(|bk| bk.to_string()) .collect(); static ref SPRITE_KINDS: Vec = terrain::sprite::SPRITE_KINDS diff --git a/common/src/terrain/block.rs b/common/src/terrain/block.rs index 69fc6e21f3..c2822b31b5 100644 --- a/common/src/terrain/block.rs +++ b/common/src/terrain/block.rs @@ -3,13 +3,11 @@ use crate::{ comp::{fluid_dynamics::LiquidKind, tool::ToolKind}, make_case_elim, }; -use enum_iterator::IntoEnumIterator; -use hashbrown::HashMap; -use lazy_static::lazy_static; use num_derive::FromPrimitive; use num_traits::FromPrimitive; use serde::{Deserialize, Serialize}; -use std::{convert::TryFrom, fmt, ops::Deref}; +use std::ops::Deref; +use strum_macros::{EnumIter, EnumString, ToString}; use vek::*; make_case_elim!( @@ -23,8 +21,10 @@ make_case_elim!( PartialEq, Serialize, Deserialize, - IntoEnumIterator, FromPrimitive, + EnumString, + EnumIter, + ToString, )] #[repr(u8)] pub enum BlockKind { @@ -88,22 +88,6 @@ impl BlockKind { pub const fn has_color(&self) -> bool { self.is_filled() } } -impl fmt::Display for BlockKind { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{:?}", self) } -} - -lazy_static! { - pub static ref BLOCK_KINDS: HashMap = BlockKind::into_enum_iter() - .map(|bk| (bk.to_string(), bk)) - .collect(); -} - -impl<'a> TryFrom<&'a str> for BlockKind { - type Error = (); - - fn try_from(s: &'a str) -> Result { BLOCK_KINDS.get(s).copied().ok_or(()) } -} - #[derive(Copy, Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)] pub struct Block { kind: BlockKind, diff --git a/server/src/cmd.rs b/server/src/cmd.rs index a10e1276d1..254dcec5e8 100644 --- a/server/src/cmd.rs +++ b/server/src/cmd.rs @@ -43,6 +43,7 @@ use hashbrown::{HashMap, HashSet}; use humantime::Duration as HumanDuration; use rand::Rng; use specs::{storage::StorageEntry, Builder, Entity as EcsEntity, Join, WorldExt}; +use std::str::FromStr; use vek::*; use wiring::{Circuit, Wire, WiringAction, WiringActionEffect, WiringElement}; use world::util::Sampler; @@ -515,7 +516,7 @@ fn handle_make_block( action: &ChatCommand, ) -> CmdResult<()> { if let Some(block_name) = scan_fmt_some!(&args, &action.arg_fmt(), String) { - if let Ok(bk) = BlockKind::try_from(block_name.as_str()) { + if let Ok(bk) = BlockKind::from_str(block_name.as_str()) { let pos = position(server, target, "target")?; server.state.set_block( pos.0.map(|e| e.floor() as i32),