diff --git a/dotscape b/dotscape index 69b03ea..953f346 100755 Binary files a/dotscape and b/dotscape differ diff --git a/fcore/common-update.sml b/fcore/common-update.sml index d51c285..a2544eb 100644 --- a/fcore/common-update.sml +++ b/fcore/common-update.sml @@ -10,7 +10,7 @@ struct fun getSaveSquaresMsg (model: app_type) = let val {canvasWidth, canvasHeight, squares, ...} = model - val str = CollisionTree.toString (squares, canvasWidth, canvasHeight) + val str = CollisionTree.toSaveString (squares, canvasWidth, canvasHeight) val msg = SAVE_SQUARES str in (model, [FILE msg]) @@ -19,9 +19,17 @@ struct fun getLoadSquaresMsg model = (model, [FILE LOAD_SQUARES]) - (* unimplemented *) - fun getExportSquaresMsg model = (model, []) + fun getExportSquaresMsg (model: app_type) = + let + val {squares, canvasWidth, canvasHeight, ...} = model + val exportString = + CollisionTree.toExportString (squares, canvasWidth, canvasHeight) + val msg = EXPORT_SQUARES exportString + in + (model, [FILE msg]) + end + (* unimplemented *) fun useSquaresInNormalMode (model, squares) = (model, []) fun squaresLoadError model = (model, []) diff --git a/fcore/quad-tree.sml b/fcore/quad-tree.sml index 7c652b9..1e58256 100644 --- a/fcore/quad-tree.sml +++ b/fcore/quad-tree.sml @@ -457,7 +457,7 @@ struct toBintree tree end - fun toStringFolder ({x, ex, y, ey, data = {r, g, b, a}}, acc) = + fun toSaveStringFolder ({x, ex, y, ey, data = {r, g, b, a}}, acc) = let val item = String.concat [ "{" @@ -482,14 +482,14 @@ struct item :: acc end - fun toString (squares, canvasWidth, canvasHeight) = + fun toSaveString (squares, canvasWidth, canvasHeight) = let val size = Int.max (canvasWidth, canvasHeight) val qtree = buildTree (0, 0, size, squares) val bintree = merge (qtree, squares) val initial = ["}"] - val acc = BinTree.foldr (toStringFolder, bintree, initial) + val acc = BinTree.foldr (toSaveStringFolder, bintree, initial) val acc = String.concat [Int.toString canvasWidth, " ", Int.toString canvasHeight, " { "] @@ -582,7 +582,7 @@ struct , " #[\n" ] - val footer = String.concat [" end\n", "end\n"] + val footer = String.concat [" ]\n", " end\n", "end\n"] in String.concat [header, coords, footer] end diff --git a/message-types/file-msg.sml b/message-types/file-msg.sml index 8a59384..aa359ef 100644 --- a/message-types/file-msg.sml +++ b/message-types/file-msg.sml @@ -3,7 +3,7 @@ struct datatype t = SAVE_SQUARES of string | LOAD_SQUARES - | EXPORT_SQUARES of int vector vector + | EXPORT_SQUARES of string | LOAD_FILES of string | SELECT_PATH of string end