mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-01-19 01:29:49 +00:00
Experimental undo redo for tileset tiles
This commit is contained in:
parent
ad919a2a10
commit
a10a0a9bda
|
@ -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 := []
|
||||
|
|
|
@ -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
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue