computer has now an "on" state

This commit is contained in:
nek0 2018-08-12 06:28:31 +02:00
parent b14d9a6d76
commit 1f63e15582
2 changed files with 93 additions and 12 deletions

View file

@ -62,7 +62,7 @@ loadFork
-> MVar (Float, T.Text) -> MVar (Float, T.Text)
-> IO () -> IO ()
loadFork ws win glc nvg future progress = do loadFork ws win glc nvg future progress = do
let stateSteps = 36 let stateSteps = 37
increment = 1 / stateSteps increment = 1 / stateSteps
SDL.glMakeCurrent win glc SDL.glMakeCurrent win glc
modifyMVar_ progress (return . (\(p, _) -> modifyMVar_ progress (return . (\(p, _) ->
@ -272,6 +272,15 @@ loadFork ws win glc nvg future progress = do
, AnimationConfig (0, 0) (64, 74) (64, 0) 2 2 APLoop , AnimationConfig (0, 0) (64, 74) (64, 0) 2 2 APLoop
) )
] ]
modifyMVar_ progress (return . (\(p, _) ->
( p + increment
, "Loading Animation \"computer: on\""
)))
computerOn <- loadAnimationSprites "assets/misc/tableCornerComputer.png" nvg
[ ( AnimId "computer" "on" N
, AnimationConfig (128, 0) (64, 74) (0, 0) 1 0 APLoop
)
]
modifyMVar_ progress (return . (\(p, _) -> modifyMVar_ progress (return . (\(p, _) ->
( p + increment ( p + increment
, "Loading Animation \"computer: hack\"" , "Loading Animation \"computer: hack\""
@ -316,6 +325,7 @@ loadFork ws win glc nvg future progress = do
copierStand ++ copierStand ++
copierCopy ++ copierCopy ++
computerOff ++ computerOff ++
computerOn ++
computerHack ++ computerHack ++
toiletFree ++ toiletFree ++
toiletOccupied toiletOccupied

View file

@ -36,6 +36,41 @@ instance ObjectAction ObjType ObjState where
Just ttl -> return (ttl < 0) Just ttl -> return (ttl < 0)
when trans (setEntity ent =<< objectTransition t s False ent) when trans (setEntity ent =<< objectTransition t s False ent)
objectAction dt t@ObjComputer s@"on" ent = do
[vel] <- efor allEnts $ do
with player
with vel
query vel
emap (anEnt ent) $ do
mtime <- queryMaybe objStateTime
case mtime of
Nothing -> do
liftIO $ logIO Debug ("Computer " ++ show ent ++ ": on!")
let dur = actionTime t s
return unchanged
{ objStateTime = Set dur
}
Just ttl -> do
return unchanged
{ objStateTime = Set (ttl - dt)
}
trans <- efor (anEnt ent) $ do
mttl <- queryMaybe objStateTime
case mttl of
Nothing -> return Nothing
Just ttl -> do
pa <- query objPlayerActivated
if (ttl < 0)
then do
return (Just pa)
else if (pa && vel `dot` vel > 0)
then return (Just pa)
else return Nothing
maybe
(return ())
(\tpa -> setEntity ent =<< objectTransition t s tpa ent)
(head trans)
objectAction dt t@ObjComputer s@"hack" ent = do objectAction dt t@ObjComputer s@"hack" ent = do
[vel] <- efor allEnts $ do [vel] <- efor allEnts $ do
with player with player
@ -104,7 +139,8 @@ instance ObjectAction ObjType ObjState where
objectTransition ObjComputer "off" pa ent = do objectTransition ObjComputer "off" pa ent = do
[e] <- efor (anEnt ent) $ do [e] <- efor (anEnt ent) $ do
solved <- queryMaybe objSolved solved <- queryMaybe objSolved
if pa && not (fromMaybe False solved) if pa
then if not (fromMaybe False solved)
then do then do
let nstat = AnimState let nstat = AnimState
(AnimId "computer" "hack" N) (AnimId "computer" "hack" N)
@ -115,10 +151,29 @@ instance ObjectAction ObjType ObjState where
, objState = Set "hack" , objState = Set "hack"
, objPlayerActivated = Set True , objPlayerActivated = Set True
} }
else return unchanged else do
let nstat = AnimState
(AnimId "computer" "on" N)
0
0
return unchanged
{ anim = Set nstat
, objState = Set "on"
, objPlayerActivated = Set True
}
else do
let nstat = AnimState
(AnimId "computer" "on" N)
0
0
return unchanged
{ anim = Set nstat
, objState = Set "on"
, objPlayerActivated = Set False
}
return e return e
objectTransition ObjComputer "hack" _ ent = do objectTransition ObjComputer "on" _ ent = do
[e] <- efor (anEnt ent) $ do [e] <- efor (anEnt ent) $ do
let nstat = AnimState let nstat = AnimState
(AnimId "computer" "off" N) (AnimId "computer" "off" N)
@ -130,7 +185,22 @@ instance ObjectAction ObjType ObjState where
, objState = Set "off" , objState = Set "off"
, objPlayerActivated = Unset , objPlayerActivated = Unset
, objStateTime = Unset , objStateTime = Unset
, objSolved = Set (ost < 0) }
return e
objectTransition ObjComputer "hack" pa ent = do
[e] <- efor (anEnt ent) $ do
let nstat = AnimState
(AnimId "computer" "off" N)
0
0
ost <- query objStateTime
return unchanged
{ anim = Set nstat
, objState = Set "off"
, objPlayerActivated = Unset
, objStateTime = Unset
, objSolved = if pa then Set (ost < 0) else Keep
} }
return e return e
@ -139,6 +209,7 @@ instance ObjectAction ObjType ObjState where
instance ActionTime ObjType ObjState where instance ActionTime ObjType ObjState where
actionTime ObjCopier "copying" = 5 actionTime ObjCopier "copying" = 5
actionTime ObjComputer "off" = 0 actionTime ObjComputer "off" = 0
actionTime ObjComputer "on" = 20
actionTime ObjComputer "hack" = 20 actionTime ObjComputer "hack" = 20
actionTime o s = A.log Error (show o ++ ": " ++ s ++ ": has not time") 0 actionTime o s = A.log Error (show o ++ ": " ++ s ++ ": has not a time") 0