[Tile Drawer] Now supports undo.

This commit is contained in:
Tanasart 2025-01-02 14:54:31 +07:00
parent 8afa1f3899
commit a4429fbe32
7 changed files with 30 additions and 17 deletions

View file

@ -451,10 +451,9 @@
{"name":"__shapes","order":3,"path":"scripts/__shapes/__shapes.yy",},
{"name":"__strandSim","order":2,"path":"scripts/__strandSim/__strandSim.yy",},
{"name":"__surface","order":7,"path":"scripts/__surface/__surface.yy",},
{"name":"__tiler_animated","order":1,"path":"scripts/__tiler_animated/__tiler_animated.yy",},
{"name":"__tiler_autoterrain","order":6,"path":"scripts/__tiler_autoterrain/__tiler_autoterrain.yy",},
{"name":"__tiler_brush","order":2,"path":"scripts/__tiler_brush/__tiler_brush.yy",},
{"name":"__tiler_rule","order":7,"path":"scripts/__tiler_rule/__tiler_rule.yy",},
{"name":"__tiler_autoterrain","order":1,"path":"scripts/__tiler_autoterrain/__tiler_autoterrain.yy",},
{"name":"__tiler_brush","order":3,"path":"scripts/__tiler_brush/__tiler_brush.yy",},
{"name":"__tiler_rule","order":4,"path":"scripts/__tiler_rule/__tiler_rule.yy",},
{"name":"__tiler_tool","order":2,"path":"scripts/__tiler_tool/__tiler_tool.yy",},
{"name":"__vec2","order":7,"path":"scripts/__vec2/__vec2.yy",},
{"name":"__vec3","order":8,"path":"scripts/__vec3/__vec3.yy",},
@ -1406,11 +1405,11 @@
{"name":"textBox","order":2,"path":"scripts/textBox/textBox.yy",},
{"name":"textInput","order":3,"path":"scripts/textInput/textInput.yy",},
{"name":"theme_definition","order":14,"path":"scripts/theme_definition/theme_definition.yy",},
{"name":"tiler_tool_brush_shape","order":4,"path":"scripts/tiler_tool_brush_shape/tiler_tool_brush_shape.yy",},
{"name":"tiler_tool_brush","order":2,"path":"scripts/tiler_tool_brush/tiler_tool_brush.yy",},
{"name":"tiler_tool_fill","order":3,"path":"scripts/tiler_tool_fill/tiler_tool_fill.yy",},
{"name":"tiler_tool_selection_shape","order":6,"path":"scripts/tiler_tool_selection_shape/tiler_tool_selection_shape.yy",},
{"name":"tiler_tool_selection","order":5,"path":"scripts/tiler_tool_selection/tiler_tool_selection.yy",},
{"name":"tiler_tool_brush_shape","order":7,"path":"scripts/tiler_tool_brush_shape/tiler_tool_brush_shape.yy",},
{"name":"tiler_tool_brush","order":5,"path":"scripts/tiler_tool_brush/tiler_tool_brush.yy",},
{"name":"tiler_tool_fill","order":6,"path":"scripts/tiler_tool_fill/tiler_tool_fill.yy",},
{"name":"tiler_tool_selection_shape","order":9,"path":"scripts/tiler_tool_selection_shape/tiler_tool_selection_shape.yy",},
{"name":"tiler_tool_selection","order":8,"path":"scripts/tiler_tool_selection/tiler_tool_selection.yy",},
{"name":"tilesetBox","order":1,"path":"scripts/tilesetBox/tilesetBox.yy",},
{"name":"time_source","order":43,"path":"scripts/time_source/time_source.yy",},
{"name":"timeline_data","order":18,"path":"scripts/timeline_data/timeline_data.yy",},

View file

@ -1,6 +1,6 @@
function tiler_tool(node) constructor {
self.node = node;
subtool = 0;
function tiler_tool(_node) constructor {
node = _node;
subtool = 0;
brush_resizable = true;
apply_draw_surface = noone;

View file

@ -118,6 +118,16 @@ function Node_Tile_Drawer(_x, _y, _group = noone) : Node_Processor(_x, _y, _grou
triggerRender();
}
static storeAction = function() {
var action = recordAction(ACTION_TYPE.custom, function(data) {
var _canvas = surface_clone(canvas_surface);
canvas_surface = data.surface;
data.surface = _canvas;
triggerRender();
}, { surface: surface_clone(canvas_surface), tooltip: "Modify tilemap" });
}
function reset_surface(surface) {
surface_set_shader(surface, noone, true, BLEND.over);
draw_surface(canvas_surface, 0, 0);

View file

@ -1,4 +1,4 @@
function tiler_tool_brush(node, _brush, eraser = false) : tiler_tool(node) constructor {
function tiler_tool_brush(_node, _brush, eraser = false) : tiler_tool(_node) constructor {
self.brush = _brush;
isEraser = eraser;
brush_resizable = true;
@ -51,6 +51,7 @@ function tiler_tool_brush(node, _brush, eraser = false) : tiler_tool(node) const
}
if(mouse_press(mb_left, active)) {
node.storeAction();
surface_set_target(drawing_surface);
tiler_draw_point_brush(brush, mouse_cur_x, mouse_cur_y);

View file

@ -1,4 +1,4 @@
function tiler_tool_shape(node, _brush, _shape) : tiler_tool(node) constructor {
function tiler_tool_shape(_node, _brush, _shape) : tiler_tool(_node) constructor {
self.brush = _brush;
self.shape = _shape;
@ -54,6 +54,7 @@ function tiler_tool_shape(node, _brush, _shape) : tiler_tool(node) constructor {
mouse_pre_x = mouse_cur_x;
mouse_pre_y = mouse_cur_y;
node.storeAction();
mouse_holding = true;
}

View file

@ -1,4 +1,4 @@
function tiler_tool_fill(node, _brush, toolAttr) : tiler_tool(node) constructor {
function tiler_tool_fill(_node, _brush, toolAttr) : tiler_tool(_node) constructor {
self.brush = _brush;
self.tool_attribute = toolAttr;
@ -18,12 +18,14 @@ function tiler_tool_fill(node, _brush, toolAttr) : tiler_tool(node) constructor
var _auto = brush.autoterrain;
if(mouse_press(mb_left, active) && point_in_rectangle(mouse_cur_x, mouse_cur_y, 0, 0, surface_w - 1, surface_h - 1)) {
node.storeAction();
surface_set_target(drawing_surface);
tiler_flood_fill_scanline(drawing_surface, mouse_cur_x, mouse_cur_y, brush, tool_attribute.fillType);
surface_reset_target();
if(_auto != noone) {
_auto.drawing_start(drawing_surface, isEraser);
_auto.drawing_start(drawing_surface);
tiler_flood_fill_scanline(drawing_surface, mouse_cur_x, mouse_cur_y, brush, tool_attribute.fillType);
_auto.drawing_end();
}

View file

@ -1,3 +1,3 @@
function tiler_tool_selection(node) : tiler_tool(node) constructor {
function tiler_tool_selection(_node) : tiler_tool(_node) constructor {
}