Improve terminal parsing
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
{-# LANGUAGE TupleSections #-}
|
||||
module Dodge.Debug.Terminal
|
||||
where
|
||||
import MaybeHelp
|
||||
import ListHelp (safeHead)
|
||||
import Dodge.Inventory.Add
|
||||
import Dodge.Creature
|
||||
import Dodge.Creature.Damage
|
||||
@@ -62,11 +62,21 @@ applyTerminalCommand s = case s of
|
||||
applyTerminalCommandArguments :: String -> [String] -> Universe -> Universe
|
||||
applyTerminalCommandArguments command args u = case command of
|
||||
"ITEM" -> fromMaybe u $ do
|
||||
ibt <- (safeHead args >>= readMaybe) <|> (safeTake2 args >>= (readMaybe . unwords))
|
||||
n <- (args ^? ix 1 >>= readMaybe) <|> Just 1
|
||||
(ibt,n) <- parseItem args
|
||||
return $ u & uvWorld %~ (flip (foldr ($)) $ replicate n (snd . createPutItem (itemFromBase ibt)))
|
||||
_ -> u
|
||||
|
||||
parseItem :: [String] -> Maybe (ItemBaseType,Int)
|
||||
parseItem (x:xs)
|
||||
= (readMaybe (x++" {_xNum=" ++ show (parseNum xs)++"}") <&> (,1))
|
||||
<|> (readMaybe x <&> (,parseNum xs) )
|
||||
<|> (readMaybe ("CRAFT "++x) <&> (,parseNum xs))
|
||||
<|> parseItem (xs & ix 0 .++~ (x ++ " "))
|
||||
parseItem [] = Nothing
|
||||
|
||||
parseNum :: [String] -> Int
|
||||
parseNum xs = fromMaybe 1 $ xs ^? ix 0 >>= readMaybe
|
||||
|
||||
safeTake2 :: [a] -> Maybe [a]
|
||||
safeTake2 (x:y:_) = Just (x:y:[])
|
||||
safeTake2 _ = Nothing
|
||||
|
||||
+1
-1
@@ -41,7 +41,7 @@ initialAnoTree :: Annotation
|
||||
initialAnoTree = OnwardList
|
||||
$ intersperse (AnTree corDoor)
|
||||
[ IntAnno $ AnTree . startRoom
|
||||
, AnRoom $ roomCCrits 0
|
||||
, AnRoom $ roomCCrits 10
|
||||
, AnRoom $ return airlock0
|
||||
, AnRoom slowDoorRoom
|
||||
, AnRoom $ roomCCrits 10
|
||||
|
||||
Reference in New Issue
Block a user