Skip to content

Commit

Permalink
argsparse into the mix
Browse files Browse the repository at this point in the history
  • Loading branch information
dynnamitt committed Feb 17, 2022
1 parent 60b63f1 commit 7d5ad32
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 5 deletions.
40 changes: 35 additions & 5 deletions Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# hask-hex

Another tile-gen generation, now using hexagons

Work In Progress

cabal run

0 comments on commit 7d5ad32

Please sign in to comment.