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)
-> IO ()
loadFork ws win glc nvg future progress = do
let stateSteps = 36
let stateSteps = 37
increment = 1 / stateSteps
SDL.glMakeCurrent win glc
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
)
]
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, _) ->
( p + increment
, "Loading Animation \"computer: hack\""
@ -316,6 +325,7 @@ loadFork ws win glc nvg future progress = do
copierStand ++
copierCopy ++
computerOff ++
computerOn ++
computerHack ++
toiletFree ++
toiletOccupied

View file

@ -36,6 +36,41 @@ instance ObjectAction ObjType ObjState where
Just ttl -> return (ttl < 0)
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
[vel] <- efor allEnts $ do
with player
@ -104,21 +139,41 @@ instance ObjectAction ObjType ObjState where
objectTransition ObjComputer "off" pa ent = do
[e] <- efor (anEnt ent) $ do
solved <- queryMaybe objSolved
if pa && not (fromMaybe False solved)
then do
if pa
then if not (fromMaybe False solved)
then do
let nstat = AnimState
(AnimId "computer" "hack" N)
0
0
return unchanged
{ anim = Set nstat
, objState = Set "hack"
, objPlayerActivated = Set True
}
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" "hack" N)
(AnimId "computer" "on" N)
0
0
return unchanged
{ anim = Set nstat
, objState = Set "hack"
, objPlayerActivated = Set True
}
else return unchanged
{ anim = Set nstat
, objState = Set "on"
, objPlayerActivated = Set False
}
return e
objectTransition ObjComputer "hack" _ ent = do
objectTransition ObjComputer "on" _ ent = do
[e] <- efor (anEnt ent) $ do
let nstat = AnimState
(AnimId "computer" "off" N)
@ -130,7 +185,22 @@ instance ObjectAction ObjType ObjState where
, objState = Set "off"
, objPlayerActivated = 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
@ -139,6 +209,7 @@ instance ObjectAction ObjType ObjState where
instance ActionTime ObjType ObjState where
actionTime ObjCopier "copying" = 5
actionTime ObjComputer "off" = 0
actionTime ObjComputer "on" = 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