From 7d5ad3221582945d888fbef96bc7da45d0a794c3 Mon Sep 17 00:00:00 2001 From: kjetil midtlie Date: Thu, 17 Feb 2022 21:15:02 +0100 Subject: [PATCH] argsparse into the mix --- Main.hs | 40 +++++++++++++++++++++++++++++++++++----- README.md | 4 ++++ 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/Main.hs b/Main.hs index 33f439b..1a3e987 100644 --- a/Main.hs +++ b/Main.hs @@ -4,21 +4,43 @@ import Colors import InfiniteHexGrid import System.Random (getStdGen) import Data.List (zip, transpose, unfoldr) +import System.Environment +import System.Exit -seed = 2022 -screenLen = 20 +screenLen = 25 -biomes = "-|*¤X" -- PutInto data w rangeInput +biomes = "█·▒░·▓" rRange = (0, length biomes - 1) +data InputArgs = InputArgs { + viewportW::Int, + viewportH::Int +} deriving (Show) + main :: IO () -main = drawGrid screenLen screenLen +main = do + args' <- parseArgs 2 + drawGrid (viewportW args') (viewportH args') +-- args or death +parseArgs :: Int -> IO InputArgs +parseArgs argsLen = do + args <- getArgs -- IO + if length args < argsLen + then do + usage + exitWith $ ExitFailure 1 + else do + -- errorhandling ? + return InputArgs { + viewportW = read $ args !! 0 + , viewportH = read $ args !! 1 + } drawGrid :: Int -> Int -> IO () drawGrid maxCols maxRows = do g <- getStdGen - let (x,y) = (10,10) + let (x,y) = (0,0) let grid = initIHexGrid g rRange let fGrid = finiteHexGrid (maxCols,maxRows) (x,y) grid let rasterized = map (zoomRow2x biomes) fGrid @@ -33,3 +55,11 @@ zoomRow2x biomeSet (off, x:xs) = maybeCap Complete = complete capped = (:[]) . (!!) biomeSet complete = replicate 2 . (!!) biomeSet + +usage :: IO () +usage = do + prog <- getProgName + putStrLn "usage:" + putStrLn $ " " ++ prog ++ " WIDTH HEIGHT [ZOOM] " + putStrLn " " + putStrLn " Prints hexagon cells to terminal. ZOOM default = 2" diff --git a/README.md b/README.md index 1f476b1..6fb7bff 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,7 @@ # hask-hex Another tile-gen generation, now using hexagons + +Work In Progress + + cabal run