2019-09-13 21:24:05 +02:00
|
|
|
module Main ( main ) where
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
import Xanthous.Prelude
|
|
|
|
import Brick
|
2019-09-07 20:49:59 +02:00
|
|
|
import qualified Options.Applicative as Opt
|
2019-09-13 21:24:05 +02:00
|
|
|
import System.Random
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
import Xanthous.Game (getInitialState)
|
|
|
|
import Xanthous.App (makeApp)
|
|
|
|
import Xanthous.Generators
|
2019-09-19 19:56:14 +02:00
|
|
|
( GeneratorInput
|
2019-09-07 20:49:59 +02:00
|
|
|
, parseGeneratorInput
|
|
|
|
, generateFromInput
|
|
|
|
, showCells
|
|
|
|
)
|
2019-09-13 21:24:05 +02:00
|
|
|
import Xanthous.Generators.Util (regions)
|
|
|
|
import Xanthous.Generators.LevelContents
|
|
|
|
import Xanthous.Data (Dimensions, Dimensions'(Dimensions))
|
|
|
|
import Data.Array.IArray ( amap )
|
|
|
|
--------------------------------------------------------------------------------
|
2019-09-07 20:49:59 +02:00
|
|
|
data Command
|
|
|
|
= Run
|
|
|
|
| Generate GeneratorInput Dimensions
|
2019-08-25 19:28:10 +02:00
|
|
|
|
2019-09-07 20:49:59 +02:00
|
|
|
parseDimensions :: Opt.Parser Dimensions
|
|
|
|
parseDimensions = Dimensions
|
|
|
|
<$> Opt.option Opt.auto
|
|
|
|
( Opt.short 'w'
|
|
|
|
<> Opt.long "width"
|
|
|
|
)
|
|
|
|
<*> Opt.option Opt.auto
|
|
|
|
( Opt.short 'h'
|
|
|
|
<> Opt.long "height"
|
|
|
|
)
|
|
|
|
|
|
|
|
parseCommand :: Opt.Parser Command
|
2019-09-10 02:54:33 +02:00
|
|
|
parseCommand = (<|> pure Run) $ Opt.subparser
|
2019-09-07 20:49:59 +02:00
|
|
|
$ Opt.command "run"
|
|
|
|
(Opt.info
|
|
|
|
(pure Run)
|
|
|
|
(Opt.progDesc "Run the game"))
|
|
|
|
<> Opt.command "generate"
|
|
|
|
(Opt.info
|
|
|
|
(Generate
|
|
|
|
<$> parseGeneratorInput
|
|
|
|
<*> parseDimensions
|
|
|
|
<**> Opt.helper
|
|
|
|
)
|
|
|
|
(Opt.progDesc "Generate a sample level"))
|
|
|
|
|
|
|
|
optParser :: Opt.ParserInfo Command
|
|
|
|
optParser = Opt.info
|
|
|
|
(parseCommand <**> Opt.helper)
|
|
|
|
(Opt.header "Xanthous: a WIP TUI RPG")
|
|
|
|
|
|
|
|
runGame :: IO ()
|
|
|
|
runGame = do
|
2019-08-25 19:28:10 +02:00
|
|
|
app <- makeApp
|
2019-09-01 22:21:45 +02:00
|
|
|
initialState <- getInitialState
|
2019-08-25 19:28:10 +02:00
|
|
|
_ <- defaultMain app initialState
|
|
|
|
pure ()
|
2019-09-07 20:49:59 +02:00
|
|
|
|
|
|
|
runGenerate :: GeneratorInput -> Dimensions -> IO ()
|
|
|
|
runGenerate input dims = do
|
|
|
|
randGen <- getStdGen
|
|
|
|
let res = generateFromInput input dims randGen
|
2019-09-13 21:24:05 +02:00
|
|
|
rs = regions $ amap not res
|
|
|
|
putStr "num regions: "
|
|
|
|
print $ length rs
|
|
|
|
putStr "region lengths: "
|
|
|
|
print $ length <$> rs
|
|
|
|
putStr "character position: "
|
|
|
|
print =<< chooseCharacterPosition res
|
2019-09-07 20:49:59 +02:00
|
|
|
putStrLn $ showCells res
|
|
|
|
|
|
|
|
runCommand :: Command -> IO ()
|
|
|
|
runCommand Run = runGame
|
|
|
|
runCommand (Generate input dims) = runGenerate input dims
|
|
|
|
|
|
|
|
main :: IO ()
|
|
|
|
main = runCommand =<< Opt.execParser optParser
|