Partially successful change of terminals to external entities
This commit is contained in:
@@ -15,8 +15,8 @@ import qualified Data.Set as S
|
|||||||
import Data.Maybe
|
import Data.Maybe
|
||||||
{- | The AI equivalent for your control. -}
|
{- | The AI equivalent for your control. -}
|
||||||
yourControl :: Creature -> World -> World
|
yourControl :: Creature -> World -> World
|
||||||
yourControl cr w = case w ^? hud . hudElement . subInventory . termParams . termInput . _Just of
|
yourControl cr w = case w ^? hud . hudElement . subInventory . onInputLine of
|
||||||
Just _ -> w
|
Just True -> w
|
||||||
_ -> w
|
_ -> w
|
||||||
& creatures . ix (_crID cr) %~
|
& creatures . ix (_crID cr) %~
|
||||||
(wasdWithAiming w (_mvSpeed $ _crMvType cr) . mouseActionsCr (_mouseButtons w))
|
(wasdWithAiming w (_mvSpeed $ _crMvType cr) . mouseActionsCr (_mouseButtons w))
|
||||||
|
|||||||
+8
-19
@@ -203,8 +203,8 @@ data SubInventory
|
|||||||
| InspectInventory
|
| InspectInventory
|
||||||
| LockedInventory
|
| LockedInventory
|
||||||
| DisplayTerminal
|
| DisplayTerminal
|
||||||
{_termParams :: TerminalParams
|
{_termID :: Int
|
||||||
,_termID :: Int
|
,_onInputLine :: Bool
|
||||||
}
|
}
|
||||||
-- deriving (Eq,Ord,Show)
|
-- deriving (Eq,Ord,Show)
|
||||||
|
|
||||||
@@ -408,18 +408,6 @@ data Button = Button
|
|||||||
, _btTermMID :: Maybe Int
|
, _btTermMID :: Maybe Int
|
||||||
, _btName :: String
|
, _btName :: String
|
||||||
}
|
}
|
||||||
data TerminalParams = NoTerminalParams | TerminalParams
|
|
||||||
{ _termDisplayedLines :: [World -> (String,Color)]
|
|
||||||
, _termFutureLines :: [TerminalLine]
|
|
||||||
, _termMaxLines :: Int
|
|
||||||
, _termTitle :: String
|
|
||||||
, _termSel :: Maybe (Int,Int)
|
|
||||||
-- , _termOptions :: [(String, World -> World)]
|
|
||||||
, _termInput :: Maybe T.Text
|
|
||||||
, _termScrollCommands :: [TerminalCommand]
|
|
||||||
, _termWriteCommands :: [TerminalCommand]
|
|
||||||
, _termDeathCommand :: Maybe String
|
|
||||||
}
|
|
||||||
data TerminalLine
|
data TerminalLine
|
||||||
= TerminalLineDisplay
|
= TerminalLineDisplay
|
||||||
{_tlPause :: Int
|
{_tlPause :: Int
|
||||||
@@ -432,7 +420,7 @@ data TerminalLine
|
|||||||
}
|
}
|
||||||
| TerminalLineEffect
|
| TerminalLineEffect
|
||||||
{_tlPause :: Int
|
{_tlPause :: Int
|
||||||
,_tlEffect :: SubInventory -> World -> World
|
,_tlEffect :: Terminal -> World -> World
|
||||||
}
|
}
|
||||||
data ButtonState = BtOn | BtOff | BtNoLabel
|
data ButtonState = BtOn | BtOff | BtNoLabel
|
||||||
deriving (Eq, Show)
|
deriving (Eq, Show)
|
||||||
@@ -948,9 +936,10 @@ data Block = Block
|
|||||||
, _blMaterial :: BlockMaterial
|
, _blMaterial :: BlockMaterial
|
||||||
}
|
}
|
||||||
data BlockMaterial = WoodBlock | DirtBlock | StoneBlock | GlassBlock | MetalBlock
|
data BlockMaterial = WoodBlock | DirtBlock | StoneBlock | GlassBlock | MetalBlock
|
||||||
|
data TerminalStatus = Connected | Disconnected
|
||||||
data Terminal = Terminal
|
data Terminal = Terminal
|
||||||
{ _tmID :: Int
|
{ _tmID :: Int
|
||||||
, _tmProgram :: Terminal -> World -> TerminalParams
|
, _tmProgram :: Terminal -> World -> [TerminalLine]
|
||||||
, _tmButtonID :: Int
|
, _tmButtonID :: Int
|
||||||
, _tmMachineID :: Int
|
, _tmMachineID :: Int
|
||||||
, _tmName :: String
|
, _tmName :: String
|
||||||
@@ -963,6 +952,7 @@ data Terminal = Terminal
|
|||||||
, _tmScrollCommands :: [TerminalCommand]
|
, _tmScrollCommands :: [TerminalCommand]
|
||||||
, _tmWriteCommands :: [TerminalCommand]
|
, _tmWriteCommands :: [TerminalCommand]
|
||||||
, _tmDeathEffect :: Terminal -> World -> World
|
, _tmDeathEffect :: Terminal -> World -> World
|
||||||
|
, _tmStatus :: TerminalStatus
|
||||||
}
|
}
|
||||||
data Machine = Machine
|
data Machine = Machine
|
||||||
{ _mcID :: Int
|
{ _mcID :: Int
|
||||||
@@ -1384,8 +1374,8 @@ data TerminalCommand = TerminalCommand
|
|||||||
, _tcAlias :: [String]
|
, _tcAlias :: [String]
|
||||||
, _tcHelp :: String
|
, _tcHelp :: String
|
||||||
, _tcArgumentType :: Maybe String
|
, _tcArgumentType :: Maybe String
|
||||||
, _tcArguments :: World -> [String]
|
, _tcArguments :: Terminal -> World -> [String]
|
||||||
, _tcEffect :: [String] -> World -> Either String World
|
, _tcEffect :: [String] -> Terminal -> World -> Either String World
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1601,7 +1591,6 @@ makeLenses ''Nozzle
|
|||||||
makeLenses ''HUD
|
makeLenses ''HUD
|
||||||
makeLenses ''HUDElement
|
makeLenses ''HUDElement
|
||||||
makeLenses ''SubInventory
|
makeLenses ''SubInventory
|
||||||
makeLenses ''TerminalParams
|
|
||||||
makeLenses ''TerminalLine
|
makeLenses ''TerminalLine
|
||||||
makeLenses ''ItemValue
|
makeLenses ''ItemValue
|
||||||
makeLenses ''Equipment
|
makeLenses ''Equipment
|
||||||
|
|||||||
@@ -244,7 +244,7 @@ defaultDrawButton col bt =
|
|||||||
defaultTerminal :: Terminal
|
defaultTerminal :: Terminal
|
||||||
defaultTerminal = Terminal
|
defaultTerminal = Terminal
|
||||||
{ _tmID = 0
|
{ _tmID = 0
|
||||||
, _tmProgram = (\_ _ -> NoTerminalParams)
|
, _tmProgram = (\_ _ -> [])
|
||||||
, _tmButtonID = 0
|
, _tmButtonID = 0
|
||||||
, _tmMachineID = 0
|
, _tmMachineID = 0
|
||||||
, _tmName = "TESTTERMINAL"
|
, _tmName = "TESTTERMINAL"
|
||||||
@@ -257,6 +257,7 @@ defaultTerminal = Terminal
|
|||||||
, _tmScrollCommands = []
|
, _tmScrollCommands = []
|
||||||
, _tmWriteCommands = []
|
, _tmWriteCommands = []
|
||||||
, _tmDeathEffect = const id
|
, _tmDeathEffect = const id
|
||||||
|
, _tmStatus = Disconnected
|
||||||
}
|
}
|
||||||
|
|
||||||
defaultButton :: Button
|
defaultButton :: Button
|
||||||
|
|||||||
+24
-24
@@ -94,8 +94,8 @@ handlePressedMouseButton :: MouseButton -> Universe -> Maybe Universe
|
|||||||
handlePressedMouseButton but w = case (_hudElement (_hud $ _uvWorld w), but) of
|
handlePressedMouseButton but w = case (_hudElement (_hud $ _uvWorld w), but) of
|
||||||
(DisplayCarte,_) -> Just $ w & uvWorld . clickMousePos .~ _mousePos (_uvWorld w)
|
(DisplayCarte,_) -> Just $ w & uvWorld . clickMousePos .~ _mousePos (_uvWorld w)
|
||||||
(_,ButtonMiddle) -> Just $ w & uvWorld . clickMousePos .~ _mousePos (_uvWorld w)
|
(_,ButtonMiddle) -> Just $ w & uvWorld . clickMousePos .~ _mousePos (_uvWorld w)
|
||||||
( DisplayInventory (DisplayTerminal _ _) , ButtonLeft)
|
( DisplayInventory (DisplayTerminal tmid _) , ButtonLeft)
|
||||||
-> Just $ over uvWorld doTerminalEffect w
|
-> Just $ over uvWorld (doTerminalEffect (w ^?! uvWorld . terminals . ix tmid)) w
|
||||||
( DisplayInventory (CombineInventory mi) , ButtonLeft)
|
( DisplayInventory (CombineInventory mi) , ButtonLeft)
|
||||||
-> Just $ fromMaybe (w & uvWorld . hud . hudElement .~ DisplayInventory NoSubInventory)
|
-> Just $ fromMaybe (w & uvWorld . hud . hudElement .~ DisplayInventory NoSubInventory)
|
||||||
$ do -- ugly
|
$ do -- ugly
|
||||||
@@ -144,30 +144,30 @@ wheelEvent y w = case _hudElement $ _hud w of
|
|||||||
| otherwise -> w & moveTweakSel yi
|
| otherwise -> w & moveTweakSel yi
|
||||||
DisplayInventory (CombineInventory _) -> w
|
DisplayInventory (CombineInventory _) -> w
|
||||||
& hud . hudElement . subInventory . combineInvSel . _Just %~ ((`mod` numcombs) . subtract yi)
|
& hud . hudElement . subInventory . combineInvSel . _Just %~ ((`mod` numcombs) . subtract yi)
|
||||||
DisplayInventory DisplayTerminal{}
|
-- DisplayInventory (DisplayTerminal tmid True)
|
||||||
| rbDown -> w
|
-- | rbDown -> w
|
||||||
& hud . hudElement . subInventory . termParams %~ updatetermsubsel
|
-- & terminals . ix tmid %~ updatetermsubsel
|
||||||
| otherwise -> w
|
-- | otherwise -> w
|
||||||
& hud . hudElement . subInventory . termParams %~ updatetermsel
|
-- & terminals . ix tmid %~ updatetermsel
|
||||||
_ -> w
|
_ -> w
|
||||||
where
|
where
|
||||||
updatetermsel tp = case _termSel tp of
|
-- updatetermsel tp = case _tmSel tp of
|
||||||
Nothing -> tp & termSel ?~ (0,0)
|
-- Nothing -> tp & tmSel ?~ (0,0)
|
||||||
& termInput . _Just %~ replacewith tp 0
|
-- & tmInput . _Just %~ replacewith tp 0
|
||||||
Just (i,_) -> let newi = ((`mod` length (_termScrollCommands tp)) . subtract yi) i
|
-- Just (i,_) -> let newi = ((`mod` length (_tmScrollCommands tp)) . subtract yi) i
|
||||||
in tp & termSel . _Just .~ (newi,0)
|
-- in tp & tmSel . _Just .~ (newi,0)
|
||||||
& termInput . _Just %~ replacewith tp newi
|
-- & tmInput . _Just %~ replacewith tp newi
|
||||||
updatetermsubsel tp = case _termSel tp of
|
-- updatetermsubsel tp = case _tmSel tp of
|
||||||
Nothing -> tp
|
-- Nothing -> tp
|
||||||
Just (i,j) -> let newj = (j - yi) `mod` (1 + length (_tcArguments (_termScrollCommands tp !! i) w))
|
-- Just (i,j) -> let newj = (j - yi) `mod` (1 + length (_tcArguments (_tmScrollCommands tp !! i) tp w))
|
||||||
in tp & termSel . _Just .~ (i,newj)
|
-- in tp & tmSel . _Just .~ (i,newj)
|
||||||
& termInput . _Just %~ replacewith' tp i newj w
|
-- & tmInput . _Just %~ replacewith' tp i newj w
|
||||||
replacewith tp newi _ = T.pack (_tcString (_termScrollCommands tp !! newi))
|
-- replacewith tp newi _ = T.pack (_tcString (_tmScrollCommands tp !! newi))
|
||||||
replacewith' tp i j w' _ = T.pack $ _tcString tc ++ " " ++ arg-- ++ ((_tcArguments tp) w !! j)
|
-- replacewith' tp i j w' _ = T.pack $ _tcString tc ++ " " ++ arg-- ++ ((_tcArguments tp) w !! j)
|
||||||
where
|
-- where
|
||||||
arg :: String
|
-- arg :: String
|
||||||
arg = ("": _tcArguments tc w' )!! j
|
-- arg = ("": _tcArguments tc w' )!! j
|
||||||
tc = _termScrollCommands tp !! i
|
-- tc = _tmScrollCommands tp !! i
|
||||||
numcombs = length $ combineItemListYou w
|
numcombs = length $ combineItemListYou w
|
||||||
yi = round $ signum y
|
yi = round $ signum y
|
||||||
numLocs = (fst . IM.findMax $ _seenLocations w) + 1
|
numLocs = (fst . IM.findMax $ _seenLocations w) + 1
|
||||||
|
|||||||
@@ -30,9 +30,13 @@ import qualified Data.Text as T
|
|||||||
-- also, note that this currently "doubles" the inputs to both terminals if both
|
-- also, note that this currently "doubles" the inputs to both terminals if both
|
||||||
-- are open
|
-- are open
|
||||||
handleTextInput :: T.Text -> Universe -> IO (Maybe Universe)
|
handleTextInput :: T.Text -> Universe -> IO (Maybe Universe)
|
||||||
handleTextInput text = return . Just . (menuLayers . ix 0 . scInput %~ updateText)
|
handleTextInput text u = return . Just $ u
|
||||||
. (uvWorld . hud . hudElement . subInventory . termParams . termInput . _Just %~ updateText)
|
& menuLayers . ix 0 . scInput %~ updateText
|
||||||
|
& updateTerminalText
|
||||||
where
|
where
|
||||||
|
updateTerminalText = case u ^? uvWorld . hud . hudElement . subInventory of
|
||||||
|
Just (DisplayTerminal tmid True) -> uvWorld . terminals . ix tmid . tmInput . _Just %~ updateText
|
||||||
|
_ -> id
|
||||||
updateText s = case T.unpack text of
|
updateText s = case T.unpack text of
|
||||||
";" -> s
|
";" -> s
|
||||||
_ -> s `T.append` T.toUpper text
|
_ -> s `T.append` T.toUpper text
|
||||||
@@ -60,8 +64,8 @@ handlePressedKey _ scode u = case scode of
|
|||||||
ScancodeF5 -> return . Just $ doQuicksave u
|
ScancodeF5 -> return . Just $ doQuicksave u
|
||||||
ScancodeF9 -> return . Just $ loadSaveSlot QuicksaveSlot u
|
ScancodeF9 -> return . Just $ loadSaveSlot QuicksaveSlot u
|
||||||
ScancodeSemicolon -> return . Just $ gotoTerminal u
|
ScancodeSemicolon -> return . Just $ gotoTerminal u
|
||||||
_ | null (_menuLayers u) -> case u ^? uvWorld . hud . hudElement . subInventory . termParams . termInput . _Just of
|
_ | null (_menuLayers u) -> case u ^? uvWorld . hud . hudElement . subInventory of
|
||||||
Just {} -> return $ uvWorld (handlePressedKeyTerminal scode) u
|
Just (DisplayTerminal tmid True) -> return $ uvWorld (handlePressedKeyTerminal tmid scode) u
|
||||||
_ -> return $ uvWorld (Just . handlePressedKeyInGame scode) u
|
_ -> return $ uvWorld (Just . handlePressedKeyInGame scode) u
|
||||||
_ -> handlePressedKeyInMenu (head $ _menuLayers u) scode u
|
_ -> handlePressedKeyInMenu (head $ _menuLayers u) scode u
|
||||||
|
|
||||||
@@ -80,12 +84,12 @@ handlePressedKeyInGame scode w = case scode of
|
|||||||
_ -> w
|
_ -> w
|
||||||
|
|
||||||
|
|
||||||
handlePressedKeyTerminal :: Scancode -> World -> Maybe World
|
handlePressedKeyTerminal :: Int -> Scancode -> World -> Maybe World
|
||||||
handlePressedKeyTerminal scode w = case scode of
|
handlePressedKeyTerminal tmid scode w = case scode of
|
||||||
ScancodeEscape -> Just $ w & hud . hudElement . subInventory .~ NoSubInventory
|
ScancodeEscape -> Just $ w & hud . hudElement . subInventory . onInputLine .~ False
|
||||||
ScancodeReturn -> Just $ w & doTerminalEffect
|
ScancodeReturn -> Just $ w & doTerminalEffect (w ^?! terminals . ix tmid)
|
||||||
ScancodeBackspace -> Just $ w
|
ScancodeBackspace -> Just $ w
|
||||||
& hud . hudElement . subInventory . termParams . termInput . _Just %~ doBackspace
|
& terminals . ix tmid . tmInput . _Just %~ doBackspace
|
||||||
& backspaceTimer .~ 5
|
& backspaceTimer .~ 5
|
||||||
_ -> Just w
|
_ -> Just w
|
||||||
where
|
where
|
||||||
|
|||||||
+1
-20
@@ -146,7 +146,7 @@ invSelPos w = splitgap + (foldl' (+) 0 . fst $ IM.split invsel (augmentedInvSize
|
|||||||
| otherwise = 1
|
| otherwise = 1
|
||||||
|
|
||||||
updateTerminal :: World -> World
|
updateTerminal :: World -> World
|
||||||
updateTerminal = checkTermDist . updateTerminalLine
|
updateTerminal = checkTermDist
|
||||||
|
|
||||||
checkTermDist :: World -> World
|
checkTermDist :: World -> World
|
||||||
checkTermDist w = case w ^? hud . hudElement . subInventory . termID of
|
checkTermDist w = case w ^? hud . hudElement . subInventory . termID of
|
||||||
@@ -155,25 +155,6 @@ checkTermDist w = case w ^? hud . hudElement . subInventory . termID of
|
|||||||
if dist btpos (_crPos $ you w) < 40 then Just w else Nothing
|
if dist btpos (_crPos $ you w) < 40 then Just w else Nothing
|
||||||
Nothing -> w
|
Nothing -> w
|
||||||
|
|
||||||
updateTerminalLine :: World -> World
|
|
||||||
updateTerminalLine w = case w ^? hud . hudElement . subInventory . termParams . termFutureLines . ix 0 of
|
|
||||||
Nothing -> w
|
|
||||||
Just tl | _tlPause tl > 0 -> w & pointTermParams . termFutureLines . ix 0 . tlPause -~ 1
|
|
||||||
Just (TerminalLineDisplay _ f) -> w & pointTermParams %~
|
|
||||||
( ( termFutureLines %~ tail )
|
|
||||||
. ( termDisplayedLines .:~ f )
|
|
||||||
)
|
|
||||||
Just (TerminalLineEffect _ eff) -> w
|
|
||||||
& pointTermParams . termFutureLines %~ tail
|
|
||||||
& eff (_subInventory . _hudElement $ _hud w)
|
|
||||||
Just (TerminalLineInput _) -> w & pointTermParams %~
|
|
||||||
( ( termFutureLines %~ tail )
|
|
||||||
-- . ( termScrollCommands .~ scrollc )
|
|
||||||
-- . ( termWriteCommands .~ writec )
|
|
||||||
. ( termInput ?~ T.empty ) )
|
|
||||||
where
|
|
||||||
pointTermParams = hud . hudElement . subInventory . termParams
|
|
||||||
|
|
||||||
-- this looks ugly...
|
-- this looks ugly...
|
||||||
updateCloseObjects :: World -> World
|
updateCloseObjects :: World -> World
|
||||||
updateCloseObjects w = w & closeObjects .~ unionBy closeObjEq oldCloseFiltered currentClose
|
updateCloseObjects w = w & closeObjects .~ unionBy closeObjEq oldCloseFiltered currentClose
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ analyser
|
|||||||
analyser starts sucs fails afters upf pslight psmc = extTrigLitPos pslight $ \tp ->
|
analyser starts sucs fails afters upf pslight psmc = extTrigLitPos pslight $ \tp ->
|
||||||
Just $ plSpot .~ psmc $ putTerminal' aquamarine tparams (termupdate tp)
|
Just $ plSpot .~ psmc $ putTerminal' aquamarine tparams (termupdate tp)
|
||||||
where
|
where
|
||||||
tparams = const $ defaultTermParams & termFutureLines ++.~
|
tparams = const $ defaultTermParams & tmFutureLines ++.~
|
||||||
(map makeTermLine starts ++ [makeTermLine sucs] ++ map makeTermLine afters)
|
(map makeTermLine starts ++ [makeTermLine sucs] ++ map makeTermLine afters)
|
||||||
termupdate tp btid =
|
termupdate tp btid =
|
||||||
(\mc -> upf mc . (triggers . ix (fromJust $ _plMID tp) .~ const (_sensToggle $ _mcSensor mc))
|
(\mc -> upf mc . (triggers . ix (fromJust $ _plMID tp) .~ const (_sensToggle $ _mcSensor mc))
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ import Data.Maybe
|
|||||||
|
|
||||||
putTerminal''
|
putTerminal''
|
||||||
:: Machine
|
:: Machine
|
||||||
-> (World -> TerminalParams)
|
-> (World -> Terminal)
|
||||||
-> (Int -> Machine -> World -> World) -- | machine update, takes button id as input
|
-> (Int -> Machine -> World -> World) -- | machine update, takes button id as input
|
||||||
-> Placement
|
-> Placement
|
||||||
putTerminal'' mc f mcf = ps0PushPS (PutTerminal theterminal) $ \tmpl -> Just $
|
putTerminal'' mc f mcf = ps0PushPS (PutTerminal theterminal) $ \tmpl -> Just $
|
||||||
@@ -46,11 +46,11 @@ putTerminal'' mc f mcf = ps0PushPS (PutTerminal theterminal) $ \tmpl -> Just $
|
|||||||
tmid = fromJust (_plMID tmpl)
|
tmid = fromJust (_plMID tmpl)
|
||||||
btid = fromJust (_plMID btpl)
|
btid = fromJust (_plMID btpl)
|
||||||
mcid = fromJust (_plMID mcpl)
|
mcid = fromJust (_plMID mcpl)
|
||||||
theterminal = defaultTerminal & tmProgram .~ const f
|
theterminal = defaultTerminal & tmProgram .~ (\_ w -> _tmFutureLines (f w))
|
||||||
|
|
||||||
putTerminal'
|
putTerminal'
|
||||||
:: Color
|
:: Color
|
||||||
-> (World -> TerminalParams)
|
-> (World -> Terminal)
|
||||||
-> (Int -> Machine -> World -> World) -- | machine update, takes button id as input
|
-> (Int -> Machine -> World -> World) -- | machine update, takes button id as input
|
||||||
-> Placement
|
-> Placement
|
||||||
putTerminal' col = putTerminal'' (defaultMachine & mcColor .~ col)
|
putTerminal' col = putTerminal'' (defaultMachine & mcColor .~ col)
|
||||||
@@ -59,7 +59,7 @@ putTerminal' col = putTerminal'' (defaultMachine & mcColor .~ col)
|
|||||||
, _mcSensor = SensorCloseToggle NotClose False
|
, _mcSensor = SensorCloseToggle NotClose False
|
||||||
}
|
}
|
||||||
|
|
||||||
putTerminal :: Color -> (World -> TerminalParams) -> Placement
|
putTerminal :: Color -> (World -> Terminal) -> Placement
|
||||||
putTerminal col f = putTerminal'' (mc & mcColor .~ col) f (\_ -> basicMachineUpdate $ const id)
|
putTerminal col f = putTerminal'' (mc & mcColor .~ col) f (\_ -> basicMachineUpdate $ const id)
|
||||||
where
|
where
|
||||||
mc = defaultMachine
|
mc = defaultMachine
|
||||||
@@ -73,7 +73,7 @@ termButton = Button
|
|||||||
{ _btPict = const mempty
|
{ _btPict = const mempty
|
||||||
, _btPos = 0
|
, _btPos = 0
|
||||||
, _btRot = 0
|
, _btRot = 0
|
||||||
, _btEvent = displayTerminalMessage . _btTermMID
|
, _btEvent = bootTerminal . _btTermMID
|
||||||
, _btID = 0
|
, _btID = 0
|
||||||
, _btText = "TERMINAL"
|
, _btText = "TERMINAL"
|
||||||
, _btState = BtOff
|
, _btState = BtOff
|
||||||
@@ -100,19 +100,16 @@ terminalShape mc = colorSH col (prismPoly
|
|||||||
where
|
where
|
||||||
col = _mcColor mc
|
col = _mcColor mc
|
||||||
|
|
||||||
displayTerminalMessage :: Maybe Int -> World -> World
|
bootTerminal :: Maybe Int -> World -> World
|
||||||
displayTerminalMessage mtmid w = case mtmid of
|
bootTerminal mtmid w = case mtmid of
|
||||||
Nothing -> w
|
Nothing -> w
|
||||||
Just tmid -> w & hud . hudElement .~ DisplayInventory DisplayTerminal
|
Just tmid -> w & hud . hudElement .~ DisplayInventory (DisplayTerminal tmid False)
|
||||||
{ _termID = tmid
|
& terminals . ix tmid . tmFutureLines ++.~ _tmProgram tm tm w
|
||||||
, _termParams = message tmid
|
& terminals . ix tmid . tmStatus .~ Connected
|
||||||
}
|
where
|
||||||
where
|
tm = w ^?! terminals . ix tmid
|
||||||
message tmid = fromMaybe NoTerminalParams $ do
|
|
||||||
tm <- w ^? terminals . ix tmid
|
|
||||||
return $ _tmProgram tm tm w
|
|
||||||
|
|
||||||
simpleTermMessage :: [String] -> World -> TerminalParams
|
simpleTermMessage :: [String] -> World -> Terminal
|
||||||
simpleTermMessage = genTermMessage . const
|
simpleTermMessage = genTermMessage . const
|
||||||
--simpleTermMessage ss = const $ TerminalParams
|
--simpleTermMessage ss = const $ TerminalParams
|
||||||
-- {_termDisplayedLines = []
|
-- {_termDisplayedLines = []
|
||||||
@@ -135,5 +132,5 @@ topFlushStrings = topFlush . maximum . map length
|
|||||||
topFlush :: Int -> [String]
|
topFlush :: Int -> [String]
|
||||||
topFlush twidth = [replicate i ' ' ++ "*" | i <- [0, max 1 $ twidth `div` 5 .. twidth]]
|
topFlush twidth = [replicate i ' ' ++ "*" | i <- [0, max 1 $ twidth `div` 5 .. twidth]]
|
||||||
|
|
||||||
genTermMessage :: (World -> [String]) -> World -> TerminalParams
|
genTermMessage :: (World -> [String]) -> World -> Terminal
|
||||||
genTermMessage f w = defaultTermParams & termFutureLines ++.~ map makeTermLine (f w)
|
genTermMessage f w = defaultTermParams & tmFutureLines ++.~ map makeTermLine (f w)
|
||||||
|
|||||||
@@ -84,14 +84,16 @@ subInventoryDisplay subinv cfig w = case subinv of
|
|||||||
, invHead cfig "TWEAK"
|
, invHead cfig "TWEAK"
|
||||||
, listTextPicturesAt subInvX 60 cfig $ map text (ammoTweakStrings it)
|
, listTextPicturesAt subInvX 60 cfig $ map text (ammoTweakStrings it)
|
||||||
]
|
]
|
||||||
DisplayTerminal {_termParams = tp,_termID = tid} -> pictures
|
DisplayTerminal {_termID = tid,_onInputLine=isoninput} ->
|
||||||
[ invHead cfig (_termTitle tp ++ ":T" ++ show tid)
|
let tp = w ^?! terminals . ix tid
|
||||||
|
in pictures
|
||||||
|
[ invHead cfig (_tmTitle tp ++ ":T" ++ show tid)
|
||||||
, renderListAt subInvX 60 cfig
|
, renderListAt subInvX 60 cfig
|
||||||
. displayTermInput tp
|
. displayTermInput tp
|
||||||
-- . (++ map (\(str,_) -> (str,white)) (_termOptions tp))
|
-- . (++ map (\(str,_) -> (str,white)) (_termOptions tp))
|
||||||
. reverse
|
. reverse
|
||||||
. take (_termMaxLines tp)
|
. take (_tmMaxLines tp)
|
||||||
$ _termDisplayedLines tp <&> ($ w)
|
$ _tmDisplayedLines tp
|
||||||
-- , fromMaybe mempty $ do
|
-- , fromMaybe mempty $ do
|
||||||
-- cursori <- _termSel tp <&> (+ _termMaxLines tp)
|
-- cursori <- _termSel tp <&> (+ _termMaxLines tp)
|
||||||
-- return $ listCursorNSW subInvX 60 cfig cursori white 15 1
|
-- return $ listCursorNSW subInvX 60 cfig cursori white 15 1
|
||||||
@@ -122,7 +124,7 @@ subInventoryDisplay subinv cfig w = case subinv of
|
|||||||
]
|
]
|
||||||
InspectInventory -> invHead cfig "INSPECT"
|
InspectInventory -> invHead cfig "INSPECT"
|
||||||
where
|
where
|
||||||
displayTermInput tp = case _termInput tp of
|
displayTermInput tp = case _tmInput tp of
|
||||||
Nothing -> id
|
Nothing -> id
|
||||||
Just s -> (++ [('>':T.unpack s++clockCycle 10 (V.fromList ["_",""]) w,white)])
|
Just s -> (++ [('>':T.unpack s++clockCycle 10 (V.fromList ["_",""]) w,white)])
|
||||||
closeobjectcursor = case selectedCloseObject w of
|
closeobjectcursor = case selectedCloseObject w of
|
||||||
|
|||||||
+65
-66
@@ -1,5 +1,6 @@
|
|||||||
module Dodge.Terminal where
|
module Dodge.Terminal where
|
||||||
import Dodge.Data
|
import Dodge.Data
|
||||||
|
import Dodge.Default
|
||||||
import Dodge.Base
|
import Dodge.Base
|
||||||
import Dodge.SoundLogic
|
import Dodge.SoundLogic
|
||||||
import Color
|
import Color
|
||||||
@@ -20,28 +21,28 @@ quitCommand = TerminalCommand
|
|||||||
, _tcAlias = ["Q","EXIT","X","SHUTDOWN",""]
|
, _tcAlias = ["Q","EXIT","X","SHUTDOWN",""]
|
||||||
, _tcHelp = "DISCONNECTS THE TERMINAL."
|
, _tcHelp = "DISCONNECTS THE TERMINAL."
|
||||||
, _tcArgumentType = Nothing
|
, _tcArgumentType = Nothing
|
||||||
, _tcArguments = const []
|
, _tcArguments = const (const [])
|
||||||
, _tcEffect = const $ \w -> Right $ w & disconnectTerminal
|
, _tcEffect = const $ \tm w -> Right $ w & disconnectTerminal tm
|
||||||
}
|
}
|
||||||
disconnectTerminal :: World -> World
|
disconnectTerminal :: Terminal -> World -> World
|
||||||
disconnectTerminal = hud . hudElement . subInventory . termParams %~
|
disconnectTerminal tm w = w
|
||||||
( (termInput .~ Nothing)
|
& terminals . ix (_tmID tm) . tmStatus .~ Disconnected
|
||||||
. (termFutureLines ++.~ [makeTermLine "DISCONNECTION COMPLETE"] )
|
& terminals . ix (_tmID tm) . tmFutureLines ++.~ [makeTermLine "DISCONNECTION COMPLETE"]
|
||||||
)
|
|
||||||
damageCodeCommand :: TerminalCommand
|
damageCodeCommand :: TerminalCommand
|
||||||
damageCodeCommand = TerminalCommand
|
damageCodeCommand = TerminalCommand
|
||||||
{ _tcString = "DAMAGECODE"
|
{ _tcString = "DAMAGECODE"
|
||||||
, _tcAlias = ["DCODE","DC"]
|
, _tcAlias = ["DCODE","DC"]
|
||||||
, _tcHelp = "DISPLAYS THE SHAPE AND COLOR ASSOCIATED WITH A GIVEN DAMAGE TYPE."
|
, _tcHelp = "DISPLAYS THE SHAPE AND COLOR ASSOCIATED WITH A GIVEN DAMAGE TYPE."
|
||||||
, _tcArgumentType = Just "A DAMAGE TYPE"
|
, _tcArgumentType = Just "A DAMAGE TYPE"
|
||||||
, _tcArguments = map (map toUpper . show) . M.keys . _sensorCoding . _genParams
|
, _tcArguments = \_ -> map (map toUpper . show) . M.keys . _sensorCoding . _genParams
|
||||||
, _tcEffect = f
|
, _tcEffect = f
|
||||||
}
|
}
|
||||||
where
|
where
|
||||||
f args w = fromMaybe (Left "") $ do
|
f args tm w = fromMaybe (Left "") $ do
|
||||||
dtype <- safeHead args >>= readMaybe
|
dtype <- safeHead args >>= readMaybe
|
||||||
dinfo <- _sensorCoding (_genParams w) M.!? dtype
|
dinfo <- _sensorCoding (_genParams w) M.!? dtype
|
||||||
return $ Right $ w & infoClearInput [makeTermLine $ show (fst dinfo) ++ " " ++ show (snd dinfo)]
|
return $ Right $ w & infoClearInput tm [makeTermLine $ show (fst dinfo) ++ " " ++ show (snd dinfo)]
|
||||||
|
|
||||||
helpCommand :: TerminalCommand
|
helpCommand :: TerminalCommand
|
||||||
helpCommand = TerminalCommand
|
helpCommand = TerminalCommand
|
||||||
@@ -49,31 +50,31 @@ helpCommand = TerminalCommand
|
|||||||
, _tcAlias = ["H","MAN"]
|
, _tcAlias = ["H","MAN"]
|
||||||
, _tcHelp = "DISPLAYS HELP FOR A SPECIFIC COMMAND. TO DISPLAY AVAILABLE COMMANDS USE \"COMMANDS\"."
|
, _tcHelp = "DISPLAYS HELP FOR A SPECIFIC COMMAND. TO DISPLAY AVAILABLE COMMANDS USE \"COMMANDS\"."
|
||||||
, _tcArgumentType = Just "AN AVAILABLE COMMAND"
|
, _tcArgumentType = Just "AN AVAILABLE COMMAND"
|
||||||
, _tcArguments = \w -> fromMaybe [] $ do
|
, _tcArguments = \tm w -> fromMaybe [] $ do
|
||||||
commands <- getCommands w
|
commands <- getCommands tm w
|
||||||
return $ map _tcString commands
|
return $ map _tcString commands
|
||||||
, _tcEffect = helpf
|
, _tcEffect = helpf
|
||||||
}
|
}
|
||||||
helpf :: [String] -> World -> Either String World
|
helpf :: [String] -> Terminal -> World -> Either String World
|
||||||
helpf [] w = helpf ["HELP"] w
|
helpf [] tm w = helpf ["HELP"] tm w
|
||||||
helpf (str:_) w = maybe (Left "") Right $ do
|
helpf (str:_) tm w = maybe (Left "") Right $ do
|
||||||
commands <- getCommands w
|
commands <- getCommands tm w
|
||||||
command <- find (\tc -> _tcString tc == str || str `elem` _tcAlias tc) commands
|
command <- find (\tc -> _tcString tc == str || str `elem` _tcAlias tc) commands
|
||||||
return $ w & infoClearInput
|
return $ w & infoClearInput tm
|
||||||
([makeTermLine ("COMMAND:" ++ _tcString command)
|
([makeTermLine ("COMMAND:" ++ _tcString command)
|
||||||
,makeTermLine ("ALIASES:" ++ unwords (_tcAlias command)) ]
|
,makeTermLine ("ALIASES:" ++ unwords (_tcAlias command)) ]
|
||||||
++ makeTermPara (_tcHelp command ++ " " ++ argumentHelp (_tcArgumentType command))
|
++ makeTermPara (_tcHelp command ++ " " ++ argumentHelp (_tcArgumentType command))
|
||||||
)
|
)
|
||||||
getCommands :: World -> Maybe [TerminalCommand]
|
getCommands :: Terminal -> World -> Maybe [TerminalCommand]
|
||||||
getCommands w = do
|
getCommands tm w = do
|
||||||
commands1 <- w ^? hud . hudElement . subInventory . termParams . termScrollCommands
|
commands1 <- w ^? terminals . ix (_tmID tm) . tmScrollCommands
|
||||||
commands2 <- w ^? hud . hudElement . subInventory . termParams . termWriteCommands
|
commands2 <- w ^? terminals . ix (_tmID tm) . tmWriteCommands
|
||||||
return $ commands1 ++ commands2
|
return $ commands1 ++ commands2
|
||||||
|
|
||||||
infoClearInput :: [TerminalLine] -> World -> World
|
infoClearInput :: Terminal -> [TerminalLine] -> World -> World
|
||||||
infoClearInput tls = hud . hudElement . subInventory . termParams %~
|
infoClearInput tm tls = terminals . ix (_tmID tm) %~
|
||||||
( (termInput ?~ T.empty)
|
( (tmInput ?~ T.empty)
|
||||||
. (termFutureLines ++.~ tls
|
. (tmFutureLines ++.~ tls
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -94,9 +95,9 @@ makeTermLine = makeColorTermLine white
|
|||||||
termSoundLine :: SoundID -> TerminalLine
|
termSoundLine :: SoundID -> TerminalLine
|
||||||
termSoundLine sid = TerminalLineEffect 0 termsound
|
termSoundLine sid = TerminalLineEffect 0 termsound
|
||||||
where
|
where
|
||||||
termsound subinv w = soundStart TerminalSound tpos sid Nothing w
|
termsound tm w = soundStart TerminalSound tpos sid Nothing w
|
||||||
where
|
where
|
||||||
tpos = fromMaybe 0 $ w ^? buttons . ix (_termID subinv) . btPos
|
tpos = fromMaybe 0 $ w ^? buttons . ix (_tmButtonID tm) . btPos
|
||||||
|
|
||||||
infoCommand :: String -> TerminalCommand
|
infoCommand :: String -> TerminalCommand
|
||||||
infoCommand str = TerminalCommand
|
infoCommand str = TerminalCommand
|
||||||
@@ -104,8 +105,8 @@ infoCommand str = TerminalCommand
|
|||||||
, _tcAlias = ["INFO","I"]
|
, _tcAlias = ["INFO","I"]
|
||||||
, _tcHelp = "DISPLAYS INFORMATION CONCERNING THE TERMINAL."
|
, _tcHelp = "DISPLAYS INFORMATION CONCERNING THE TERMINAL."
|
||||||
, _tcArgumentType = Nothing
|
, _tcArgumentType = Nothing
|
||||||
, _tcArguments = const []
|
, _tcArguments = const (const [])
|
||||||
, _tcEffect = const $ \w -> Right $ w & infoClearInput
|
, _tcEffect = const $ \tm w -> Right $ w & infoClearInput tm
|
||||||
( makeTermPara str)
|
( makeTermPara str)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -115,10 +116,10 @@ commandsCommand = TerminalCommand
|
|||||||
, _tcAlias = ["COMMAND","COM"]
|
, _tcAlias = ["COMMAND","COM"]
|
||||||
, _tcHelp = "DISPLAYS AVAILABLE COMMANDS."
|
, _tcHelp = "DISPLAYS AVAILABLE COMMANDS."
|
||||||
, _tcArgumentType = Nothing
|
, _tcArgumentType = Nothing
|
||||||
, _tcArguments = const []
|
, _tcArguments = const $ const []
|
||||||
, _tcEffect = const $ \w -> Right $ w & infoClearInput
|
, _tcEffect = \_ tm w -> Right $ w & infoClearInput tm
|
||||||
( makeTermLine "AVAILABLE COMMANDS:"
|
( makeTermLine "AVAILABLE COMMANDS:"
|
||||||
: makeTermPara (unwords (maybe [""] (map _tcString) $ getCommands w))
|
: makeTermPara (unwords (maybe [""] (map _tcString) $ getCommands tm w))
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -128,59 +129,57 @@ singleCommand command aliases htext eff = TerminalCommand
|
|||||||
,_tcAlias = aliases
|
,_tcAlias = aliases
|
||||||
,_tcHelp = htext
|
,_tcHelp = htext
|
||||||
,_tcArgumentType = Nothing
|
,_tcArgumentType = Nothing
|
||||||
, _tcArguments = const []
|
, _tcArguments = const $ const []
|
||||||
,_tcEffect = const $ \w -> Right $ eff $ disconnectTerminal w
|
,_tcEffect = \_ tm w -> Right $ eff $ disconnectTerminal tm w
|
||||||
}
|
}
|
||||||
|
|
||||||
doTerminalEffect :: World -> World
|
doTerminalEffect :: Terminal -> World -> World
|
||||||
doTerminalEffect w = fromMaybe w $ do
|
doTerminalEffect tm w = fromMaybe w $ do
|
||||||
s <- fmap T.unpack $ w ^? hud . hudElement . subInventory . termParams . termInput . _Just
|
s <- fmap T.unpack $ w ^? terminals . ix (_tmID tm) . tmInput . _Just
|
||||||
return $ doTerminalEffect' s $ w
|
return $ doTerminalEffect' s tm $ w
|
||||||
& hud . hudElement . subInventory . termParams . termFutureLines
|
& terminals . ix (_tmID tm) . tmFutureLines
|
||||||
.~ [makeColorTermLine (greyN 0.9) ('>':s)]
|
.~ [makeColorTermLine (greyN 0.9) ('>':s)]
|
||||||
|
|
||||||
doTerminalEffect' :: String -> World -> World
|
doTerminalEffect' :: String -> Terminal -> World -> World
|
||||||
doTerminalEffect' s w = fromMaybe (w & badinput) $ do
|
doTerminalEffect' s tm w = fromMaybe (w & badinput) $ do
|
||||||
commands <- getCommands w
|
commands <- getCommands tm w
|
||||||
if null (words s) then Just $ disconnectTerminal w else do
|
if null (words s) then Just $ disconnectTerminal tm w else do
|
||||||
let (str:args) = words s
|
let (str:args) = words s
|
||||||
command <- find (\tc -> _tcString tc == str || str `elem` _tcAlias tc) commands
|
command <- find (\tc -> _tcString tc == str || str `elem` _tcAlias tc) commands
|
||||||
case _tcEffect command args w of
|
case _tcEffect command args tm w of
|
||||||
Right w' -> return w'
|
Right w' -> return w'
|
||||||
Left err -> return $ w & hud . hudElement . subInventory . termParams %~
|
Left err -> return $ w & terminals . ix (_tmID tm) %~
|
||||||
( (termInput ?~ T.empty)
|
( (tmInput ?~ T.empty)
|
||||||
. (termFutureLines ++.~
|
. (tmFutureLines ++.~
|
||||||
[makeColorTermLine red
|
[makeColorTermLine red
|
||||||
("^ INVALID ARGUMENT: EXPECTS "++fromJust (_tcArgumentType command)++ err)
|
("^ INVALID ARGUMENT: EXPECTS "++fromJust (_tcArgumentType command)++ err)
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
where
|
where
|
||||||
badinput = hud . hudElement . subInventory . termParams %~
|
badinput = terminals . ix (_tmID tm) %~
|
||||||
( (termInput ?~ T.empty)
|
( (tmInput ?~ T.empty)
|
||||||
. (termFutureLines ++.~ [makeColorTermLine red "^ INVALID INPUT"
|
. (tmFutureLines ++.~ [makeColorTermLine red "^ INVALID INPUT" ]
|
||||||
]
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
addInputLine :: [TerminalCommand] -> [TerminalCommand] -> TerminalParams -> TerminalParams
|
addInputLine :: [TerminalCommand] -> [TerminalCommand] -> Terminal -> Terminal
|
||||||
addInputLine searchablecommands hiddencommands =
|
addInputLine searchablecommands hiddencommands =
|
||||||
(termFutureLines ++.~ [TerminalLineInput 0])
|
(tmFutureLines ++.~ [TerminalLineInput 0])
|
||||||
. (termScrollCommands ++.~ searchablecommands)
|
. (tmScrollCommands .~ searchablecommands)
|
||||||
. (termWriteCommands ++.~ hiddencommands)
|
. (tmWriteCommands .~ hiddencommands)
|
||||||
|
|
||||||
defaultTermParams :: TerminalParams
|
defaultTermParams :: Terminal
|
||||||
defaultTermParams = TerminalParams
|
defaultTermParams = defaultTerminal
|
||||||
{_termDisplayedLines = []
|
{_tmDisplayedLines = []
|
||||||
,_termFutureLines = termSoundLine computerBeepingS
|
,_tmFutureLines = termSoundLine computerBeepingS
|
||||||
: map makeTermLine connectionBlurb
|
: map makeTermLine connectionBlurb
|
||||||
,_termMaxLines = 14
|
,_tmMaxLines = 14
|
||||||
,_termTitle = "TERMINAL"
|
,_tmTitle = "TERMINAL"
|
||||||
,_termSel = Nothing
|
,_tmSel = Nothing
|
||||||
,_termInput = Nothing
|
,_tmInput = Nothing
|
||||||
,_termScrollCommands = []
|
,_tmScrollCommands = []
|
||||||
,_termWriteCommands = []
|
,_tmWriteCommands = []
|
||||||
,_termDeathCommand = Nothing
|
|
||||||
}
|
}
|
||||||
|
|
||||||
connectionBlurb :: [String]
|
connectionBlurb :: [String]
|
||||||
|
|||||||
+1
-1
@@ -109,7 +109,7 @@ tmUpdate tm w = case w ^? terminals . ix (_tmID tm) . tmFutureLines . ix 0 of
|
|||||||
)
|
)
|
||||||
Just (TerminalLineEffect _ eff) -> w
|
Just (TerminalLineEffect _ eff) -> w
|
||||||
& pointTermParams . tmFutureLines %~ tail
|
& pointTermParams . tmFutureLines %~ tail
|
||||||
& eff (_subInventory . _hudElement $ _hud w)
|
& eff tm
|
||||||
Just (TerminalLineInput _) -> w & pointTermParams %~
|
Just (TerminalLineInput _) -> w & pointTermParams %~
|
||||||
( ( tmFutureLines %~ tail )
|
( ( tmFutureLines %~ tail )
|
||||||
-- . ( tmScrollCommands .~ scrollc )
|
-- . ( tmScrollCommands .~ scrollc )
|
||||||
|
|||||||
@@ -167,8 +167,9 @@ rotateCamera cfig w
|
|||||||
keyl = SDL.ScancodeQ `S.member` _keys w && notAtTerminal w
|
keyl = SDL.ScancodeQ `S.member` _keys w && notAtTerminal w
|
||||||
keyr = SDL.ScancodeE `S.member` _keys w && notAtTerminal w
|
keyr = SDL.ScancodeE `S.member` _keys w && notAtTerminal w
|
||||||
|
|
||||||
|
-- TODO check where/how this is used
|
||||||
notAtTerminal :: World -> Bool
|
notAtTerminal :: World -> Bool
|
||||||
notAtTerminal w = isNothing $ w ^? hud . hudElement . subInventory . termParams . termInput . _Just
|
notAtTerminal w = isNothing $ w ^? hud . hudElement . subInventory . termID
|
||||||
|
|
||||||
--zoomCamBy :: Float -> World -> World
|
--zoomCamBy :: Float -> World -> World
|
||||||
--zoomCamBy x w = w {_cameraZoom = max (_cameraZoom w + x) 0.01}
|
--zoomCamBy x w = w {_cameraZoom = max (_cameraZoom w + x) 0.01}
|
||||||
|
|||||||
Reference in New Issue
Block a user