git-subtree-dir: dotscape git-subtree-mainline:6b91d64fc3git-subtree-split:f306501a68
55 lines
1.4 KiB
Standard ML
55 lines
1.4 KiB
Standard ML
signature FILE_THREAD =
|
|
sig
|
|
val run: FileMessage.t Mailbox.mbox * InputMessage.t Mailbox.mbox -> unit
|
|
end
|
|
|
|
structure FileThread :> FILE_THREAD =
|
|
struct
|
|
open FileMessage
|
|
open InputMessage
|
|
|
|
fun loadIO (io, str) =
|
|
case TextIO.inputLine io of
|
|
SOME line => loadIO (io, str ^ line)
|
|
| NONE => str
|
|
|
|
fun loadSquares (path, inputMailbox) =
|
|
let
|
|
val io = TextIO.openIn path
|
|
val str = loadIO (io, "")
|
|
val () = TextIO.closeIn io
|
|
in
|
|
case Parser.parse str of
|
|
SOME (canvasWidth, canvasHeight, tree) =>
|
|
Mailbox.send
|
|
( inputMailbox
|
|
, USE_LAYERS
|
|
{ tree = tree
|
|
, canvasWidth = canvasWidth
|
|
, canvasHeight = canvasHeight
|
|
}
|
|
)
|
|
| NONE => ()
|
|
end
|
|
|
|
fun saveString (filename, toSaveString) =
|
|
let
|
|
val io = TextIO.openOut filename
|
|
val () = TextIO.output (io, toSaveString)
|
|
in
|
|
TextIO.closeOut io
|
|
end
|
|
|
|
fun run (fileMailbox, inputMailbox) =
|
|
let
|
|
val _ =
|
|
case Mailbox.recv fileMailbox of
|
|
SAVE_SQUARES {filepath, output} => saveString (filepath, output)
|
|
| EXPORT_SQUARES {filepath, output} => saveString (filepath, output)
|
|
| EXPORT_COLLISIONS {filepath, output} => saveString (filepath, output)
|
|
| LOAD_SQUARES {filepath} => loadSquares (filepath, inputMailbox)
|
|
in
|
|
run (fileMailbox, inputMailbox)
|
|
end
|
|
end
|