From 0cd8fa7ddf9cb63b1b4c1006642e91fabaaebfa1 Mon Sep 17 00:00:00 2001 From: OverloadedOrama <35376950+OverloadedOrama@users.noreply.github.com> Date: Sat, 9 May 2020 03:51:23 +0300 Subject: [PATCH] Fixes critical bug with saving projects that contained linked cels It used to save the linked cel array which contained the canvas nodes into the .pxo. This, however, does not make sense, because the canvas nodes are being recreated when a .pxo is loaded. Therefore, they are different nodes than they used to be. Now, an array containing the frame numbers which have cels linked for each frame is being saved and loaded into the pxo. --- Changelog.md | 2 +- src/Autoload/Global.gd | 2 +- src/Autoload/OpenSave.gd | 22 ++++++++++++++++------ src/Canvas.gd | 8 +++++--- src/UI/Dialogs/AboutDialog.gd | 1 + 5 files changed, 24 insertions(+), 11 deletions(-) diff --git a/Changelog.md b/Changelog.md index 4b95d52c6..f18b628ed 100644 --- a/Changelog.md +++ b/Changelog.md @@ -8,7 +8,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). This update has been brought to you by the contributions of: Martin Novák (novhack), Darshan Phaldesai (luiq54), Schweini07, Marco Galli (Gaarco), Matheus Pesegoginski (MatheusPese), -sapient-cogbag, Kinwailo, Igor Santarek (jegor377), Dávid Gábor BODOR (dragonfi) +sapient-cogbag, Kinwailo, Igor Santarek (jegor377), Dávid Gábor BODOR (dragonfi), John Jerome Romero (Wishdream) ### Added - Cels are now in the timeline. Each cel refers to a specific layer AND a frame. Frames are a collection of cels for every layer. diff --git a/src/Autoload/Global.gd b/src/Autoload/Global.gd index a33779517..14fa37738 100644 --- a/src/Autoload/Global.gd +++ b/src/Autoload/Global.gd @@ -402,7 +402,7 @@ func _ready() -> void: error_dialog = find_node_by_name(root, "ErrorDialog") # Store [Layer name (0), Layer visibility boolean (1), Layer lock boolean (2), Frame container (3), - # will new frames be linked boolean (4), Array of linked frames (5)] + # will new cels be linked boolean (4), Array of linked cels (5)] layers.append([tr("Layer") + " 0", true, false, HBoxContainer.new(), false, []]) diff --git a/src/Autoload/OpenSave.gd b/src/Autoload/OpenSave.gd index b91df1a74..db4d2b73c 100644 --- a/src/Autoload/OpenSave.gd +++ b/src/Autoload/OpenSave.gd @@ -38,18 +38,19 @@ func open_pxo_file(path : String, untitled_backup : bool = false) -> void: var frame := 0 Global.layers.clear() + var linked_cels := [] if file_major_version >= 0 and file_minor_version > 6: var global_layer_line := file.get_line() while global_layer_line == ".": var layer_name := file.get_line() var layer_visibility := file.get_8() var layer_lock := file.get_8() - var layer_new_frames_linked := file.get_8() - var linked_frames = file.get_var() + var layer_new_cels_linked := file.get_8() + linked_cels.append(file.get_var()) # Store [Layer name (0), Layer visibility boolean (1), Layer lock boolean (2), Frame container (3), - # will new frames be linked boolean (4), Array of linked frames (5)] - Global.layers.append([layer_name, layer_visibility, layer_lock, HBoxContainer.new(), layer_new_frames_linked, linked_frames]) + # will new cels be linked boolean (4), Array of linked cels (5)] + Global.layers.append([layer_name, layer_visibility, layer_lock, HBoxContainer.new(), layer_new_cels_linked, []]) global_layer_line = file.get_line() var frame_line := file.get_line() @@ -60,6 +61,7 @@ func open_pxo_file(path : String, untitled_backup : bool = false) -> void: var width := file.get_16() var height := file.get_16() + var layer_i := 0 var layer_line := file.get_line() while layer_line == "-": # Load layers var buffer := file.get_buffer(width * height * 4) @@ -78,6 +80,10 @@ func open_pxo_file(path : String, untitled_backup : bool = false) -> void: var tex := ImageTexture.new() tex.create_from_image(image, 0) canvas.layers.append([image, tex, layer_transparency]) + if frame in linked_cels[layer_i]: + Global.layers[layer_i][5].append(canvas) + + layer_i += 1 layer_line = file.get_line() var guide_line := file.get_line() # "guideline" no pun intended @@ -168,8 +174,12 @@ func save_pxo_file(path : String, autosave : bool) -> void: file.store_line(layer[0]) # Layer name file.store_8(layer[1]) # Layer visibility file.store_8(layer[2]) # Layer lock - file.store_8(layer[4]) # Future frames linked - file.store_var(layer[5]) # Linked frames + file.store_8(layer[4]) # Future cels linked + var linked_cels := [] + for canvas in layer[5]: + linked_cels.append(canvas.frame) + file.store_var(linked_cels) # Linked cels as cel numbers + file.store_line("END_GLOBAL_LAYERS") # Store frames diff --git a/src/Canvas.gd b/src/Canvas.gd index 0cdd5cd3a..fef7a2e58 100644 --- a/src/Canvas.gd +++ b/src/Canvas.gd @@ -42,6 +42,7 @@ var simple_drawer := SimpleDrawer.new() # Called when the node enters the scene tree for the first time. func _ready() -> void: var fill_layers := layers.empty() + var layer_i := 0 for l in Global.layers: if fill_layers: # The sprite itself @@ -68,9 +69,10 @@ func _ready() -> void: if self in l[5]: # If the linked button is pressed, set as the Image & ImageTexture # to be the same as the first linked cel - var current_layer := layers.size() - 1 - layers[current_layer][0] = l[5][0].layers[current_layer][0] - layers[current_layer][1] = l[5][0].layers[current_layer][1] + layers[layer_i][0] = l[5][0].layers[layer_i][0] + layers[layer_i][1] = l[5][0].layers[layer_i][1] + + layer_i += 1 # Only handle camera zoom settings & offset on the first frame if Global.canvases[0] == self: diff --git a/src/UI/Dialogs/AboutDialog.gd b/src/UI/Dialogs/AboutDialog.gd index 28c8aba23..d022b235d 100644 --- a/src/UI/Dialogs/AboutDialog.gd +++ b/src/UI/Dialogs/AboutDialog.gd @@ -33,6 +33,7 @@ func _ready() -> void: contributors.create_item(contributor_root).set_text(0, " Kinwailo") contributors.create_item(contributor_root).set_text(0, " Igor Santarek (jegor377)") contributors.create_item(contributor_root).set_text(0, " Dávid Gábor BODOR (dragonfi)") + contributors.create_item(contributor_root).set_text(0, " John Jerome Romero (Wishdream)") var donors_root := donors.create_item() donors.create_item(donors_root).set_text(0, " pcmxms - https://www.nonamefornowsoft.com.br/")