Separate out concrete part of world
This commit is contained in:
+26
-26
@@ -38,17 +38,17 @@ handleTextInput text u = u
|
||||
& menuLayers . ix 0 . scInput %~ updateText
|
||||
& updateTerminalText
|
||||
where
|
||||
updateTerminalText = case u ^? uvWorld . hud . hudElement . subInventory of
|
||||
updateTerminalText = case u ^? uvWorld . cWorld . hud . hudElement . subInventory of
|
||||
Just (DisplayTerminal tmid) | hasfocus tmid
|
||||
-> uvWorld %~ \w -> guardDisconnectedID tmid w (w & terminals . ix tmid . tmInput . tiText %~ updateText)
|
||||
-> uvWorld %~ \w -> guardDisconnectedID tmid w (w & cWorld . terminals . ix tmid . tmInput . tiText %~ updateText)
|
||||
_ -> id
|
||||
hasfocus tmid = fromMaybe False $ u ^? uvWorld . terminals . ix tmid . tmInput . tiFocus
|
||||
hasfocus tmid = fromMaybe False $ u ^? uvWorld . cWorld . terminals . ix tmid . tmInput . tiFocus
|
||||
updateText s = case T.unpack text of
|
||||
";" -> s
|
||||
_ -> s `T.append` T.toUpper text
|
||||
|
||||
guardDisconnectedID :: Int -> World -> World -> World
|
||||
guardDisconnectedID tmid w w' = case w ^? terminals . ix tmid . tmStatus of
|
||||
guardDisconnectedID tmid w w' = case w ^? cWorld . terminals . ix tmid . tmStatus of
|
||||
Just TerminalReady -> w'
|
||||
_ -> w
|
||||
|
||||
@@ -60,23 +60,23 @@ see 'handlePressedKeyInGame'.
|
||||
-}
|
||||
handleKeyboardEvent :: KeyboardEventData -> Universe -> IO (Maybe Universe)
|
||||
handleKeyboardEvent kev u = case keyboardEventKeyMotion kev of
|
||||
Released -> return . Just $ u & uvWorld . keys %~ S.delete scode
|
||||
Released -> return . Just $ u & uvWorld . cWorld . keys %~ S.delete scode
|
||||
Pressed -> handlePressedKey (keyboardEventRepeat kev) scode
|
||||
(u & uvWorld . keys %~ S.insert scode)
|
||||
(u & uvWorld . cWorld . keys %~ S.insert scode)
|
||||
where
|
||||
scode = (keysymScancode . keyboardEventKeysym) kev
|
||||
|
||||
handlePressedKey :: Bool -> Scancode -> Universe -> IO (Maybe Universe)
|
||||
handlePressedKey True ScancodeBackspace u
|
||||
| _backspaceTimer (_uvWorld u) <= 0 = handlePressedKey False ScancodeBackspace u
|
||||
<&> _Just . uvWorld . backspaceTimer .~ 0
|
||||
| otherwise = return $ Just $ u & uvWorld . backspaceTimer -~ 1
|
||||
| _backspaceTimer (_cWorld $ _uvWorld u) <= 0 = handlePressedKey False ScancodeBackspace u
|
||||
<&> _Just . uvWorld . cWorld . backspaceTimer .~ 0
|
||||
| otherwise = return $ Just $ u & uvWorld . cWorld . backspaceTimer -~ 1
|
||||
handlePressedKey True _ u = return $ Just u
|
||||
handlePressedKey _ scode u = case scode of
|
||||
ScancodeF5 -> return . Just $ doQuicksave u
|
||||
ScancodeF9 -> return . Just $ loadSaveSlot QuicksaveSlot u
|
||||
ScancodeSemicolon -> return . Just $ gotoTerminal u
|
||||
_ | null (_menuLayers u) -> case u ^? uvWorld . hud . hudElement . subInventory of
|
||||
_ | null (_menuLayers u) -> case u ^? uvWorld . cWorld . hud . hudElement . subInventory of
|
||||
Just (DisplayTerminal tmid) | inTermFocus (_uvWorld u)
|
||||
-> return $ uvWorld (Just . handlePressedKeyTerminal tmid scode) u
|
||||
_ -> return $ (Just . handlePressedKeyInGame scode) u
|
||||
@@ -91,9 +91,9 @@ handlePressedKeyInGame scode uv = case scode of
|
||||
ScancodeM -> over uvWorld toggleMap uv
|
||||
ScancodeR -> over uvWorld (crToggleReloading (you w)) uv
|
||||
ScancodeT -> over uvWorld testEvent uv
|
||||
ScancodeX -> uv & uvWorld . hud . hudElement %~ toggleTweakInv
|
||||
ScancodeX -> uv & uvWorld . cWorld . hud . hudElement %~ toggleTweakInv
|
||||
ScancodeC -> over uvWorld toggleCombineInv uv
|
||||
ScancodeI -> uv & uvWorld . hud . hudElement %~ toggleInspectInv
|
||||
ScancodeI -> uv & uvWorld . cWorld . hud . hudElement %~ toggleInspectInv
|
||||
_ -> uv
|
||||
where
|
||||
w = _uvWorld uv
|
||||
@@ -101,11 +101,11 @@ handlePressedKeyInGame scode uv = case scode of
|
||||
|
||||
handlePressedKeyTerminal :: Int -> Scancode -> World -> World
|
||||
handlePressedKeyTerminal tmid scode w = case scode of
|
||||
ScancodeEscape -> w & terminals . ix tmid . tmInput . tiFocus %~ const False
|
||||
ScancodeReturn -> w & terminalReturnEffect (w ^?! terminals . ix tmid)
|
||||
ScancodeEscape -> w & cWorld . terminals . ix tmid . tmInput . tiFocus %~ const False
|
||||
ScancodeReturn -> w & terminalReturnEffect (w ^?! cWorld . terminals . ix tmid)
|
||||
ScancodeBackspace -> w
|
||||
& terminals . ix tmid . tmInput . tiText %~ doBackspace
|
||||
& backspaceTimer .~ 5
|
||||
& cWorld . terminals . ix tmid . tmInput . tiText %~ doBackspace
|
||||
& cWorld . backspaceTimer .~ 5
|
||||
_ -> w
|
||||
where
|
||||
doBackspace t = case T.unsnoc t of
|
||||
@@ -128,26 +128,26 @@ gotoTerminal w = case _menuLayers w of
|
||||
_ -> w & menuLayers .:~ InputScreen T.empty "Enter command"
|
||||
|
||||
spaceAction :: World -> World
|
||||
spaceAction w = case _hudElement $ _hud w of
|
||||
DisplayCarte -> w & hud . carteCenter .~ theLoc
|
||||
spaceAction w = case _hudElement $ _hud (_cWorld w) of
|
||||
DisplayCarte -> w & cWorld . hud . carteCenter .~ theLoc
|
||||
DisplayInventory NoSubInventory -> case selectedCloseObject w of
|
||||
Just (_,Left flit) -> pickUpItem 0 flit w
|
||||
Just (_,Right but) -> doButtonEvent (_btEvent but) but w
|
||||
_ -> w
|
||||
DisplayInventory DisplayTerminal {} -> w & hud . hudElement .~ DisplayInventory NoSubInventory
|
||||
_ -> w & hud . hudElement .~ DisplayInventory NoSubInventory
|
||||
DisplayInventory DisplayTerminal {} -> w & cWorld . hud . hudElement .~ DisplayInventory NoSubInventory
|
||||
_ -> w & cWorld . hud . hudElement .~ DisplayInventory NoSubInventory
|
||||
where
|
||||
theLoc = doWorldPos (fst (_seenLocations w IM.! _selLocation w)) w
|
||||
theLoc = doWorldPos (fst (_seenLocations (_cWorld w) IM.! _selLocation (_cWorld w))) w
|
||||
-- updateTopCloseObject i w' = w' & closeObjects %~ ( Right (_buttons w' IM.! i) : ) . tail
|
||||
|
||||
pauseGame :: Universe -> Universe
|
||||
pauseGame = menuLayers .~ [pauseMenu]
|
||||
|
||||
toggleMap :: World -> World
|
||||
toggleMap w = case _hudElement $ _hud w of
|
||||
DisplayCarte -> w & hud . hudElement .~ DisplayInventory NoSubInventory
|
||||
_ -> w & hud . hudElement .~ DisplayCarte
|
||||
toggleMap w = case _hudElement $ _hud (_cWorld w) of
|
||||
DisplayCarte -> w & cWorld . hud . hudElement .~ DisplayInventory NoSubInventory
|
||||
_ -> w & cWorld . hud . hudElement .~ DisplayCarte
|
||||
escapeMap :: World -> World
|
||||
escapeMap w = case _hudElement $ _hud w of
|
||||
DisplayCarte -> w & hud . hudElement .~ DisplayInventory NoSubInventory
|
||||
escapeMap w = case _hudElement $ _hud (_cWorld w) of
|
||||
DisplayCarte -> w & cWorld . hud . hudElement .~ DisplayInventory NoSubInventory
|
||||
_ -> w
|
||||
|
||||
Reference in New Issue
Block a user