diff --git a/src/Classes/Cels/CelTileMap.gd b/src/Classes/Cels/CelTileMap.gd index 8e7638420..73af2e2ba 100644 --- a/src/Classes/Cels/CelTileMap.gd +++ b/src/Classes/Cels/CelTileMap.gd @@ -398,6 +398,26 @@ func on_undo_redo(undo: bool) -> void: update_tileset(undo) +func serialize_undo_data() -> Dictionary: + var dict := {} + var indices_serialized := [] + indices_serialized.resize(indices.size()) + for i in indices.size(): + indices_serialized[i] = indices[i].serialize() + dict["tiles_data"] = indices_serialized + return dict + + +func deserialize_undo_data(dict: Dictionary, undo_redo: UndoRedo, undo: bool) -> void: + var tiles_data = dict["tiles_data"] + for i in tiles_data.size(): + var tile_data: Dictionary = tiles_data[i] + if undo: + undo_redo.add_undo_method(indices[i].deserialize.bind(tile_data)) + else: + undo_redo.add_do_method(indices[i].deserialize.bind(tile_data)) + + func serialize() -> Dictionary: var dict := super.serialize() var tile_indices := [] diff --git a/src/Tools/BaseDraw.gd b/src/Tools/BaseDraw.gd index 64d3f973b..f333de2cc 100644 --- a/src/Tools/BaseDraw.gd +++ b/src/Tools/BaseDraw.gd @@ -282,6 +282,12 @@ func commit_undo() -> void: project.undos += 1 Global.undo_redo_compress_images(redo_data, _undo_data, project) + for cel in redo_data: + if cel is CelTileMap: + (cel as CelTileMap).deserialize_undo_data(redo_data[cel], project.undo_redo, false) + for cel in _undo_data: + if cel is CelTileMap: + (cel as CelTileMap).deserialize_undo_data(_undo_data[cel], project.undo_redo, true) project.undo_redo.add_do_method(Global.undo_or_redo.bind(false, frame, layer)) project.undo_redo.add_undo_method(Global.undo_or_redo.bind(true, frame, layer)) project.undo_redo.commit_action() @@ -762,6 +768,8 @@ func _get_undo_data() -> Dictionary: continue var image := (cel as PixelCel).get_image() image.add_data_to_dictionary(data) + if cel is CelTileMap: + data[cel] = (cel as CelTileMap).serialize_undo_data() return data