2025-07-06 14:45:20 +01:00
|
|
|
structure CommonUpdate =
|
|
|
|
|
struct
|
2025-07-12 06:03:59 +01:00
|
|
|
open AppType
|
|
|
|
|
|
|
|
|
|
open DrawMessage
|
|
|
|
|
open FileMessage
|
|
|
|
|
open InputMessage
|
|
|
|
|
open UpdateMessage
|
2025-07-06 14:45:20 +01:00
|
|
|
|
2025-08-09 07:17:48 +01:00
|
|
|
fun resizeWindow (model, width, height, dots) =
|
|
|
|
|
let
|
|
|
|
|
val
|
2025-08-09 10:19:26 +01:00
|
|
|
{ canvasWidth
|
2025-08-09 07:17:48 +01:00
|
|
|
, canvasHeight
|
|
|
|
|
, showGraph
|
|
|
|
|
, arrowX
|
|
|
|
|
, arrowY
|
|
|
|
|
, xClickPoints
|
|
|
|
|
, yClickPoints
|
2025-08-09 10:19:26 +01:00
|
|
|
, layerTree
|
2025-08-09 07:17:48 +01:00
|
|
|
, ...
|
|
|
|
|
} = model
|
2025-08-09 10:19:26 +01:00
|
|
|
|
2025-08-09 07:17:48 +01:00
|
|
|
val maxSide = Int.max (canvasWidth, canvasHeight)
|
2025-08-09 10:19:26 +01:00
|
|
|
val squares = LayerTree.flatten (maxSide, layerTree)
|
2025-08-09 07:17:48 +01:00
|
|
|
|
|
|
|
|
val squares = CollisionTree.toTriangles
|
|
|
|
|
( width
|
|
|
|
|
, height
|
|
|
|
|
, squares
|
|
|
|
|
, maxSide
|
|
|
|
|
, canvasWidth
|
|
|
|
|
, canvasHeight
|
|
|
|
|
, xClickPoints
|
|
|
|
|
, yClickPoints
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
val graphLines =
|
|
|
|
|
if showGraph then GraphLines.generate model else Vector.fromList []
|
|
|
|
|
|
|
|
|
|
val drawMsg =
|
|
|
|
|
RESIZE_SQUARES_DOTS_AND_GRAPH
|
|
|
|
|
{squares = squares, graphLines = graphLines, dots = dots}
|
|
|
|
|
val drawMsg = [DRAW drawMsg]
|
|
|
|
|
in
|
|
|
|
|
(model, drawMsg)
|
|
|
|
|
end
|
|
|
|
|
|
2025-07-12 06:03:59 +01:00
|
|
|
fun getSaveSquaresMsg (model: app_type) =
|
|
|
|
|
let
|
2025-08-26 16:15:40 +01:00
|
|
|
val {layerTree, canvasWidth, canvasHeight, openFilePath, ...} = model
|
|
|
|
|
val saveString =
|
2025-08-09 12:39:41 +01:00
|
|
|
CollisionTree.toSaveString (layerTree, canvasWidth, canvasHeight)
|
2025-08-26 16:15:40 +01:00
|
|
|
val msg = SAVE_SQUARES {output = saveString, filepath = openFilePath}
|
2025-08-09 12:39:41 +01:00
|
|
|
in
|
|
|
|
|
(model, [FILE msg])
|
2025-07-12 06:03:59 +01:00
|
|
|
end
|
|
|
|
|
|
2025-08-26 16:15:40 +01:00
|
|
|
fun getLoadSquaresMsg (model: app_type) =
|
|
|
|
|
let val msg = LOAD_SQUARES {filepath = #openFilePath model}
|
|
|
|
|
in (model, [FILE msg])
|
|
|
|
|
end
|
2025-07-06 14:45:20 +01:00
|
|
|
|
2025-07-12 19:16:36 +01:00
|
|
|
fun getExportSquaresMsg (model: app_type) =
|
|
|
|
|
let
|
2025-08-26 16:15:40 +01:00
|
|
|
val {layerTree, canvasWidth, canvasHeight, openFilePath, ...} = model
|
2025-08-09 10:19:26 +01:00
|
|
|
|
|
|
|
|
val maxSide = Int.max (canvasWidth, canvasHeight)
|
|
|
|
|
val squares = LayerTree.flatten (maxSide, layerTree)
|
|
|
|
|
|
2025-07-12 19:16:36 +01:00
|
|
|
val exportString =
|
|
|
|
|
CollisionTree.toExportString (squares, canvasWidth, canvasHeight)
|
2025-08-26 16:15:40 +01:00
|
|
|
val msg = EXPORT_SQUARES {output = exportString, filepath = openFilePath}
|
2025-07-12 19:16:36 +01:00
|
|
|
in
|
|
|
|
|
(model, [FILE msg])
|
|
|
|
|
end
|
2025-07-06 14:45:20 +01:00
|
|
|
|
2025-07-13 15:33:32 +01:00
|
|
|
fun getCollisionMsg (model: app_type) =
|
|
|
|
|
let
|
2025-08-26 16:15:40 +01:00
|
|
|
val {layerTree, canvasWidth, canvasHeight, modalNum, openFilePath, ...} =
|
|
|
|
|
model
|
2025-08-09 10:19:26 +01:00
|
|
|
|
|
|
|
|
val maxSide = Int.max (canvasWidth, canvasHeight)
|
|
|
|
|
val squares = LayerTree.flatten (maxSide, layerTree)
|
|
|
|
|
|
2025-07-13 15:33:32 +01:00
|
|
|
val exportString =
|
2025-07-30 07:28:37 +01:00
|
|
|
CollisionTree.toCollisionString
|
|
|
|
|
(squares, canvasWidth, canvasHeight, modalNum)
|
2025-08-26 16:15:40 +01:00
|
|
|
|
|
|
|
|
val exportFilePath = FileString.getCollisionFilename openFilePath
|
|
|
|
|
val msg =
|
|
|
|
|
EXPORT_COLLISIONS {output = exportString, filepath = exportFilePath}
|
2025-07-13 15:33:32 +01:00
|
|
|
|
|
|
|
|
val model = AppWith.modalNum (model, 0)
|
|
|
|
|
in
|
|
|
|
|
(model, [FILE msg])
|
|
|
|
|
end
|
|
|
|
|
|
2025-07-12 19:16:36 +01:00
|
|
|
(* unimplemented *)
|
2025-07-06 14:45:20 +01:00
|
|
|
fun useSquaresInNormalMode (model, squares) = (model, [])
|
|
|
|
|
|
|
|
|
|
fun squaresLoadError model = (model, [])
|
|
|
|
|
end
|