save grid to custom format
This commit is contained in:
@@ -1,8 +1,22 @@
|
|||||||
structure CommonUpdate =
|
structure CommonUpdate =
|
||||||
struct
|
struct
|
||||||
(* unimplemented *)
|
open AppType
|
||||||
fun getSaveSquaresMsg model = (model, [])
|
|
||||||
|
|
||||||
|
open DrawMessage
|
||||||
|
open FileMessage
|
||||||
|
open InputMessage
|
||||||
|
open UpdateMessage
|
||||||
|
|
||||||
|
fun getSaveSquaresMsg (model: app_type) =
|
||||||
|
let
|
||||||
|
val {canvasWidth, canvasHeight, squares, ...} = model
|
||||||
|
val str = CollisionTree.toString (squares, canvasWidth, canvasHeight)
|
||||||
|
val msg = SAVE_SQUARES str
|
||||||
|
in
|
||||||
|
(model, [FILE msg])
|
||||||
|
end
|
||||||
|
|
||||||
|
(* unimplemented *)
|
||||||
fun getLoadSquaresMsg model = (model, [])
|
fun getLoadSquaresMsg model = (model, [])
|
||||||
|
|
||||||
fun getExportSquaresMsg model = (model, [])
|
fun getExportSquaresMsg model = (model, [])
|
||||||
|
|||||||
@@ -526,13 +526,19 @@ struct
|
|||||||
item :: acc
|
item :: acc
|
||||||
end
|
end
|
||||||
|
|
||||||
fun toString (squares, size) =
|
fun toString (squares, canvasWidth, canvasHeight) =
|
||||||
let
|
let
|
||||||
|
val size = Int.max (canvasWidth, canvasHeight)
|
||||||
val qtree = buildTree (0, 0, size, squares)
|
val qtree = buildTree (0, 0, size, squares)
|
||||||
val bintree = merge (qtree, squares)
|
val bintree = merge (qtree, squares)
|
||||||
|
|
||||||
val vec = BinTree.foldr (toStringFolder, bintree, [])
|
val initial = ["}"]
|
||||||
|
val acc = BinTree.foldr (toStringFolder, bintree, initial)
|
||||||
|
val acc =
|
||||||
|
String.concat
|
||||||
|
[Int.toString canvasWidth, " ", Int.toString canvasHeight, " { "]
|
||||||
|
:: acc
|
||||||
in
|
in
|
||||||
Vector.concat vec
|
String.concat acc
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -51,7 +51,13 @@ struct
|
|||||||
|
|
||||||
fun loadSquares (path, inputMailbox) = ()
|
fun loadSquares (path, inputMailbox) = ()
|
||||||
|
|
||||||
fun saveSquares squares = ()
|
fun saveSquares squaresString =
|
||||||
|
let
|
||||||
|
val io = TextIO.openOut filename
|
||||||
|
val () = TextIO.output (io, squaresString)
|
||||||
|
in
|
||||||
|
TextIO.closeOut io
|
||||||
|
end
|
||||||
|
|
||||||
fun getDirList (dir, acc, rootPath) =
|
fun getDirList (dir, acc, rootPath) =
|
||||||
case OS.FileSys.readDir dir of
|
case OS.FileSys.readDir dir of
|
||||||
@@ -87,7 +93,7 @@ struct
|
|||||||
let
|
let
|
||||||
val _ =
|
val _ =
|
||||||
case Mailbox.recv fileMailbox of
|
case Mailbox.recv fileMailbox of
|
||||||
SAVE_SQUARES triangles => saveSquares triangles
|
SAVE_SQUARES str => saveSquares str
|
||||||
| LOAD_SQUARES => loadSquares (filename, inputMailbox)
|
| LOAD_SQUARES => loadSquares (filename, inputMailbox)
|
||||||
| EXPORT_SQUARES triangles => exportSquares triangles
|
| EXPORT_SQUARES triangles => exportSquares triangles
|
||||||
| LOAD_FILES path => loadFiles (path, inputMailbox)
|
| LOAD_FILES path => loadFiles (path, inputMailbox)
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
structure FileMessage =
|
structure FileMessage =
|
||||||
struct
|
struct
|
||||||
datatype t =
|
datatype t =
|
||||||
SAVE_SQUARES of int vector vector
|
SAVE_SQUARES of string
|
||||||
| LOAD_SQUARES
|
| LOAD_SQUARES
|
||||||
| EXPORT_SQUARES of int vector vector
|
| EXPORT_SQUARES of int vector vector
|
||||||
| LOAD_FILES of string
|
| LOAD_FILES of string
|
||||||
|
|||||||
Reference in New Issue
Block a user