progress towards saving export string in correct format (but note there is currently an exception somewhere because of changes; need to fix)
This commit is contained in:
@@ -46,6 +46,17 @@ struct
|
|||||||
foldl (f, right, acc)
|
foldl (f, right, acc)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
fun foldr (f, tree, acc) =
|
||||||
|
case tree of
|
||||||
|
LEAF => acc
|
||||||
|
| NODE {value, left, right, ...} =>
|
||||||
|
let
|
||||||
|
val acc = foldr (f, right, acc)
|
||||||
|
val acc = f (value, acc)
|
||||||
|
in
|
||||||
|
foldr (f, left, acc)
|
||||||
|
end
|
||||||
|
|
||||||
fun map (f, tree) =
|
fun map (f, tree) =
|
||||||
case tree of
|
case tree of
|
||||||
LEAF => LEAF
|
LEAF => LEAF
|
||||||
|
|||||||
@@ -16,6 +16,6 @@ layer ::= **[** item **]**
|
|||||||
layer_tree ::= int int **{** (layer)* **}**
|
layer_tree ::= int int **{** (layer)* **}**
|
||||||
```
|
```
|
||||||
|
|
||||||
The first two `int`s in the grid `int int **{** (item)+ **}**` always follow the order: `canvasWidth canvasHeight`.
|
The first two `int`s in the `layer_tree` always follow the order: `canvasWidth canvasHeight`.
|
||||||
|
|
||||||
The large number of `int`s in the `item` always follows the order: `x y ex ey r g b a`.
|
The large number of `int`s in the `item` always follow the order: `x y ex ey r g b a`.
|
||||||
|
|||||||
@@ -460,7 +460,7 @@ struct
|
|||||||
fun toSaveStringFolder ({x, ex, y, ey, data = {r, g, b, a}}, acc) =
|
fun toSaveStringFolder ({x, ex, y, ey, data = {r, g, b, a}}, acc) =
|
||||||
let
|
let
|
||||||
val item = String.concat
|
val item = String.concat
|
||||||
[ "{"
|
[ "["
|
||||||
, Int.toString x
|
, Int.toString x
|
||||||
, " "
|
, " "
|
||||||
, Int.toString y
|
, Int.toString y
|
||||||
@@ -476,20 +476,28 @@ struct
|
|||||||
, Int.toString b
|
, Int.toString b
|
||||||
, " "
|
, " "
|
||||||
, Int.toString a
|
, Int.toString a
|
||||||
, " } "
|
, " ] "
|
||||||
]
|
]
|
||||||
in
|
in
|
||||||
item :: acc
|
item :: acc
|
||||||
end
|
end
|
||||||
|
|
||||||
fun toSaveString (squares, canvasWidth, canvasHeight) =
|
fun toSaveStringTreeFolder size (grid, acc) =
|
||||||
|
let
|
||||||
|
val qtree = buildTree (0, 0, size, grid)
|
||||||
|
val bintree = merge (qtree, grid)
|
||||||
|
val str = BinTree.foldr (toSaveStringFolder, bintree, [])
|
||||||
|
in
|
||||||
|
String.concat str :: acc
|
||||||
|
end
|
||||||
|
|
||||||
|
fun toSaveString (layerTree, canvasWidth, canvasHeight) =
|
||||||
let
|
let
|
||||||
val size = Int.max (canvasWidth, canvasHeight)
|
val size = Int.max (canvasWidth, canvasHeight)
|
||||||
val qtree = buildTree (0, 0, size, squares)
|
val f = toSaveStringTreeFolder size
|
||||||
val bintree = merge (qtree, squares)
|
|
||||||
|
|
||||||
val initial = ["}"]
|
val initial = ["}"]
|
||||||
val acc = BinTree.foldr (toSaveStringFolder, bintree, initial)
|
val acc = LayerTree.foldr (f, layerTree, initial)
|
||||||
val acc =
|
val acc =
|
||||||
String.concat
|
String.concat
|
||||||
[Int.toString canvasWidth, " ", Int.toString canvasHeight, " { "]
|
[Int.toString canvasWidth, " ", Int.toString canvasHeight, " { "]
|
||||||
|
|||||||
Reference in New Issue
Block a user