initialise app with a file path, for the functionality of loading different files from the terminal
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
signature APP_INIT =
|
||||
sig
|
||||
val fromWindowWidthAndHeight: int * int * int * int -> AppType.app_type
|
||||
val fromWindowWidthAndHeight: int * int * int * int * string
|
||||
-> AppType.app_type
|
||||
end
|
||||
|
||||
structure AppInit :> APP_INIT =
|
||||
@@ -16,6 +17,7 @@ struct
|
||||
, hFinish
|
||||
, canvasWidth
|
||||
, canvasHeight
|
||||
, filepath
|
||||
) : app_type =
|
||||
let
|
||||
val (xClickPoints, yClickPoints) =
|
||||
@@ -38,7 +40,7 @@ struct
|
||||
, showGraph = true
|
||||
, arrowX = 0
|
||||
, arrowY = 0
|
||||
, openFilePath = ""
|
||||
, openFilePath = filepath
|
||||
, r = 0
|
||||
, g = 0
|
||||
, b = 0
|
||||
@@ -50,7 +52,7 @@ struct
|
||||
end
|
||||
|
||||
fun fromWindowWidthAndHeight
|
||||
(windowWidth, windowHeight, canvasWidth, canvasHeight) =
|
||||
(windowWidth, windowHeight, canvasWidth, canvasHeight, filepath) =
|
||||
if windowWidth > windowHeight then
|
||||
let
|
||||
val difference = windowWidth - windowHeight
|
||||
@@ -66,6 +68,7 @@ struct
|
||||
, windowHeight
|
||||
, canvasWidth
|
||||
, canvasHeight
|
||||
, filepath
|
||||
)
|
||||
end
|
||||
else
|
||||
@@ -83,6 +86,7 @@ struct
|
||||
, hFinish
|
||||
, canvasWidth
|
||||
, canvasHeight
|
||||
, filepath
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,13 +1,22 @@
|
||||
structure CollisionTree =
|
||||
struct
|
||||
local
|
||||
fun findLastDot (str, pos) =
|
||||
if pos < 0 then ~1
|
||||
else if String.sub (str, pos) = #"." then pos
|
||||
else findLastDot (str, pos - 1)
|
||||
fun findLastChr (str, pos, findChr) =
|
||||
if pos < 0 then ~1
|
||||
else if String.sub (str, pos) = findChr then pos
|
||||
else findLastChr (str, pos - 1, findChr)
|
||||
|
||||
fun extractFileName str =
|
||||
let
|
||||
val lastSlash = findLastChr (str, String.size str - 1, #"/")
|
||||
val strStart = lastSlash + 1
|
||||
in
|
||||
if lastSlash = ~1 then str
|
||||
else String.substring (str, strStart, String.size str - strStart)
|
||||
end
|
||||
|
||||
local
|
||||
fun removeFileExtension str =
|
||||
let val lastDot = findLastDot (str, String.size str - 1)
|
||||
let val lastDot = findLastChr (str, String.size str - 1, #".")
|
||||
in if lastDot = ~1 then str else String.substring (str, 0, lastDot)
|
||||
end
|
||||
|
||||
@@ -16,18 +25,25 @@ struct
|
||||
in String.implode acc
|
||||
end
|
||||
|
||||
(* convert from kebab-case or snake_case to PascalCase *)
|
||||
fun loop (#"-" :: chr :: tl, acc) =
|
||||
let val acc = Char.toUpper chr :: acc
|
||||
in loop (tl, acc)
|
||||
end
|
||||
| loop (#"_" :: chr :: tl, acc) =
|
||||
let val acc = Char.toUpper chr :: acc
|
||||
in loop (tl, acc)
|
||||
end
|
||||
| loop ([#"-"], acc) = finish acc
|
||||
| loop ([#"_"], acc) = finish acc
|
||||
| loop (chr :: tl, acc) =
|
||||
loop (tl, chr :: acc)
|
||||
| loop ([], acc) = finish acc
|
||||
in
|
||||
fun kebabCaseToPascalCase str =
|
||||
fun filenameToStructureName str =
|
||||
let
|
||||
val str = removeFileExtension str
|
||||
val str = extractFileName str
|
||||
in
|
||||
(* capitalise first character in string *)
|
||||
case String.explode str of
|
||||
|
||||
@@ -2,7 +2,7 @@ structure InitGlfw =
|
||||
struct
|
||||
open CML
|
||||
|
||||
fun init () =
|
||||
fun init path () =
|
||||
let
|
||||
(* Set up GLFW. *)
|
||||
val _ = Glfw.init ()
|
||||
@@ -20,6 +20,7 @@ struct
|
||||
, Constants.windowHeight
|
||||
, Constants.initialWidthClickPoints
|
||||
, Constants.initialHeightClickPoints
|
||||
, path
|
||||
)
|
||||
|
||||
val graphLines = GraphLines.generate initialModel
|
||||
@@ -59,6 +60,6 @@ struct
|
||||
()
|
||||
end
|
||||
|
||||
fun main () =
|
||||
(RunCML.doit (init, NONE); ())
|
||||
fun main path =
|
||||
(RunCML.doit (init path, NONE); ())
|
||||
end
|
||||
|
||||
@@ -3,7 +3,8 @@ struct
|
||||
fun main () =
|
||||
case CommandLine.arguments () of
|
||||
["-r"] => Converter.main ()
|
||||
| [] => InitGlfw.main ()
|
||||
| [filename] => InitGlfw.main filename
|
||||
| [] => print "error: no arguments\n"
|
||||
| args =>
|
||||
let
|
||||
val args = String.concatWith "" args
|
||||
|
||||
Reference in New Issue
Block a user