Add 'dotscape/' from commit 'f306501a68a51b634e895c5fdac70788ae899d75'
git-subtree-dir: dotscape git-subtree-mainline:6b91d64fc3git-subtree-split:f306501a68
This commit is contained in:
103
dotscape/fcore/common-update.sml
Normal file
103
dotscape/fcore/common-update.sml
Normal file
@@ -0,0 +1,103 @@
|
||||
structure CommonUpdate =
|
||||
struct
|
||||
open AppType
|
||||
|
||||
open DrawMessage
|
||||
open FileMessage
|
||||
open InputMessage
|
||||
open UpdateMessage
|
||||
|
||||
fun resizeWindow (model, width, height, dots) =
|
||||
let
|
||||
val
|
||||
{ canvasWidth
|
||||
, canvasHeight
|
||||
, showGraph
|
||||
, arrowX
|
||||
, arrowY
|
||||
, xClickPoints
|
||||
, yClickPoints
|
||||
, layerTree
|
||||
, ...
|
||||
} = model
|
||||
|
||||
val maxSide = Int.max (canvasWidth, canvasHeight)
|
||||
val squares = LayerTree.flatten (maxSide, layerTree)
|
||||
|
||||
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
|
||||
|
||||
fun getSaveSquaresMsg (model: app_type) =
|
||||
let
|
||||
val {layerTree, canvasWidth, canvasHeight, openFilePath, ...} = model
|
||||
val saveString =
|
||||
CollisionTree.toSaveString (layerTree, canvasWidth, canvasHeight)
|
||||
val msg = SAVE_SQUARES {output = saveString, filepath = openFilePath}
|
||||
in
|
||||
(model, [FILE msg])
|
||||
end
|
||||
|
||||
fun getLoadSquaresMsg (model: app_type) =
|
||||
let val msg = LOAD_SQUARES {filepath = #openFilePath model}
|
||||
in (model, [FILE msg])
|
||||
end
|
||||
|
||||
fun getExportSquaresMsg (model: app_type) =
|
||||
let
|
||||
val {layerTree, canvasWidth, canvasHeight, openFilePath, ...} = model
|
||||
|
||||
val maxSide = Int.max (canvasWidth, canvasHeight)
|
||||
val squares = LayerTree.flatten (maxSide, layerTree)
|
||||
|
||||
val exportString =
|
||||
CollisionTree.toExportString (squares, canvasWidth, canvasHeight, openFilePath)
|
||||
val msg = EXPORT_SQUARES {output = exportString, filepath = openFilePath}
|
||||
in
|
||||
(model, [FILE msg])
|
||||
end
|
||||
|
||||
fun getCollisionMsg (model: app_type) =
|
||||
let
|
||||
val {layerTree, canvasWidth, canvasHeight, modalNum, openFilePath, ...} =
|
||||
model
|
||||
|
||||
val maxSide = Int.max (canvasWidth, canvasHeight)
|
||||
val squares = LayerTree.flatten (maxSide, layerTree)
|
||||
|
||||
val exportString =
|
||||
CollisionTree.toCollisionString
|
||||
(squares, canvasWidth, canvasHeight, modalNum)
|
||||
|
||||
val exportFilePath = FileString.getCollisionFilename openFilePath
|
||||
val msg =
|
||||
EXPORT_COLLISIONS {output = exportString, filepath = exportFilePath}
|
||||
|
||||
val model = AppWith.modalNum (model, 0)
|
||||
in
|
||||
(model, [FILE msg])
|
||||
end
|
||||
|
||||
(* unimplemented *)
|
||||
fun useSquaresInNormalMode (model, squares) = (model, [])
|
||||
|
||||
fun squaresLoadError model = (model, [])
|
||||
end
|
||||
Reference in New Issue
Block a user