about summary refs log tree commit diff
diff options
context:
space:
mode:
authorsternenseemann <git@lukasepple.de>2019-10-29 14:27:18 +0100
committersternenseemann <git@lukasepple.de>2019-10-29 14:27:18 +0100
commite71d65f8774479615522cc94914516dfe3cc84ec (patch)
tree456336630969e3aa0e3c2d56fa43271c5438d1fe
parentff8a5fa2b5727f1fc28e09305236c889550b9dc6 (diff)
remove LocalMod switch to pure Id basted modification
-rw-r--r--lib/Grav2ty/Core.hs6
-rw-r--r--src/Main.hs17
2 files changed, 12 insertions, 11 deletions
diff --git a/lib/Grav2ty/Core.hs b/lib/Grav2ty/Core.hs
index 8b67af9..4d61c5a 100644
--- a/lib/Grav2ty/Core.hs
+++ b/lib/Grav2ty/Core.hs
@@ -48,9 +48,9 @@ type Tick = Integer
 type World a = Map Id (Object a)
 
 data Modifier
-  = NoMod            -- ^ Not modified, purely physics based.
-  | LocalMod         -- ^ Object is modified by local client / player.
-  | External Integer -- ^ Object is modified by an external source / other players.
+  = NoMod  -- ^ Not modified, purely physics based.
+  | Mod Id -- ^ Object is modified by the modifier with a certain 'Id',
+           --   which might be a local or remote player.
   deriving(Eq, Ord, Show)
 
 -- | @Just (<cannon position>, <cannon direction>)@ describes origin and
diff --git a/src/Main.hs b/src/Main.hs
index 0d4853c..3549c23 100644
--- a/src/Main.hs
+++ b/src/Main.hs
@@ -8,6 +8,7 @@ import Grav2ty.Simulation
 import Grav2ty.Control
 
 import Control.Lens
+import Control.Monad (when)
 import Linear.V2
 import Control.Monad.Trans.State
 import Data.Fixed (mod')
@@ -53,13 +54,10 @@ renderUi state = uncurry translate (homBimap ((+ 50) . (* (-1)) . (/ 2) . fromIn
   . (^. graphics.glossViewPort) $ state)
   . scale 0.2 0.2 . Color green . Text $ uiText
   where uiText = printf "Acceleration: %.0f Time/Tick: %f Tick: %d" acc tpt t
-        acc = fromMaybe 0 $ state^?inputs.at LocalMod ._Just.modAcc
+        acc = fromMaybe 0 $ state^?inputs.at localMod ._Just.modAcc
         t = state^.tick
         tpt = state^.timePerTick
 
-renderStars :: (Float, Float) -> Picture
-renderStars center = undefined
-
 renderGame :: Grav2tyState Float GlossState -> Picture
 renderGame state = Pictures [ renderUi  state, applyViewPort objs ]
   where objs = Pictures . foldl' (\l x -> renderObject x : l) [] $ state^.world
@@ -84,7 +82,7 @@ eventHandler :: (Show a, Ord a, Real a, Floating a) => Event
 eventHandler (EventKey key Down _ _) state = action state
   where updateLocalMod :: Lens' (Modification a) b -> (b -> b)
                        -> Grav2tyState a GlossState -> Grav2tyState a GlossState
-        updateLocalMod l = over (inputs.at LocalMod ._Just.l)
+        updateLocalMod l = over (inputs.at localMod ._Just.l)
         accStep = 1
         rotStep = pi / 10
         scaleStep = 1.1
@@ -106,16 +104,19 @@ eventHandler _ s = s
 
 updateWorld :: Float -> Grav2tyState Float GlossState -> Grav2tyState Float GlossState
 updateWorld ts state = snd . flip runState state $ timePerTick .= ts >> processTick hook
-  where hook obj@Dynamic { objectMod = LocalMod } =
+  where hook obj@Dynamic { } = when (objectMod obj == localMod) $
           graphics.glossViewPortCenter .= (vectorToPoint . objectLoc $ obj)
         hook _ = pure ()
 
+localMod :: Modifier
+localMod = Mod 0
+
 initialWorld :: Fractional a => Grav2tyState a GlossState
 initialWorld = snd . flip runState (Grav2tyState 0 (1/300)
-  (M.fromList [(LocalMod, zeroModification)])
+  (M.fromList [(localMod, zeroModification)])
   (GlossState (800, 800) (0, 0) 1 True)
   mempty 0) $ do
-    addObject $ Dynamic shipHitbox 0 10000 (V2 200 0) (V2 0 0) (V2 0 0) LocalMod (Just (V2 15 0, V2 1 0)) Nothing
+    addObject $ Dynamic shipHitbox 0 10000 (V2 200 0) (V2 0 0) (V2 0 0) localMod (Just (V2 15 0, V2 1 0)) Nothing
     addObject $ Dynamic (centeredCircle 10) 0 5000 (V2 0 200) (V2 15 0) (V2 0 0) NoMod Nothing Nothing
     addObject $ Static (centeredCircle 80) 0 moonMass (V2 0 0)
 --  addObject $ Static (centeredCircle 40) 0 (0.5 * moonMass) (V2 250 250)