diff --git a/dotscape b/dotscape index f2c5a15..864c3a9 100755 Binary files a/dotscape and b/dotscape differ diff --git a/fcore/app-with.sml b/fcore/app-with.sml index a1cade8..f52d8f9 100644 --- a/fcore/app-with.sml +++ b/fcore/app-with.sml @@ -1011,8 +1011,8 @@ struct , yClickPoints , windowWidth , windowHeight - , arrowX = _ - , arrowY = _ + , arrowX + , arrowY , canvasWidth = _ , canvasHeight = _ @@ -1028,9 +1028,6 @@ struct , layerTree = _ , modalNum } = app - - val arrowX = 0 - val arrowY = 0 in { mode = mode , mouseX = mouseX diff --git a/fcore/common-update.sml b/fcore/common-update.sml index 416a79f..98f6ec5 100644 --- a/fcore/common-update.sml +++ b/fcore/common-update.sml @@ -48,12 +48,12 @@ struct fun getSaveSquaresMsg (model: app_type) = let - (* todo: reimplement, saving each layer to a different line - val {canvasWidth, canvasHeight, squares, ...} = model - val str = CollisionTree.toSaveString (squares, canvasWidth, canvasHeight) - val msg = SAVE_SQUARES str - *) - in raise Fail "todo common-update.sml: reimplement saving" + val {layerTree, canvasWidth, canvasHeight, ...} = model + val str = + CollisionTree.toSaveString (layerTree, canvasWidth, canvasHeight) + val msg = SAVE_SQUARES str + in + (model, [FILE msg]) end fun getLoadSquaresMsg model = diff --git a/fcore/parser/parser.sml b/fcore/parser/parser.sml index 7c5707c..fe46950 100644 --- a/fcore/parser/parser.sml +++ b/fcore/parser/parser.sml @@ -2,7 +2,7 @@ structure Parser = struct structure T = Tokens - fun parseItems (tokens, grid) = + fun parseItem (tokens, grid) = case tokens of T.L_BRACE :: T.INT x :: @@ -14,27 +14,48 @@ struct val colour = {r = r, g = g, b = b, a = a} val grid = ParseGrid.applyItem (grid, x, y, ex, ey, colour) in - parseItems (tl, grid) + SOME (tl, grid) end - | _ => SOME (tokens, grid) + | _ => NONE + + (* note to be careful of: + * - startParseItems returns NONE if there are no items found, + * because we have not found a single item yet. + * + * - loopParseItems returns SOME if there are no items found, + * because this function is called after we have parsed at least one item. + * *) + fun loopParseItems (tokens, grid) = + case parseItem (tokens, grid) of + SOME (tokens, grid) => loopParseItems (tokens, grid) + | NONE => SOME (tokens, grid) + + fun startParseItems (tokens, grid) = + case parseItem (tokens, grid) of + SOME (tokens, grid) => loopParseItems (tokens, grid) + | NONE => NONE fun parseLayers (tokens, canvasWidth, canvasHeight, tree, counter) = - let - val grid = ParseGrid.make (canvasWidth, canvasHeight) - in - case parseItems (tokens, grid) of - SOME (tokens, grid) => - let val tree = LayerTree.insert (counter, grid, tree) - in parseLayers (tokens, canvasWidth, canvasHeight, tree, counter + 1) - end - | NONE => (tokens, tree) - end + case tokens of + T.L_BRACKET :: tl => + let + val grid = ParseGrid.make (canvasWidth, canvasHeight) + in + case startParseItems (tl, grid) of + SOME (T.R_BRACKET :: tl, grid) => + let val tree = LayerTree.insert (counter, grid, tree) + in parseLayers (tl, canvasWidth, canvasHeight, tree, counter + 1) + end + | SOME _ => NONE + | NONE => (tokens, tree) + end + | _ => (tokens, tree) fun parse string = case Lexer.scan string of SOME tokens => (case tokens of - T.INT canvasWidth :: T.INT canvasHeight :: tl => + T.INT canvasWidth :: T.INT canvasHeight :: T.L_BRACE :: tl => let val maxSide = Int.max (canvasWidth, canvasHeight) val tree = LayerTree.init maxSide diff --git a/fcore/quad-tree.sml b/fcore/quad-tree.sml index aaf7aef..c7dca00 100644 --- a/fcore/quad-tree.sml +++ b/fcore/quad-tree.sml @@ -460,7 +460,7 @@ struct fun toSaveStringFolder ({x, ex, y, ey, data = {r, g, b, a}}, acc) = let val item = String.concat - [ "[" + [ " { " , Int.toString x , " " , Int.toString y @@ -476,7 +476,7 @@ struct , Int.toString b , " " , Int.toString a - , " ] " + , " } " ] in item :: acc @@ -486,9 +486,11 @@ struct let val qtree = buildTree (0, 0, size, grid) val bintree = merge (qtree, grid) - val str = BinTree.foldr (toSaveStringFolder, bintree, []) + val coords = BinTree.foldr (toSaveStringFolder, bintree, []) + val coords = String.concat coords + val str = " [ " ^ coords ^ " ] " in - String.concat str :: acc + str :: acc end fun toSaveString (layerTree, canvasWidth, canvasHeight) = @@ -496,7 +498,7 @@ struct val size = Int.max (canvasWidth, canvasHeight) val f = toSaveStringTreeFolder size - val initial = ["}"] + val initial = ["}\n"] val acc = LayerTree.foldr (f, layerTree, initial) val acc = String.concat diff --git a/green.dsc b/green.dsc new file mode 100644 index 0000000..e85856a --- /dev/null +++ b/green.dsc @@ -0,0 +1 @@ +4 4 { [ { 0 0 0 0 33 0 0 1 } ] [ { 1 1 1 1 33 0 99 1 } ] }