done with implementing conversion of each .dsc file in a directory, to an .sml export string (may need to adapt later)
This commit is contained in:
@@ -1,5 +1,35 @@
|
|||||||
structure Converter =
|
structure Converter =
|
||||||
struct
|
struct
|
||||||
|
fun loadIO (io, str) =
|
||||||
|
case TextIO.inputLine io of
|
||||||
|
SOME line => loadIO (io, str ^ line)
|
||||||
|
| NONE => str
|
||||||
|
|
||||||
|
fun convertFile fullPath =
|
||||||
|
let
|
||||||
|
val io = TextIO.openIn fullPath
|
||||||
|
val text = loadIO (io, "")
|
||||||
|
val () = TextIO.closeIn io
|
||||||
|
in
|
||||||
|
case Parser.parse text of
|
||||||
|
SOME (canvasWidth, canvasHeight, tree) =>
|
||||||
|
let
|
||||||
|
val maxSide = Int.max (canvasWidth, canvasHeight)
|
||||||
|
val squares = LayerTree.flatten (maxSide, tree)
|
||||||
|
val exportString =
|
||||||
|
CollisionTree.toExportString (squares, canvasWidth, canvasHeight)
|
||||||
|
|
||||||
|
val pathWithoutExtension = String.substring
|
||||||
|
(fullPath, 0, String.size fullPath - 4)
|
||||||
|
val outputFilePath = pathWithoutExtension ^ ".sml"
|
||||||
|
val io = TextIO.openOut outputFilePath
|
||||||
|
val () = TextIO.output (io, exportString)
|
||||||
|
in
|
||||||
|
TextIO.closeOut io
|
||||||
|
end
|
||||||
|
| NONE => (* we have an error, but ignore *) ()
|
||||||
|
end
|
||||||
|
|
||||||
fun endsWithDsc str =
|
fun endsWithDsc str =
|
||||||
if String.size str >= 4 then
|
if String.size str >= 4 then
|
||||||
let
|
let
|
||||||
@@ -11,14 +41,11 @@ struct
|
|||||||
else
|
else
|
||||||
false
|
false
|
||||||
|
|
||||||
fun convertFile path = ()
|
|
||||||
|
|
||||||
fun loop (dir, rootPath) =
|
fun loop (dir, rootPath) =
|
||||||
case OS.FileSys.readDir dir of
|
case OS.FileSys.readDir dir of
|
||||||
SOME path =>
|
SOME path =>
|
||||||
let
|
let
|
||||||
val folderPath = String.concat [rootPath, "/", path]
|
val folderPath = String.concat [rootPath, "/", path]
|
||||||
val () = print (folderPath ^ "\n")
|
|
||||||
val () =
|
val () =
|
||||||
if OS.FileSys.isDir folderPath then
|
if OS.FileSys.isDir folderPath then
|
||||||
(* handle recursive directory *)
|
(* handle recursive directory *)
|
||||||
|
|||||||
Reference in New Issue
Block a user