From bb208dfdebb7dead0e7d68e837c37972498c22d5 Mon Sep 17 00:00:00 2001 From: Justin Worthe Date: Sat, 2 Jun 2018 13:09:13 +0200 Subject: Moved replay-based test to have convenience import from game engine replay --- src/engine/command.rs | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/engine/command.rs') diff --git a/src/engine/command.rs b/src/engine/command.rs index 17dbd5a..b350d65 100644 --- a/src/engine/command.rs +++ b/src/engine/command.rs @@ -29,4 +29,11 @@ impl BuildingType { use self::BuildingType::*; [Defence, Attack, Energy] } + + fn count() -> u8 { BuildingType::Energy as u8 + 1 } + pub fn from_u8(id: u8) -> Option { + use std::mem; + if id < Self::count() { Some(unsafe { mem::transmute(id) }) } else { None } + } + } -- cgit v1.2.3