Commit 887fb1e8 authored by Reg Huijben's avatar Reg Huijben

Added start for switches, fixed drawing errors

parent 79a5ef07
......@@ -29,17 +29,31 @@ createTiles s = map createTile (myCoolTiles s)
createTile :: (Tile,Int) -> Image State
createTile (t,i) = overlay [(AtMiddleX,AtMiddleY),(AtMiddleX,AtMiddleY)] offs imgs NoHost where
offs = [(px 0.0, px 0.0): fst3 (unzip3 (filteredSwitchList (t, i)))]
imgs = [createTracksOfTile (t,i): snd3 (unzip3 (filteredSwitchList (t, i)))]
//createTile (t,i) = overlay [(AtMiddleX,AtMiddleY),(AtMiddleX,AtMiddleY)] offs imgs NoHost where
createTile (t,i) = overlay all offs imgs NoHost where
all = [(AtLeft,AtTop): fst4 (unzip4 (filteredSwitchList (t, i)))]
offs = [(px 0.0, px 0.0): snd4 (unzip4 (filteredSwitchList (t, i)))]
imgs = [createTracksOfTile (t,i): thd4 (unzip4 (filteredSwitchList (t, i)))]
// welp
fst4 :: (a, b, c,d) -> a
fst4 (a,_,_,_) = a
snd4 :: (a, b, c,d) -> b
snd4 (_,b,_,_) = b
thd4 :: (a, b, c,d) -> c
thd4 (_,_,c,_) = c
filteredSwitchList (t,i) = filter (\(_,_,active). active) (switchList (t,i))
filteredSwitchList (t,i) = filter (\(_,_,_,active). active) (switchList (t,i))
switchList :: (Tile,Int) -> [(ImageOffset,Image State, Bool)]
switchList :: (Tile,Int) -> [(XYAlign,ImageOffset,Image State, Bool)]
switchList (t,i) = [
((px 0.0, px (half - strw)), (south t i), drawSouth t )
((AtMiddleX,AtTop),(px 0.0, px (0.0)), (north t i), drawNorth t ),
((AtRight,AtMiddleY),(px 0.0, px (0.0)), (east t i), drawEast t ),
//((px 0.0, px (half - strw)), (south t i), drawEast t )
((AtMiddleX,AtBottom),(px 0.0, px (0.0 )), (south t i), drawSouth t ),
((AtLeft,AtMiddleY),(px 0.0, px (0.0)), (west t i), drawWest t )
//((px 0.0, px (half - strw)), (south t i), drawWest t )
]
......@@ -57,23 +71,22 @@ trackList :: (Tile,Int) -> [(ImageOffset,Image State, Bool)]
trackList (t,i) = [
( (px half, px 0.0) , (ns t i), t.ns ),
( (zero, px half), (ew t i), t.ew),
( (px 0.0, px 0.0), (ne t i), t.ne),
( (px half, px 0.0), (nw t i), t.nw),
( (px half, px 0.0), (ne t i), t.ne),
( (px 0.0, px 0.0), (nw t i), t.nw),
((px 0.0, px half),(sw t i), t.sw ),
((px half, px half), (se t i),t.se)
]
ne tile i = line (px (half)) (px (0.0-half))
ne tile i = line (px (half)) (px (half))
<@< { stroke = toSVGColor (if tile.ne activecol inactivecol)}
<@< { strokewidth = (px (strw))}
<@< { mask = (rect (px half) (px half) <@< {fill = toSVGColor "white"})}
nw tile i = line (px (full)) (px full)
nw tile i = line (px (half)) (px (0.0-half))
<@< { stroke = toSVGColor (if tile.nw activecol inactivecol)}
<@< { strokewidth = (px (strw))}
<@< { mask = (rect (px (half + (strw))) (px (half + (strw))) <@< {fill = toSVGColor "white"})}
sw tile i = line (px (half)) (px (half))
......@@ -84,7 +97,8 @@ sw tile i = line (px (half)) (px (half))
se tile i = line (px half) (px (0.0 - half))
<@< { stroke = toSVGColor (if tile.se activecol inactivecol)}
<@< { strokewidth = (px (toReal (strw)))}
<@< { mask = (rect (px half) (px half) <@< {fill = toSVGColor "white"})}
ns tile i = line (px 0.0) (px full)
<@< { stroke = toSVGColor (if tile.ns activecol inactivecol)}
......@@ -104,8 +118,46 @@ south tile i = circle (px (strw * 2.0))
Blocked -> toSVGColor "red"
_ -> toSVGColor "yellow" }
north tile i = circle (px (strw * 2.0))
// <@< { onclick = \span s.{s & tiles = (trace "f" updateAt i {tile & south = Middle} s.tiles ) } , local = False}
<@< { onclick = \span s.{s & tiles = (updateAt i {tile & north = Middle} s.tiles ) } , local = False}
<@< { opacity = if (drawNorth tile) (1.0) (0.0) }
<@< { strokewidth = if (drawNorth tile) (px 1.0) (px 0.0) }
<@< { fill = case tile.north of
Blocked -> toSVGColor "red"
_ -> toSVGColor "yellow" }
east tile i = circle (px (strw * 2.0))
// <@< { onclick = \span s.{s & tiles = (trace "f" updateAt i {tile & south = Middle} s.tiles ) } , local = False}
<@< { onclick = \span s.{s & tiles = (updateAt i {tile & east = Middle} s.tiles ) } , local = False}
<@< { opacity = if (drawEast tile) (1.0) (0.0) }
<@< { strokewidth = if (drawEast tile) (px 1.0) (px 0.0) }
<@< { fill = case tile.east of
Blocked -> toSVGColor "red"
_ -> toSVGColor "yellow" }
west tile i = circle (px (strw * 2.0))
// <@< { onclick = \span s.{s & tiles = (trace "f" updateAt i {tile & south = Middle} s.tiles ) } , local = False}
<@< { onclick = \span s.{s & tiles = (updateAt i {tile & west = Middle} s.tiles ) } , local = False}
<@< { opacity = if (drawWest tile) (1.0) (0.0) }
<@< { strokewidth = if (drawWest tile) (px 1.0) (px 0.0) }
<@< { fill = case tile.west of
Blocked -> toSVGColor "red"
_ -> toSVGColor "yellow" }
drawSouth :: Tile -> Bool
drawSouth t = (length (filter id [t.ns,t.se,t.sw])) >= 2
drawNorth :: Tile -> Bool
drawNorth t = (length (filter id [t.ns,t.ne,t.nw])) >= 2
drawEast :: Tile -> Bool
drawEast t = (length (filter id [t.ne,t.se,t.ew])) >= 2
drawWest :: Tile -> Bool
drawWest t = (length (filter id [t.nw,t.sw,t.ew])) >= 2
//case tile.south of
// Blocked -> toSVGColor "red"
// _ -> toSVGColor "yellow" }
......
......@@ -44,25 +44,23 @@ aList :: (Tile,Int) -> [(ImageOffset,Image State, Bool)]
aList (t,i) = [
( (px half, px 0.0) , (ns t i), t.ns ),
( (zero, px half), (ew t i), t.ew),
( (px 0.0, px 0.0), (ne t i), t.ne),
( (px half, px 0.0), (nw t i), t.nw),
( (px half, px 0.0), (ne t i), t.ne),
( (px 0.0, px 0.0), (nw t i), t.nw),
((px 0.0, px half),(sw t i), t.sw ),
((px half, px half), (se t i),t.se)
]
ne tile i = line (px (half)) (px (0.0-half))
ne tile i = line (px (half)) (px (half))
<@< { onclick = \span s.{s & tiles = (updateAt i {tile & ne = not tile.ne} s.tiles ) } , local = False}
<@< { stroke = toSVGColor (if tile.ne activecol inactivecol)}
<@< { strokewidth = (px (strw))}
<@< { mask = (rect (px half) (px half) <@< {fill = toSVGColor "white"})}
nw tile i = line (px (full)) (px full)
nw tile i = line (px (half)) (px (0.0-half))
<@< { onclick = \span s.{s & tiles = (updateAt i {tile & nw = not tile.nw} s.tiles ) } , local = False}
<@< { stroke = toSVGColor (if tile.nw activecol inactivecol)}
<@< { strokewidth = (px (strw))}
<@< { mask = (rect (px (half + (strw))) (px (half + (strw))) <@< {fill = toSVGColor "white"})}
sw tile i = line (px (half)) (px (half))
......@@ -75,7 +73,6 @@ se tile i = line (px half) (px (0.0 - half))
<@< { onclick = \span s.{s & tiles = (updateAt i {tile & se = not tile.se} s.tiles ) } , local = False}
<@< { stroke = toSVGColor (if tile.se activecol inactivecol)}
<@< { strokewidth = (px (toReal (strw)))}
<@< { mask = (rect (px half) (px half) <@< {fill = toSVGColor "white"})}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment