From 6678cfe464ed9ee595f4f3dd7398dec1416454c9 Mon Sep 17 00:00:00 2001 From: nsensfel Date: Fri, 15 Mar 2019 18:16:55 +0100 Subject: [Broken] Starting a code refactoring... --- .../battle-map/BattleMap/Struct/Direction.elm | 58 ++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 src/shared/battle-map/BattleMap/Struct/Direction.elm (limited to 'src/shared/battle-map/BattleMap/Struct/Direction.elm') 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) -- cgit v1.2.3-70-g09d2