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:
2025-08-09 11:56:18 +01:00
parent 99a47a410f
commit d6f7583273
4 changed files with 27 additions and 8 deletions

BIN
dotscape

Binary file not shown.

View File

@@ -46,6 +46,17 @@ struct
foldl (f, right, acc)
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) =
case tree of
LEAF => LEAF

View File

@@ -16,6 +16,6 @@ layer ::= **[** item **]**
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`.

View File

@@ -460,7 +460,7 @@ struct
fun toSaveStringFolder ({x, ex, y, ey, data = {r, g, b, a}}, acc) =
let
val item = String.concat
[ "{"
[ "["
, Int.toString x
, " "
, Int.toString y
@@ -476,20 +476,28 @@ struct
, Int.toString b
, " "
, Int.toString a
, " } "
, " ] "
]
in
item :: acc
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
val size = Int.max (canvasWidth, canvasHeight)
val qtree = buildTree (0, 0, size, squares)
val bintree = merge (qtree, squares)
val f = toSaveStringTreeFolder size
val initial = ["}"]
val acc = BinTree.foldr (toSaveStringFolder, bintree, initial)
val acc = LayerTree.foldr (f, layerTree, initial)
val acc =
String.concat
[Int.toString canvasWidth, " ", Int.toString canvasHeight, " { "]