Cleanup, fix damage code terminal bug

This commit is contained in:
2025-08-20 15:59:22 +01:00
parent 9daa27ee8b
commit 4bf9ce59d5
12 changed files with 153 additions and 177 deletions
+28 -20
View File
@@ -52,38 +52,46 @@ termSoundLine sid = TLine 0 [] (TmWdWdTermSound sid)
termTextColor :: Color
termTextColor = greyN 0.9
getCommands :: Terminal -> PTE.TrieMap Char (PTE.TrieMap Char [TerminalLine])
getCommands tm = foldMap (getCommand tm) $ tm ^. tmCommands
getCommands :: World -> Terminal -> PTE.TrieMap Char (PTE.TrieMap Char [TerminalLine])
getCommands w tm = foldMap (getCommand w tm) $ tm ^. tmCommands
getCommand :: Terminal -> TCom -> PTE.TrieMap Char (PTE.TrieMap Char [TerminalLine])
getCommand tm = \case
getCommand :: World
-> Terminal -> TCom -> PTE.TrieMap Char (PTE.TrieMap Char [TerminalLine])
getCommand w tm = \case
TCInfo x z -> PTE.singleton x (PTE.singleton "" (makeTermPara z))
TCBase -> helpCommand <> quitCommand
TCDamageCommand -> damageCodeCommand
TCDamageCommand -> damageCodeCommand w
TCToggles -> toggleCommand tm
TCSensorInfo -> sensorCommand
TCSensorInfo -> sensorCommand w tm
damageCodeCommand :: PTE.TrieMap Char (PTE.TrieMap Char [TerminalLine])
damageCodeCommand = PTE.singleton "DAMAGECODE" $ PTE.fromList $ mapMaybe f [minBound ..]
damageCodeCommand :: World -> PTE.TrieMap Char (PTE.TrieMap Char [TerminalLine])
damageCodeCommand w = PTE.singleton "DAMAGECODE" $ PTE.fromList $ mapMaybe f [minBound ..]
where
f :: SensorType -> Maybe (String, [TerminalLine])
f st = do
s <- g st
return (s, [TLine 0 [] $ TmGetDamageCoding st])
return (s, decodeSensorType st w)
g =
fmap (map toUpper . reverse) . List.stripPrefix (reverse "Sensor")
. reverse
. show
decodeSensorType :: SensorType -> World -> [TerminalLine]
decodeSensorType st w = fromMaybe [] $ do
x <- w ^? cWorld . cwGen . cwgParams . sensorCoding . ix st
return [makeTermLine $ show x]
-- ugly, when changing check getSensorInfo
sensorCommand :: PTE.TrieMap Char (PTE.TrieMap Char [TerminalLine])
sensorCommand =
PTE.singleton "SENSOR" $
PTE.fromList
[ ("REQUIREMENT", [])
, ("DISTANCE", [])
, ("STATUS", [])
sensorCommand :: World -> Terminal -> PTE.TrieMap Char (PTE.TrieMap Char [TerminalLine])
sensorCommand w tm = PTE.singleton "SENSOR" $ fromMaybe mempty $ do
ProximitySensor _ d r b <- w ^? cWorld . lWorld . machines . ix (tm ^. tmMachineID) . mcType . _McSensor
return $ PTE.fromList
[ ("REQUIREMENT", [makeTermLine $ show r] )
, ("RADIUS", [makeTermLine $ show d])
, ("STATUS", [makeTermLine $ show b])
]
toggleCommand :: Terminal -> PTE.TrieMap Char (PTE.TrieMap Char [TerminalLine])
toggleCommand tm =
@@ -132,10 +140,10 @@ commandColor :: Color
commandColor = yellow
-- ugly
tabComplete :: String -> Terminal -> Terminal
tabComplete s' tm = case PTE.lookup s $ getCommands tm of
tabComplete :: String -> World -> Terminal -> Terminal
tabComplete s' w tm = case PTE.lookup s $ getCommands w tm of
Just m -> f (s ++ " ") $ PTE.toList $ PTE.lookupPrefix a m
Nothing -> f "" $ PTE.toList $ PTE.lookupPrefix s $ getCommands tm
Nothing -> f "" $ PTE.toList $ PTE.lookupPrefix s $ getCommands w tm
where
ss = words s'
s = fromMaybe "" $ ss ^? ix 0
@@ -183,7 +191,7 @@ terminalReturnEffect tmid w = fromMaybe w $ do
let ss = fromMaybe [makeTermLine "ERROR: INPUT NOT RECOGNISED"] $ do
let args = words s
x <- args ^? ix 0
teff <- PTE.lookup x (getCommands tm)
teff <- PTE.lookup x (getCommands w tm)
let y = fromMaybe "" (args ^? ix 1)
PTE.lookup y teff
return $ w