summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornsensfel <SpamShield0@noot-noot.org>2019-03-15 18:16:55 +0100
committernsensfel <SpamShield0@noot-noot.org>2019-03-15 18:16:55 +0100
commit6678cfe464ed9ee595f4f3dd7398dec1416454c9 (patch)
tree2700668874e13a81ec7467dcf26a1d246caa23ff /src/shared/battle-map/BattleMap/Struct/Direction.elm
parent24efb898f526e0aa02a0e15b74436da8ba166cac (diff)
[Broken] Starting a code refactoring...
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)