Continue work on terminals

This commit is contained in:
2025-08-18 20:38:01 +01:00
parent 1c9d58c716
commit e7b66b4fa4
9 changed files with 145 additions and 119 deletions
+23 -21
View File
@@ -9,7 +9,7 @@ module Dodge.Terminal (
-- commandsCommand,
connectionBlurbLines,
disconnectTerminal,
basicTerminal,
textTerminal,
simpleTermMessage,
damageCodeCommand,
sensorCommand,
@@ -25,6 +25,7 @@ module Dodge.Terminal (
--import Dodge.Data.WorldEffect
import qualified Data.Map.Strict as M
import Data.Char
import qualified Data.List as List
import Color
@@ -43,11 +44,10 @@ import LensHelp
--import ListHelp (safeHead, safeUncons)
import Sound.Data
basicTerminal :: Terminal
basicTerminal =
textTerminal :: Terminal
textTerminal =
defaultTerminal
{ _tmBootLines = connectionBlurb
, _tmDeathEffect = TmWdWdDoDeathTriggers
}
connectionBlurbLines :: [TerminalLine] -> [TerminalLine]
@@ -115,13 +115,15 @@ termTextColor :: Color
termTextColor = greyN 0.9
getCommands :: Terminal -> PTE.TrieMap Char (PTE.TrieMap Char [TerminalLine])
getCommands = foldMap getCommand . _tmCommands -- tm -- ++ _tmWriteCommands tm
getCommands tm = foldMap (getCommand tm) $ tm ^. tmCommands
getCommand :: TCom -> PTE.TrieMap Char (PTE.TrieMap Char [TerminalLine])
getCommand = \case
getCommand :: Terminal -> TCom -> PTE.TrieMap Char (PTE.TrieMap Char [TerminalLine])
getCommand tm = \case
TCInfo x z -> PTE.singleton x (PTE.singleton "" (makeTermPara z))
TCBase -> helpCommand <> quitCommand
TCDamageCommand -> damageCodeCommand
TCToggles -> toggleCommand tm
TCSensorInfo -> sensorCommand
damageCodeCommand :: PTE.TrieMap Char (PTE.TrieMap Char [TerminalLine])
damageCodeCommand = PTE.singleton "DAMAGECODE" $ PTE.fromList $ mapMaybe f [minBound..]
@@ -133,11 +135,22 @@ damageCodeCommand = PTE.singleton "DAMAGECODE" $ PTE.fromList $ mapMaybe f [minB
g = fmap (map toUpper) . fmap reverse . List.stripPrefix (reverse "Sensor")
. reverse . show
-- ugly, when changing check getSensorInfo
sensorCommand :: PTE.TrieMap Char (PTE.TrieMap Char [TerminalLine])
sensorCommand = PTE.singleton "SENSOR" mempty
sensorCommand = PTE.singleton "SENSOR" $ PTE.fromList
[("REQUIREMENT", [])
,("DISTANCE",[])
,("STATUS",[])
]
toggleCommand :: PTE.TrieMap Char (PTE.TrieMap Char [TerminalLine])
toggleCommand = PTE.singleton "TOGGLE" mempty
toggleCommand :: Terminal -> PTE.TrieMap Char (PTE.TrieMap Char [TerminalLine])
toggleCommand tm = PTE.singleton "TOGGLE" $ PTE.fromList $
M.toList $ fmap f $ tm ^. tmToggles
where
f x = [TLine 1
[TerminalLineConst "TOGGLE DONE!" termTextColor]
(TmWdWdfromWdWd (WdWdNegateTrig $ x ^. ttTriggerID))
]
helpCommand :: PTE.TrieMap Char (PTE.TrieMap Char [TerminalLine])
helpCommand = PTE.singleton "HELP" (fmap makeTermPara helpStrings)
@@ -247,17 +260,6 @@ tabComplete s' tm = case PTE.lookup s $ getCommands tm of
-- (makeTermPara . map toLower . show . f)
-- (w ^? cWorld . lWorld . machines . ix (_tmMachineID tm) . mcType . _McSensor)
--toggleCommand :: TerminalCommand
--toggleCommand =
-- TerminalCommand
-- { _tcString = "TOGGLE"
-- , _tcAlias = ["TOG"]
-- , _tcHelp = "Performs a reversable effect."
-- , _tcEffect = TerminalCommandEffectLinkedObject -- \tm _ -> OneArgument "A LINKED OBJECT" (togglesToEffects tm)
-- }
--decodedtmap :: M.Map SensorType (PaletteColor, DecorationShape) -> M.Map String [TerminalLine]
--decodedtmap = M.mapKeys show . M.map ((: []) . makeTermLine . show)
--sensorCommand :: TerminalCommand
--sensorCommand =