aboutsummaryrefslogtreecommitdiff
path: root/src/Game
diff options
context:
space:
mode:
authorJuan J. Martinez <jjm@usebox.net>2023-04-25 23:14:15 +0100
committerJuan J. Martinez <jjm@usebox.net>2023-04-25 23:14:15 +0100
commit5c316c38b5125a040c76109357933b2fe2c37721 (patch)
tree5fa00595b534513a68735b5ca4a1433839d8e3c6 /src/Game
parentd5545c94b84fc77438280007beb72792b70dd5a3 (diff)
downloadspace-plat-hs-5c316c38b5125a040c76109357933b2fe2c37721.tar.gz
space-plat-hs-5c316c38b5125a040c76109357933b2fe2c37721.zip
Reading direction property from entities
Diffstat (limited to 'src/Game')
-rw-r--r--src/Game/Map.hs32
1 files changed, 17 insertions, 15 deletions
diff --git a/src/Game/Map.hs b/src/Game/Map.hs
index 2a85dbe..5faf0f4 100644
--- a/src/Game/Map.hs
+++ b/src/Game/Map.hs
@@ -56,6 +56,11 @@ data JsonMapData = JsonMapData
}
deriving (Show)
+data ObjectBoolProperty = ObjectBoolProperty
+ { name :: String,
+ value :: Bool
+ }
+
instance JSON Tileset where
showJSON = undefined
readJSON (JSArray [JSObject obj]) = do
@@ -77,6 +82,13 @@ instance JSON Layer where
_ -> Error "unsupported layer type"
readJSON _ = mzero
+getObjectPropertyDir :: JSObject JSValue -> Result Dir
+getObjectPropertyDir obj = case get_field obj "properties" of
+ Just (JSArray [JSObject prop]) -> do
+ p <- ObjectBoolProperty <$> valFromObj "name" prop <*> valFromObj "value" prop
+ pure $ if p.name == "flip" && p.value then DirLeft else DirRight
+ _ -> pure DirRight
+
instance JSON Object where
showJSON = undefined
readJSON (JSObject obj) =
@@ -86,25 +98,15 @@ instance JSON Object where
Just "Battery" ->
BatteryEntity <$> valFromObj "x" obj <*> valFromObj "y" obj
Just "Slime" ->
- SlimeEntity <$> valFromObj "x" obj <*> valFromObj "y" obj <*> pure DirRight
+ SlimeEntity <$> valFromObj "x" obj <*> valFromObj "y" obj <*> getObjectPropertyDir obj
Just "Robot" ->
- RobotEntity <$> valFromObj "x" obj <*> valFromObj "y" obj <*> pure DirRight
+ RobotEntity <$> valFromObj "x" obj <*> valFromObj "y" obj <*> getObjectPropertyDir obj
Just "Shooter" ->
- ShooterEntity <$> valFromObj "x" obj <*> valFromObj "y" obj <*> pure DirRight
+ ShooterEntity <$> valFromObj "x" obj <*> valFromObj "y" obj <*> getObjectPropertyDir obj
Just "Runner" ->
- RunnerEntity <$> valFromObj "x" obj <*> valFromObj "y" obj <*> pure DirRight
+ RunnerEntity <$> valFromObj "x" obj <*> valFromObj "y" obj <*> getObjectPropertyDir obj
Just "Tracker" ->
- TrackerEntity <$> valFromObj "x" obj <*> valFromObj "y" obj <*> pure DirRight
- Just "Slime-l" ->
- SlimeEntity <$> valFromObj "x" obj <*> valFromObj "y" obj <*> pure DirLeft
- Just "Robot-l" ->
- RobotEntity <$> valFromObj "x" obj <*> valFromObj "y" obj <*> pure DirLeft
- Just "Shooter-l" ->
- ShooterEntity <$> valFromObj "x" obj <*> valFromObj "y" obj <*> pure DirLeft
- Just "Runner-l" ->
- RunnerEntity <$> valFromObj "x" obj <*> valFromObj "y" obj <*> pure DirLeft
- Just "Tracker-l" ->
- TrackerEntity <$> valFromObj "x" obj <*> valFromObj "y" obj <*> pure DirLeft
+ TrackerEntity <$> valFromObj "x" obj <*> valFromObj "y" obj <*> getObjectPropertyDir obj
Just (JSString (JSONString s)) -> Error $ "unsupported entity " ++ show s
e -> Error $ "unsupported entity in " ++ show e
readJSON _ = mzero