From 14c8d62646c44902411e31595019e79a53584d1a Mon Sep 17 00:00:00 2001 From: Eric Mertens Date: Sun, 4 Dec 2022 17:16:43 -0800 Subject: [PATCH] render deep infinities correctly --- app/Main.hs | 499 +++++++++++++++++++---------------------------- app/Parser.hs | 2 +- app/Rendering.hs | 15 +- 3 files changed, 208 insertions(+), 308 deletions(-) diff --git a/app/Main.hs b/app/Main.hs index 311c967..0321876 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -125,55 +125,58 @@ smallWorld = (Location 'b' 0 0) center8 :: World -center8 = - World - (Map.fromList - [('a', - Box (Location 'a' 3 (-3)) - (Original (makeWalls [ - "▓▓▓▓▓▓▓▓▓", - "▓▓▓▓▓▓▓▓▓", - "▓▓ ▓▓", - "▓▓ ▓▓", - "▓ ▓▓", - "▓ ▓▓", - "▓▓▓▓ ▓▓▓▓", - "▓ ▓▓ ▓▓", - "▓▓▓▓▓▓▓▓▓" - ])) - (withForeColor defAttr black) - False), - ('1', - Box - (Location 'a' 0 0) - (Original (makeWalls [ - " ▓▓", - " ▓▓▓▓▓", - " ", - " ", - " ", - " ", - " ", - " ", - " " - ])) - (withForeColor defAttr green) - False), - ('2', - Box - (Location '1' (-4) 0) - (Original (solid 9)) - (withForeColor defAttr yellow) - True), - ('b', - Box - (Location 'a' (-1) 0) - (Original (solid 9)) - (withForeColor defAttr red) - True) - ]) 'b' - Set.empty - (Location 'a' 3 2) +center8 = parse + "player p\n\ + \block t white boring\n\ + \▓▓▓▓▓▓▓▓▓\n\ + \▓▓▓▓▓▓▓▓▓\n\ + \▓▓▓▓▓▓▓▓▓\n\ + \▓▓▓▓▓▓▓▓▓\n\ + \▓▓▓▓t▓a▓▓\n\ + \▓▓▓▓▓▓▓▓▓\n\ + \▓▓▓▓▓▓▓▓▓\n\ + \▓▓▓▓▓▓▓▓▓\n\ + \▓▓▓▓▓▓▓▓▓\n\ + \block a white interesting\n\ + \▓▓▓▓▓▓▓▓▓\n\ + \▓▓▓▓▓▓▓▓▓\n\ + \▓▓ ▓▓\n\ + \▓▓ p ▓▓\n\ + \▓ g ▓▓\n\ + \▓ ▓▓\n\ + \▓▓▓▓ ▓▓▓▓\n\ + \▓▓▓▓- =▓▓\n\ + \▓▓▓▓▓▓▓▓▓\n\ + \block g green interesting\n\ + \ x ▓▓\n\ + \ ▓▓▓▓▓\n\ + \ \n\ + \ \n\ + \ \n\ + \ \n\ + \ \n\ + \ \n\ + \ \n\ + \block x yellow boring\n\ + \▓▓▓▓▓▓▓▓▓\n\ + \▓▓▓▓▓▓▓▓▓\n\ + \▓▓▓▓▓▓▓▓▓\n\ + \▓▓▓▓▓▓▓▓▓\n\ + \▓▓▓▓▓▓▓▓▓\n\ + \▓▓▓▓▓▓▓▓▓\n\ + \▓▓▓▓▓▓▓▓▓\n\ + \▓▓▓▓▓▓▓▓▓\n\ + \▓▓▓▓▓▓▓▓▓\n\ + \block p magenta boring\n\ + \▓▓▓▓▓▓▓▓▓\n\ + \▓▓▓▓▓▓▓▓▓\n\ + \▓ ▓▓▓ ▓▓▓\n\ + \▓▓▓▓▓▓▓▓▓\n\ + \▓▓▓▓▓▓▓▓▓\n\ + \▓▓▓▓▓▓▓▓▓\n\ + \▓▓▓▓▓▓▓▓▓\n\ + \▓▓▓▓▓▓▓▓▓\n\ + \▓▓▓▓▓▓▓▓▓\n" center13 :: World center13 = parse @@ -230,40 +233,29 @@ center13 = parse \▓▓▓▓▓▓▓▓▓\n" clone11 :: World -clone11 = - World - (Map.fromList - [('a', - Box (Location 'a' (-2) 2) - (Original (makeWalls [ - "▓▓▓▓▓▓▓▓▓", - "▓ ▓ ▓", - "▓ ▓ ▓", - "▓ ▓ ▓", - " ▓ ", - "▓ ▓ ▓", - "▓ ▓ ▓", - "▓▓▓ ▓▓▓", - "▓▓▓▓▓▓▓▓▓" - ])) - (withForeColor defAttr green) - False), - ('A', - Box - (Location 'a' 0 2) - (Link 'a') - (withForeColor defAttr green) - True), - ('b', - Box - (Location 'a' 0 (-2)) - (Original (solid 9)) - (withForeColor defAttr red) - True) - ]) - 'b' - (Set.fromList [Location 'a' (-1) (-3), Location 'a' (-2) (-3)]) - (Location 'a' (-3) (-3)) +clone11 = parse + "player p\n\ + \block a green boring\n\ + \▓▓▓▓▓▓▓▓▓\n\ + \▓= ▓ ▓\n\ + \▓- ▓ a ▓\n\ + \▓- ▓ ▓\n\ + \ p ▓ A \n\ + \▓ ▓ ▓\n\ + \▓ ▓ ▓\n\ + \▓▓▓ ▓▓▓\n\ + \▓▓▓▓▓▓▓▓▓\n\ + \link A a green\n\ + \block p magenta boring\n\ + \▓▓▓▓▓▓▓▓▓\n\ + \▓▓▓▓▓▓▓▓▓\n\ + \▓ ▓▓▓ ▓▓▓\n\ + \▓▓▓▓▓▓▓▓▓\n\ + \▓▓▓▓▓▓▓▓▓\n\ + \▓▓▓▓▓▓▓▓▓\n\ + \▓▓▓▓▓▓▓▓▓\n\ + \▓▓▓▓▓▓▓▓▓\n\ + \▓▓▓▓▓▓▓▓▓\n" transfer14 :: World transfer14 = @@ -860,117 +852,62 @@ infiniteExit5 = infiniteExit15 :: World -infiniteExit15 = - World - (Map.fromList - [('A', -- extra frame to accomodate the larger level - Box (Location 'F' 3 3) - (Original (makeWalls [ - "▓▓▓▓▓▓▓▓▓", - "▓▓▓▓▓▓▓▓▓", - "▓▓▓▓▓▓▓▓▓", - "▓▓▓▓▓▓▓▓▓", - "▓▓▓▓ ▓▓▓▓", - "▓▓▓▓▓▓▓▓▓", - "▓▓▓▓▓▓▓▓▓", - "▓▓▓▓▓▓▓ ▓", - "▓▓▓▓▓▓▓▓▓" - ])) - (withForeColor defAttr cyan) - True), - ('a', - Box - (Location 'A' 0 0) - (Original (makeWalls [ - "▓▓▓ ▓▓▓▓▓", - " ▓▓▓▓", - " ▓▓ ", - " ▓ ▓", - " ▓▓", - " ▓▓▓▓", - " ▓▓▓▓", - " ▓▓▓▓", - "▓▓▓▓▓▓▓▓▓" - ])) - (withForeColor defAttr cyan) - False), - ('b', - Box - (Location 'a' 1 (-2)) - (Original (makeWalls [ - "▓▓▓▓▓▓▓▓▓", - "▓▓▓▓▓▓▓▓▓", - "▓▓ ▓▓▓ ▓▓", - "▓▓▓▓▓▓▓▓▓", - "▓▓▓▓▓▓▓▓▓", - "▓▓▓▓▓▓▓▓▓", - "▓▓▓▓▓▓▓▓▓", - "▓▓▓▓▓▓▓▓▓", - "▓▓▓▓▓▓▓▓▓" - ])) - (withForeColor defAttr magenta) - True), - ('g', - Box - (Location 'a' 0 (-1)) - (Original (makeWalls [ - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " " - ])) - (withForeColor defAttr green) - False), - ('G', - Box - (Location 'a' (-4) (-1)) - (Link 'g') - (withForeColor defAttr green) - True), - ('Γ', - Box - (Location 'a' 2 (-1)) - (Infinity 'g') - (withForeColor defAttr green) - False), - ('p', - Box - (Location 'a' 0 (-3)) - (Original (makeWalls [ - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " " - ])) - (withForeColor defAttr red) - False), - ('P', - Box - (Location 'a' (-2) (-3)) - (Link 'p') - (withForeColor defAttr red) - True), - ('Π', - Box - (Location 'a' 2 (-3)) - (Infinity 'p') - (withForeColor defAttr red) - False) - ]) - 'b' - (Set.fromList [Location 'a' 0 2, Location 'a' (-1) 2, Location 'a' (-1) 3, Location 'a' (-2) 3]) - (Location 'a' (-2) 4) - +infiniteExit15 = parse + "player m\n\ + \block t cyan boring\n\ + \▓▓▓▓▓▓▓▓▓\n\ + \▓▓▓▓▓▓▓▓▓\n\ + \▓▓▓▓▓▓▓▓▓\n\ + \▓▓▓▓▓▓▓▓▓\n\ + \▓▓▓▓t▓a▓▓\n\ + \▓▓▓▓▓▓▓▓▓\n\ + \▓▓▓▓▓▓▓▓▓\n\ + \▓▓▓▓▓▓▓▓▓\n\ + \▓▓▓▓▓▓▓▓▓\n\ + \block a cyan interesting\n\ + \▓▓▓G▓▓▓▓▓\n\ + \ ▓▓▓▓\n\ + \ P ▓▓-=\n\ + \ ▓--▓\n\ + \ p g -▓▓\n\ + \ m ▓▓▓▓\n\ + \ Π Γ ▓▓▓▓\n\ + \ ▓▓▓▓\n\ + \▓▓▓▓▓▓▓▓▓\n\ + \block m magenta boring\n\ + \▓▓▓▓▓▓▓▓▓\n\ + \▓▓▓▓▓▓▓▓▓\n\ + \▓▓ ▓▓▓ ▓▓\n\ + \▓▓▓▓▓▓▓▓▓\n\ + \▓▓▓▓▓▓▓▓▓\n\ + \▓▓▓▓▓▓▓▓▓\n\ + \▓▓▓▓▓▓▓▓▓\n\ + \▓▓▓▓▓▓▓▓▓\n\ + \▓▓▓▓▓▓▓▓▓\n\ + \block g green interesting\n\ + \ \n\ + \ \n\ + \ \n\ + \ \n\ + \ \n\ + \ \n\ + \ \n\ + \ \n\ + \ \n\ + \block p red interesting\n\ + \ \n\ + \ \n\ + \ \n\ + \ \n\ + \ \n\ + \ \n\ + \ \n\ + \ \n\ + \ \n\ + \link G g green\n\ + \link P p red\n\ + \infinity Γ g green\n\ + \infinity Π p red\n" infiniteEnter17 :: World infiniteEnter17 = @@ -1262,112 +1199,72 @@ multiInfinite5 = parse \▓▓▓▓▓▓▓▓▓\n\ \▓▓▓▓▓▓▓▓▓\n\ \infinity 1 b blue\n\ - \infinity 2 b blue\n\ - \infinity 3 b blue\n" + \infinity 2 1 blue\n\ + \infinity 3 2 blue\n" multiInfinite8 :: World -multiInfinite8 = - World - (Map.fromList - [('b', Box - (Location 'b' 3 1) - (Original (makeWalls [ - "▓ ▓", - "▓ ▓ ▓", - "▓▓ ▓", - "▓ ▓", - "▓▓ ▓", - "▓ ▓", - "▓▓ ▓", - "▓ ▓▓▓", - "▓▓▓▓▓▓▓▓▓"])) - (withForeColor defAttr blue) - False), - ('p', - Box - (Location 'b' (-1) 0) - (Original (makeWalls [ - "▓▓▓▓▓▓▓▓▓", - "▓▓▓▓▓▓▓▓▓", - "▓▓ ▓▓▓ ▓▓", - "▓▓▓▓▓▓▓▓▓", - "▓▓▓▓▓▓▓▓▓", - "▓▓▓▓▓▓▓▓▓", - "▓▓▓▓▓▓▓▓▓", - "▓▓▓▓▓▓▓▓▓", - "▓▓▓▓▓▓▓▓▓" - ])) - (withForeColor defAttr magenta) - True), - ('A', - Box (Location 'b' (-1) 2) - (Link 'b') - (withForeColor defAttr blue) - True), - ('1', - Box - (Location 'b' (-1) (-3)) - (Epsilon 'b' (makeWalls [ - " ", - " ▓ ", - " ", - " ▓▓", - " ▓ ", - " ▓▓", - " ", - " ", - " "])) - (withForeColor defAttr blue) - False), - ('2', - Box - (Location 'b' 1 (-3)) - (Epsilon '1' (makeWalls [ - " ", - " ", - " ▓ ", - " ▓▓", - " ▓ ", - " ▓▓", - " ", - " ", - " "])) - (withForeColor defAttr blue) - False), - ('3', - Box - (Location 'b' 3 (-3)) - (Epsilon '2' (makeWalls [ - " ", - " ", - " ", - " ▓▓", - " ▓ ", - " ▓▓", - " ", - " ", - " "])) - (withForeColor defAttr blue) - False), - ('x', - Box - (Location '2' 4 1) - (Original (solid 9)) - (withForeColor defAttr yellow) - True), - ('B', - Box - (Location '1' 0 0) - (Link 'b') - (withForeColor defAttr blue) - True), - ('C', - Box - (Location '2' 4 (-1)) - (Link 'b') - (withForeColor defAttr blue) - True) - ]) - 'p' - Set.empty - (Location '3' 0 0) \ No newline at end of file +multiInfinite8 = parse + "player p\n\ + \block b blue interesting\n\ + \▓ ▓\n\ + \▓ ▓ ▓\n\ + \▓▓ ▓\n\ + \▓1 p A ▓\n\ + \▓▓ ▓\n\ + \▓2 ▓\n\ + \▓▓ ▓\n\ + \▓3 b▓▓▓\n\ + \▓▓▓▓▓▓▓▓▓\n\ + \link A b blue\n\ + \link B b blue\n\ + \link C b blue\n\ + \block p magenta boring\n\ + \▓▓▓▓▓▓▓▓▓\n\ + \▓▓▓▓▓▓▓▓▓\n\ + \▓▓ ▓▓▓ ▓▓\n\ + \▓▓▓▓▓▓▓▓▓\n\ + \▓▓▓▓▓▓▓▓▓\n\ + \▓▓▓▓▓▓▓▓▓\n\ + \▓▓▓▓▓▓▓▓▓\n\ + \▓▓▓▓▓▓▓▓▓\n\ + \▓▓▓▓▓▓▓▓▓\n\ + \epsilon 1 b blue\n\ + \ \n\ + \ ▓ \n\ + \ \n\ + \ ▓▓\n\ + \ B ▓ \n\ + \ ▓▓\n\ + \ \n\ + \ \n\ + \ \n\ + \epsilon 2 1 blue\n\ + \ \n\ + \ \n\ + \ ▓ \n\ + \ ▓▓\n\ + \ ▓ \n\ + \ ▓▓\n\ + \ \n\ + \ \n\ + \ C x \n\ + \epsilon 3 2 blue\n\ + \ \n\ + \ \n\ + \ \n\ + \ ▓▓\n\ + \ = ▓ \n\ + \ ▓▓\n\ + \ \n\ + \ \n\ + \ \n\ + \block x yellow boring\n\ + \▓▓▓▓▓▓▓▓▓\n\ + \▓▓▓▓▓▓▓▓▓\n\ + \▓▓▓▓▓▓▓▓▓\n\ + \▓▓▓▓▓▓▓▓▓\n\ + \▓▓▓▓▓▓▓▓▓\n\ + \▓▓▓▓▓▓▓▓▓\n\ + \▓▓▓▓▓▓▓▓▓\n\ + \▓▓▓▓▓▓▓▓▓\n\ + \▓▓▓▓▓▓▓▓▓\n" \ No newline at end of file diff --git a/app/Parser.hs b/app/Parser.hs index cb72e99..9fad19d 100644 --- a/app/Parser.hs +++ b/app/Parser.hs @@ -46,7 +46,7 @@ parseBlocks (x:xs) = ["infinity", [name], [target], color] -> do color_ <- parseColor color bs <- parseBlocks xs - pure ((name, Box undefined (Infinity target) color_ False,[]):bs) + pure ((name, Box undefined (Infinity target) color_ True,[]):bs) ["epsilon", [name], [target], color] -> do color_ <- parseColor color let (xs1,xs2) = splitAt 9 xs diff --git a/app/Rendering.hs b/app/Rendering.hs index 1b710bb..f8cf287 100644 --- a/app/Rendering.hs +++ b/app/Rendering.hs @@ -52,12 +52,7 @@ renderCell world locMap name box y x scale = | otherwise -> unit (boxColor box) scale floorChar where loc = Location name' y x - name' = - case boxType box of - Original{} -> name - Link c -> c - Infinity c -> c - Epsilon{} -> name + name' = contentName world name box wallChar = case boxType box of Original{} -> '▓' @@ -71,6 +66,14 @@ renderCell world locMap name box y x scale = Infinity {} -> '∞' Epsilon {} -> 'ε' +contentName :: World -> Char -> Box -> Char +contentName world name box = + case boxType box of + Original{} -> name + Link c -> c + Infinity c -> contentName world c (worldBoxes world Map.! c) + Epsilon{} -> name + renderBox :: World -> Map Location Char -> Box -> Char -> Int -> Image renderBox world locMap box name scale = vertCat [