1
0
Fork 0
mirror of https://github.com/Orama-Interactive/Pixelorama.git synced 2025-01-19 09:39:48 +00:00

Experimental undo redo for tileset tiles

This commit is contained in:
Emmanouil Papadeas 2024-11-26 16:41:24 +02:00
parent ad919a2a10
commit a10a0a9bda
2 changed files with 28 additions and 0 deletions

View file

@ -398,6 +398,26 @@ func on_undo_redo(undo: bool) -> void:
update_tileset(undo) 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: func serialize() -> Dictionary:
var dict := super.serialize() var dict := super.serialize()
var tile_indices := [] var tile_indices := []

View file

@ -282,6 +282,12 @@ func commit_undo() -> void:
project.undos += 1 project.undos += 1
Global.undo_redo_compress_images(redo_data, _undo_data, project) 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_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.add_undo_method(Global.undo_or_redo.bind(true, frame, layer))
project.undo_redo.commit_action() project.undo_redo.commit_action()
@ -762,6 +768,8 @@ func _get_undo_data() -> Dictionary:
continue continue
var image := (cel as PixelCel).get_image() var image := (cel as PixelCel).get_image()
image.add_data_to_dictionary(data) image.add_data_to_dictionary(data)
if cel is CelTileMap:
data[cel] = (cel as CelTileMap).serialize_undo_data()
return data return data