Work on terminals, add deactive data type status

This commit is contained in:
2025-08-19 13:48:54 +01:00
parent 2f4fcb42e5
commit b8581a7862
13 changed files with 331 additions and 269 deletions
+1 -1
View File
File diff suppressed because one or more lines are too long
+3 -3
View File
@@ -5,6 +5,7 @@
module Dodge.Data.Input where module Dodge.Data.Input where
import Dodge.Data.Terminal.Status
import Control.Lens import Control.Lens
import qualified Data.Map.Strict as M import qualified Data.Map.Strict as M
import Geometry.Data import Geometry.Data
@@ -28,9 +29,8 @@ data MouseContext
| OverCombCombine { _mcoCombCombine :: (Int,Int)} | OverCombCombine { _mcoCombCombine :: (Int,Int)}
| OverCombFilter | OverCombFilter
| OverCombEscape | OverCombEscape
| OverTerminalReturn {_mcoTermID :: Int} | OverTerminal {_mcoTermID :: Int, _mcoTermStatus :: TerminalStatus}
| OverTerminalContinue {_mcoTermID :: Int} | OutsideTerminal
| OverTerminalEscape
| MouseGameRotate | MouseGameRotate
deriving (Show) deriving (Show)
+2 -1
View File
@@ -89,7 +89,8 @@ data TCom = TCInfo String String -- this may not be necessary, to revisit
data TmWdWd data TmWdWd
= TmWdId = TmWdId
| TmWdWdDisconnectTerminal | TmWdWdPowerDownTerminal
| TmWdWdDeactivateTerminal
| TmWdWdfromWdWd WdWd | TmWdWdfromWdWd WdWd
| TmWdWdTermSound SoundID | TmWdWdTermSound SoundID
| TmWdWdDoDeathTriggers | TmWdWdDoDeathTriggers
+2 -1
View File
@@ -9,10 +9,11 @@ import Data.Aeson.TH
data TerminalStatus data TerminalStatus
= TerminalOff = TerminalOff
| TerminalDeactivated
| TerminalLineRead | TerminalLineRead
| TerminalTextInput {_tiText :: String} | TerminalTextInput {_tiText :: String}
| TerminalPressTo {_tptString :: String} | TerminalPressTo {_tptString :: String}
deriving (Eq) deriving (Eq,Show)
makeLenses ''TerminalStatus makeLenses ''TerminalStatus
deriveJSON defaultOptions ''TerminalStatus deriveJSON defaultOptions ''TerminalStatus
+1
View File
@@ -383,6 +383,7 @@ drawTerminalDisplay tid cfig w = fromMaybe mempty $ do
$ _tmDisplayedLines tm $ _tmDisplayedLines tm
displayTermInput tm = case _tmStatus tm of displayTermInput tm = case _tmStatus tm of
TerminalOff -> id TerminalOff -> id
TerminalDeactivated -> id
TerminalLineRead -> id TerminalLineRead -> id
TerminalTextInput s -> TerminalTextInput s ->
(++ [(getPromptTM ++ s ++ [cFilledRect], white)]) (++ [(getPromptTM ++ s ++ [cFilledRect], white)])
+26 -3
View File
@@ -1,3 +1,4 @@
{-# LANGUAGE LambdaCase #-}
module Dodge.Render.Picture ( module Dodge.Render.Picture (
fixedCoordPictures, fixedCoordPictures,
) where ) where
@@ -109,9 +110,8 @@ mouseCursorType u = case u ^. uvWorld . input . mouseContext of
OverCombFilter{} -> drawJumpDown 5 OverCombFilter{} -> drawJumpDown 5
OverCombCombine{} -> drawGapPlus 5 OverCombCombine{} -> drawGapPlus 5
OverCombEscape -> rotate (pi / 4) $ drawPlus 5 OverCombEscape -> rotate (pi / 4) $ drawPlus 5
OverTerminalContinue{} -> drawReturn 5 OverTerminal _ ts -> drawCursorByTerminalStatus ts
OverTerminalReturn{} -> drawReturn 5 OutsideTerminal -> rotate (pi / 4) $ drawPlus 5
OverTerminalEscape -> rotate (pi / 4) $ drawPlus 5
MouseGameRotate -> rotate a (drawVerticalDoubleArrow 5) MouseGameRotate -> rotate a (drawVerticalDoubleArrow 5)
where where
w = u ^. uvWorld w = u ^. uvWorld
@@ -122,6 +122,21 @@ mouseCursorType u = case u ^. uvWorld . input . mouseContext of
argV (w ^. cWorld . lWorld . lAimPos -.- cpos) argV (w ^. cWorld . lWorld . lAimPos -.- cpos)
- w ^. wCam . camRot - w ^. wCam . camRot
drawCursorByTerminalStatus :: TerminalStatus -> Picture
drawCursorByTerminalStatus = \case
TerminalPressTo "QUIT" -> drawQuitTerminal 5
TerminalPressTo _ -> drawArrowDown 5
TerminalTextInput "QUIT" -> drawQuitTerminal 5
TerminalTextInput{} -> drawReturn 5
_ -> drawEmptySet 5
drawQuitTerminal :: Float -> Picture
drawQuitTerminal x = fold
[ line [V2 x x, V2 (- x) (- x)]
, line [V2 x (-x), V2 (- x) x]
, polygonWire (square x)
]
drawEmptySet :: Float -> Picture drawEmptySet :: Float -> Picture
drawEmptySet x = drawEmptySet x =
fold fold
@@ -202,6 +217,14 @@ drawVerticalDoubleArrow x =
z = 1.5 * x z = 1.5 * x
w = 0.6 * x w = 0.6 * x
drawArrowDown :: Float -> Picture
drawArrowDown x =
line [V2 0 z, V2 0 (- z)]
<> line [V2 (- w) (w - z), V2 0 (- z), V2 w (w - z)]
where
z = 1 * x
w = 0.6 * x
drawDragDrop :: Float -> Picture drawDragDrop :: Float -> Picture
drawDragDrop x = drawDragDrop x =
line (fmap (+ V2 z (- x)) [V2 (- x) x, V2 0 x, V2 0 (- x)]) line (fmap (+ V2 z (- x)) [V2 (- x) x, V2 0 x, V2 0 (- x)])
+4 -1
View File
@@ -26,7 +26,7 @@ rezBox :: LightSource -> Room
rezBox ls = rezBox ls =
roomRect 40 60 1 1 roomRect 40 60 1 1
& rmPmnts .~ [sPS (V2 20 1) 0 $ PutLS ls & rmPmnts .~ [sPS (V2 20 1) 0 $ PutLS ls
, putMessageTerminal terminalColor (defaultTerminal & tmBootLines .~ (makeTermPara s) <> tlSetStatus (TerminalPressTo "QUIT") <> [TLine 1 [] TmWdWdDisconnectTerminal]) , putMessageTerminal terminalColor (defaultTerminal & tmBootLines .~ (makeTermPara s) <> tlSetStatus (TerminalPressTo "QUIT") <> [TLine 1 [] TmWdWdDeactivateTerminal])
& plSpot .~ PS (V2 20 0) 0 & plSpot .~ PS (V2 20 0) 0
] ]
& restrictInLinks (\(V2 _ h, _) -> h < 1) & restrictInLinks (\(V2 _ h, _) -> h < 1)
@@ -35,6 +35,9 @@ rezBox ls =
where where
s = "RESPAWN POINT SET AT THIS LOCATION." s = "RESPAWN POINT SET AT THIS LOCATION."
tutorialMessage1 :: String
tutorialMessage1 = "SYNTHESIS SUCCESSFUL. MOVEMENT TEST 1 INITIATED [WASD]. INTERACTION TEST 1 IN QUEUE [SPACE]."
rezBox' :: RandomGen g => State g (MetaTree Room String) rezBox' :: RandomGen g => State g (MetaTree Room String)
rezBox' = do rezBox' = do
col <- rezColor col <- rezColor
+31 -14
View File
@@ -3,7 +3,8 @@
module Dodge.Terminal ( module Dodge.Terminal (
makeTermLine, makeTermLine,
connectionBlurbLines, connectionBlurbLines,
disconnectTerminal, powerDownTerminal,
deactivateTerminal,
textTerminal, textTerminal,
simpleTermMessage, simpleTermMessage,
damageCodeCommand, damageCodeCommand,
@@ -21,11 +22,11 @@ module Dodge.Terminal (
--import Dodge.Data.WorldEffect --import Dodge.Data.WorldEffect
import qualified Data.Map.Strict as M import Color
import Data.Char import Data.Char
import qualified Data.List as List import qualified Data.List as List
import Color
import qualified Data.ListTrie.Patricia.Map.Enum as PTE import qualified Data.ListTrie.Patricia.Map.Enum as PTE
import qualified Data.Map.Strict as M
--import Control.Monad --import Control.Monad
--import Data.Char --import Data.Char
--import qualified Data.Map.Strict as M --import qualified Data.Map.Strict as M
@@ -128,22 +129,30 @@ damageCodeCommand = PTE.singleton "DAMAGECODE" $ PTE.fromList $ mapMaybe f [minB
f st = do f st = do
s <- g st s <- g st
return (s, [TLine 0 [] $ TmGetDamageCoding st]) return (s, [TLine 0 [] $ TmGetDamageCoding st])
g = fmap (map toUpper) . fmap reverse . List.stripPrefix (reverse "Sensor") g =
. reverse . show fmap (map toUpper) . fmap reverse . List.stripPrefix (reverse "Sensor")
. reverse
. show
-- ugly, when changing check getSensorInfo -- ugly, when changing check getSensorInfo
sensorCommand :: PTE.TrieMap Char (PTE.TrieMap Char [TerminalLine]) sensorCommand :: PTE.TrieMap Char (PTE.TrieMap Char [TerminalLine])
sensorCommand = PTE.singleton "SENSOR" $ PTE.fromList sensorCommand =
PTE.singleton "SENSOR" $
PTE.fromList
[ ("REQUIREMENT", []) [ ("REQUIREMENT", [])
, ("DISTANCE", []) , ("DISTANCE", [])
, ("STATUS", []) , ("STATUS", [])
] ]
toggleCommand :: Terminal -> PTE.TrieMap Char (PTE.TrieMap Char [TerminalLine]) toggleCommand :: Terminal -> PTE.TrieMap Char (PTE.TrieMap Char [TerminalLine])
toggleCommand tm = PTE.singleton "TOGGLE" $ PTE.fromList $ toggleCommand tm =
PTE.singleton "TOGGLE" $
PTE.fromList $
M.toList $ fmap f $ tm ^. tmToggles M.toList $ fmap f $ tm ^. tmToggles
where where
f x = [TLine 1 f x =
[ TLine
1
[TerminalLineConst "TOGGLE DONE!" termTextColor] [TerminalLineConst "TOGGLE DONE!" termTextColor]
(TmWdWdfromWdWd (WdWdNegateTrig $ x ^. ttTriggerID)) (TmWdWdfromWdWd (WdWdNegateTrig $ x ^. ttTriggerID))
] ]
@@ -158,7 +167,7 @@ helpStrings =
] ]
quitCommand :: PTE.TrieMap Char (PTE.TrieMap Char [TerminalLine]) quitCommand :: PTE.TrieMap Char (PTE.TrieMap Char [TerminalLine])
quitCommand = PTE.singleton "QUIT" (PTE.singleton "" [TLine 0 [] TmWdWdDisconnectTerminal]) quitCommand = PTE.singleton "QUIT" (PTE.singleton "" [TLine 0 [] TmWdWdPowerDownTerminal])
makeTermLine :: String -> TerminalLine makeTermLine :: String -> TerminalLine
makeTermLine = makeColorTermLine termTextColor makeTermLine = makeColorTermLine termTextColor
@@ -195,7 +204,9 @@ tabComplete s' tm = case PTE.lookup s $ getCommands tm of
& tmFutureLines & tmFutureLines
.~ ( makeColorTermPara .~ ( makeColorTermPara
commandColor commandColor
(unwords xs) <> [TLine 1 [] . TmTmSetStatus $ TerminalTextInput s]) (unwords xs)
<> [TLine 1 [] . TmTmSetStatus $ TerminalTextInput s]
)
--doTerminalCommandEffect :: TerminalCommandEffect -> Terminal -> World -> EffectArguments --doTerminalCommandEffect :: TerminalCommandEffect -> Terminal -> World -> EffectArguments
--doTerminalCommandEffect tce = case tce of --doTerminalCommandEffect tce = case tce of
@@ -258,7 +269,6 @@ tabComplete s' tm = case PTE.lookup s $ getCommands tm of
-- (makeTermPara . map toLower . show . f) -- (makeTermPara . map toLower . show . f)
-- (w ^? cWorld . lWorld . machines . ix (_tmMachineID tm) . mcType . _McSensor) -- (w ^? cWorld . lWorld . machines . ix (_tmMachineID tm) . mcType . _McSensor)
--sensorCommand :: TerminalCommand --sensorCommand :: TerminalCommand
--sensorCommand = --sensorCommand =
-- TerminalCommand -- TerminalCommand
@@ -268,12 +278,19 @@ tabComplete s' tm = case PTE.lookup s $ getCommands tm of
-- , _tcEffect = TerminalCommandEffectSensorParameter -- \tm -> OneArgument "A SENSOR PARAMETER" . sensorInfoMap tm -- , _tcEffect = TerminalCommandEffectSensorParameter -- \tm -> OneArgument "A SENSOR PARAMETER" . sensorInfoMap tm
-- } -- }
disconnectTerminal :: Terminal -> World -> World powerDownTerminal :: Terminal -> World -> World
disconnectTerminal tm = powerDownTerminal tm =
(cWorld . lWorld . terminals . ix (_tmID tm) . tmStatus .~ TerminalOff) (cWorld . lWorld . terminals . ix (_tmID tm) . tmStatus .~ TerminalOff)
. exitTerminalSubInv
. ( cWorld . lWorld . terminals . ix (_tmID tm) . tmDisplayedLines .~ [] . ( cWorld . lWorld . terminals . ix (_tmID tm) . tmDisplayedLines .~ []
) )
. exitTerminalSubInv
deactivateTerminal :: Terminal -> World -> World
deactivateTerminal tm =
(cWorld . lWorld . terminals . ix (_tmID tm) . tmStatus .~ TerminalOff)
. ( cWorld . lWorld . terminals . ix (_tmID tm) . tmDisplayedLines .~ []
)
. exitTerminalSubInv
exitTerminalSubInv :: World -> World exitTerminalSubInv :: World -> World
exitTerminalSubInv w = case w ^? hud . hudElement . subInventory . termID of exitTerminalSubInv w = case w ^? hud . hudElement . subInventory . termID of
+1
View File
@@ -10,6 +10,7 @@ import Control.Lens
termScreenColor :: Terminal -> Maybe Color termScreenColor :: Terminal -> Maybe Color
termScreenColor tm = case tm ^. tmStatus of termScreenColor tm = case tm ^. tmStatus of
TerminalOff -> Nothing TerminalOff -> Nothing
TerminalDeactivated -> Nothing
TerminalTextInput _ -> Just green TerminalTextInput _ -> Just green
TerminalPressTo{} -> Just green TerminalPressTo{} -> Just green
TerminalLineRead -> Just white TerminalLineRead -> Just white
+2 -5
View File
@@ -397,11 +397,8 @@ updateMouseContextGame cfig u = case u ^. uvWorld . input . mouseContext of
tm <- w ^? cWorld . lWorld . terminals . ix tmid tm <- w ^? cWorld . lWorld . terminals . ix tmid
return $ return $
if isOverTerminalScreen cfig mpos if isOverTerminalScreen cfig mpos
then fromMaybe NoMouseContext $ do then OverTerminal tmid (tm ^. tmStatus)
let s = tm ^. tmStatus . tiText else OutsideTerminal
guard $ not (null s) -- && _tmStatus tm == TerminalTextInput
return $ OverTerminalReturn tmid
else OverTerminalEscape
getMenuMouseContext :: ScreenLayer -> Universe -> MouseContext getMenuMouseContext :: ScreenLayer -> Universe -> MouseContext
getMenuMouseContext screen u = case screen ^. scOptions of getMenuMouseContext screen u = case screen ^. scOptions of
+9 -4
View File
@@ -218,9 +218,9 @@ updateMouseClickInGame cfig w = case w ^. input . mouseContext of
&& isGroupSelectableSection (fst x) -> && isGroupSelectableSection (fst x) ->
w & input . mouseContext .~ OverInvDragSelect x (Just $ snd x) w & input . mouseContext .~ OverInvDragSelect x (Just $ snd x)
OverInvSelect x -> startDrag x cfig w OverInvSelect x -> startDrag x cfig w
OverTerminalReturn tmid -> terminalReturnEffect tmid w OverTerminal tmid (TerminalTextInput {}) -> terminalReturnEffect tmid w
OverTerminalContinue tmid -> undefined OverTerminal tmid (TerminalPressTo{}) -> continueTerminal tmid w
OverTerminalEscape -> w & hud . hudElement . subInventory .~ NoSubInventory OutsideTerminal -> w & hud . hudElement . subInventory .~ NoSubInventory
OverCombSelect x -> OverCombSelect x ->
w & hud . hudElement . subInventory . ciSelection ?~ f x w & hud . hudElement . subInventory . ciSelection ?~ f x
& worldEventFlags . at CombineInventoryChange ?~ () & worldEventFlags . at CombineInventoryChange ?~ ()
@@ -388,11 +388,16 @@ updateKeysInTerminal tmid u = fromMaybe u $ do
TerminalTextInput{} -> updateKeysTextInputTerminal tmid u TerminalTextInput{} -> updateKeysTextInputTerminal tmid u
TerminalPressTo{} -> updateKeyContinueTerminal tmid u TerminalPressTo{} -> updateKeyContinueTerminal tmid u
_ -> u _ -> u
updateKeyContinueTerminal :: Int -> Universe -> Universe updateKeyContinueTerminal :: Int -> Universe -> Universe
updateKeyContinueTerminal tmid u updateKeyContinueTerminal tmid u
| any (==0) $ u ^. uvWorld . input . pressedKeys = | any (==0) $ u ^. uvWorld . input . pressedKeys =
u & uvWorld . cWorld . lWorld . terminals . ix tmid . tmStatus .~ TerminalLineRead u & uvWorld %~ continueTerminal tmid
| otherwise = u | otherwise = u
continueTerminal :: Int -> World -> World
continueTerminal tmid = cWorld . lWorld . terminals . ix tmid . tmStatus .~ TerminalLineRead
updateKeysTextInputTerminal :: Int -> Universe -> Universe updateKeysTextInputTerminal :: Int -> Universe -> Universe
updateKeysTextInputTerminal tmid u = updateKeysTextInputTerminal tmid u =
u u
+3 -1
View File
@@ -66,6 +66,7 @@ accessTerminal mtmid w = fromMaybe w $ do
tm tm
& tmFutureLines .~ _tmBootLines tm & tmFutureLines .~ _tmBootLines tm
& tmStatus .~ TerminalLineRead & tmStatus .~ TerminalLineRead
TerminalDeactivated -> error "managed to boot a deactivated terminal"
torqueCr :: Float -> Int -> World -> World torqueCr :: Float -> Int -> World -> World
torqueCr x cid w torqueCr x cid w
@@ -116,7 +117,8 @@ doTmWdWd tmwdwd = case tmwdwd of
-- tid <- tm ^? tmID -- tid <- tm ^? tmID
-- return $ cWorld . lWorld . terminals . ix tid . tmPartialCommand .~ x -- return $ cWorld . lWorld . terminals . ix tid . tmPartialCommand .~ x
TmWdId -> const id TmWdId -> const id
TmWdWdDisconnectTerminal -> disconnectTerminal TmWdWdPowerDownTerminal -> powerDownTerminal
TmWdWdDeactivateTerminal -> deactivateTerminal
TmWdWdTermSound sid -> \tm w -> TmWdWdTermSound sid -> \tm w ->
let tpos = fromMaybe 0 $ w ^? cWorld . lWorld . buttons . ix (_tmButtonID tm) . btPos let tpos = fromMaybe 0 $ w ^? cWorld . lWorld . buttons . ix (_tmButtonID tm) . btPos
in soundStart TerminalSound tpos sid Nothing w in soundStart TerminalSound tpos sid Nothing w
+235 -224
View File
File diff suppressed because it is too large Load Diff