From 699b8ddd72aca8569a63b1e37a0265428c534bc9 Mon Sep 17 00:00:00 2001 From: Daniel Liu Date: Sat, 1 May 2021 17:13:03 -0400 Subject: [PATCH] very bsaic rendering done --- Render.hs | 16 ++++++++++++---- Sim.hs | 24 +++++++++++++++++++++++- readme.md | 2 ++ 3 files changed, 37 insertions(+), 5 deletions(-) diff --git a/Render.hs b/Render.hs index fc321f6..37a8e0a 100644 --- a/Render.hs +++ b/Render.hs @@ -6,10 +6,14 @@ import Brick.Types import Brick.Widgets.Core import Graphics.Vty.Input.Events +import qualified Data.Vector as V +import Sim + type ResourceName = String -data EkitaiState = - EkitaiState deriving (Show) +data EkitaiState = EkitaiState + { ekitaiStateSim :: Simulation + } deriving (Show) ekitaiApp :: App EkitaiState e ResourceName ekitaiApp = App @@ -21,10 +25,14 @@ ekitaiApp = App } buildInitialState :: IO EkitaiState -buildInitialState = pure EkitaiState +buildInitialState = + pure EkitaiState + { ekitaiStateSim = testSim + } drawEkitai :: EkitaiState -> [Widget ResourceName] -drawEkitai state = [] +-- drawEkitai state = [ vBox $ drawSim $ ekitaiStateSim state ] +drawEkitai state = [ vBox [str $ simToString $ ekitaiStateSim state] ] handleEkitaiEvent :: EkitaiState -> BrickEvent n e -> EventM n (Next EkitaiState) handleEkitaiEvent s e = diff --git a/Sim.hs b/Sim.hs index c48dbe4..26fc5f1 100644 --- a/Sim.hs +++ b/Sim.hs @@ -1,4 +1,8 @@ -module Sim ( initSimSpace, testSim, physStep, updateWaterChunk, validDirects ) where +module Sim ( + Simulation, simSpace, + ChunkType, ChunkData, chunkType, + initSimSpace, testSim, physStep, updateWaterChunk, validDirects, simToString +) where import Debug.Trace import Data.Vector ((!), (//)) @@ -66,3 +70,21 @@ validDirects x y w h = filter (\q -> 0 <= (fst q) && (fst q) < w && (snd q) <= 0 && (snd q) < h) [(a-x,b-y) | a <- [x-1..x+1], b <- [y-1..y+1], not (a==x && b==y)] +simToString :: Simulation -> [Char] +simToString sim@Simulation{simW=w} = + let simStr = V.toList $ V.map chunkToChar $ simSpace sim + in insert w '\n' simStr + +-- from https://stackoverflow.com/questions/12659562/insert-specific-element-y-after-every-n-elements-in-a-list +insert :: Int -> a -> [a] -> [a] +insert n y xs = countdown n xs where + countdown 0 xs = y:countdown n xs + countdown _ [] = [] + countdown m (x:xs) = x:countdown (m-1) xs + +chunkToChar :: ChunkData -> Char +chunkToChar c = + case chunkType c of + Water -> '~' + Air -> '.' + _ -> '?' diff --git a/readme.md b/readme.md index fe7c77e..87d051c 100644 --- a/readme.md +++ b/readme.md @@ -10,8 +10,10 @@ this will be incredibly painful ## FAQ **why ekitai?** + ekitai is fluid in japanese. since naming your projects in a different language is apparently cool. **why not in c?** + c would have probably been one of the best choices to do this project in, but i wanted to add a bit of challenge by using a language that i didn't know. -- 2.20.1