begin creating a string for collision data
This commit is contained in:
@@ -548,12 +548,36 @@ struct
|
|||||||
|
|
||||||
(* based on triangle order formed by `Ndc.ltrbToVertexRgb` function *)
|
(* based on triangle order formed by `Ndc.ltrbToVertexRgb` function *)
|
||||||
val item = String.concatWith ",\n"
|
val item = String.concatWith ",\n"
|
||||||
[ x, ey, r, g, b
|
[ x
|
||||||
, ex, ey, r, g, b
|
, ey
|
||||||
, x, y, r, g, b
|
, r
|
||||||
, x, y, r, g, b
|
, g
|
||||||
, ex, ey, r, g, b
|
, b
|
||||||
, ex, y, r, g, b
|
, ex
|
||||||
|
, ey
|
||||||
|
, r
|
||||||
|
, g
|
||||||
|
, b
|
||||||
|
, x
|
||||||
|
, y
|
||||||
|
, r
|
||||||
|
, g
|
||||||
|
, b
|
||||||
|
, x
|
||||||
|
, y
|
||||||
|
, r
|
||||||
|
, g
|
||||||
|
, b
|
||||||
|
, ex
|
||||||
|
, ey
|
||||||
|
, r
|
||||||
|
, g
|
||||||
|
, b
|
||||||
|
, ex
|
||||||
|
, y
|
||||||
|
, r
|
||||||
|
, g
|
||||||
|
, b
|
||||||
]
|
]
|
||||||
in
|
in
|
||||||
item :: acc
|
item :: acc
|
||||||
@@ -598,4 +622,25 @@ struct
|
|||||||
, "end\n"
|
, "end\n"
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
(* functions for exporting a collision detection string *)
|
||||||
|
fun mapItem (item as {r, g, b, a}) =
|
||||||
|
if shouldIgnoreData item then item else {r = 1, g = 1, b = 1, a = 1}
|
||||||
|
|
||||||
|
fun mapGrid grid =
|
||||||
|
Vector.map (fn yAxis => Vector.map (fn item => mapItem item) yAxis) grid
|
||||||
|
|
||||||
|
fun toCollisionStringFolder ({x, ex, y, ey, data = _}, acc) =
|
||||||
|
let
|
||||||
|
val ex = if x = ex then ex + 1 else ex
|
||||||
|
val ey = if y = ey then ey + 1 else ey
|
||||||
|
|
||||||
|
fun toCollisionString (squares, canvasWidth, canvasHeight) =
|
||||||
|
let
|
||||||
|
val size = Int.max (canvasWidth, canvasHeight)
|
||||||
|
val qtree = buildTree (0, 0, size, squares)
|
||||||
|
val bintree = merge (qtree, squares)
|
||||||
|
|
||||||
|
val collisions = BinTree.foldr (toExportStringFolder, bintree, [])
|
||||||
|
val collisions = String.concatWith ",\n" coords
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user