summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/shared/battle-map/BattleMap/Struct/Direction.elm')
-rw-r--r--src/shared/battle-map/BattleMap/Struct/Direction.elm58
1 files changed, 58 insertions, 0 deletions
diff --git a/src/shared/battle-map/BattleMap/Struct/Direction.elm b/src/shared/battle-map/BattleMap/Struct/Direction.elm
new file mode 100644
index 0000000..4620e29
--- /dev/null
+++ b/src/shared/battle-map/BattleMap/Struct/Direction.elm
@@ -0,0 +1,58 @@
+module BattleMap.Struct.Direction exposing
+(
+ Type(..),
+ opposite_of,
+ to_string,
+ decoder
+)
+
+-- Elm -------------------------------------------------------------------------
+import Json.Decode
+
+-- Battle Map ------------------------------------------------------------------
+
+--------------------------------------------------------------------------------
+-- TYPES -----------------------------------------------------------------------
+--------------------------------------------------------------------------------
+type Type =
+ None
+ | Left
+ | Right
+ | Up
+ | Down
+
+--------------------------------------------------------------------------------
+-- LOCAL -----------------------------------------------------------------------
+--------------------------------------------------------------------------------
+from_string : String -> Type
+from_string str =
+ case str of
+ "R" -> Right
+ "L" -> Left
+ "U" -> Up
+ "D" -> Down
+ _ -> None
+
+--------------------------------------------------------------------------------
+-- EXPORTED --------------------------------------------------------------------
+--------------------------------------------------------------------------------
+opposite_of : Type -> Type
+opposite_of d =
+ case d of
+ Left -> Right
+ Right -> Left
+ Up -> Down
+ Down -> Up
+ None -> None
+
+to_string : Type -> String
+to_string dir =
+ case dir of
+ Right -> "R"
+ Left -> "L"
+ Up -> "U"
+ Down -> "D"
+ None -> "N"
+
+decoder : (Json.Decode.Decoder Type)
+decoder = (Json.Decode.map (from_string) Json.Decode.string)