mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-01-18 17:19:50 +00:00
Fix linked cels not working when importing a pxo file
Godot 4 has changed how ImageTexture works, as now it doesn't work when the Image is empty. Thus, we need to add Images to PixelCels right when they are created, before the linked cel logic is being handled.
This commit is contained in:
parent
90f7df0f5d
commit
c225553042
|
@ -217,20 +217,7 @@ func open_pxo_file(path: String, untitled_backup := false, replace_empty := true
|
|||
zip_reader.close()
|
||||
return
|
||||
|
||||
new_project.deserialize(result)
|
||||
for frame_index in new_project.frames.size():
|
||||
var frame := new_project.frames[frame_index]
|
||||
for cel_index in frame.cels.size():
|
||||
var cel := frame.cels[cel_index]
|
||||
if not cel is PixelCel:
|
||||
continue
|
||||
var image_data := zip_reader.read_file(
|
||||
"image_data/frames/%s/layer_%s" % [frame_index + 1, cel_index + 1]
|
||||
)
|
||||
var image := Image.create_from_data(
|
||||
new_project.size.x, new_project.size.y, false, Image.FORMAT_RGBA8, image_data
|
||||
)
|
||||
cel.image_changed(image)
|
||||
new_project.deserialize(result, zip_reader)
|
||||
if result.has("brushes"):
|
||||
var brush_index := 0
|
||||
for brush in result.brushes:
|
||||
|
@ -317,19 +304,7 @@ func open_v0_pxo_file(path: String, empty_project: bool) -> Project:
|
|||
new_project.name = path.get_file()
|
||||
else:
|
||||
new_project = Project.new([], path.get_file())
|
||||
new_project.deserialize(result)
|
||||
for frame in new_project.frames:
|
||||
for cel in frame.cels:
|
||||
if cel is PixelCel:
|
||||
var buffer := file.get_buffer(new_project.size.x * new_project.size.y * 4)
|
||||
var image := Image.create_from_data(
|
||||
new_project.size.x, new_project.size.y, false, Image.FORMAT_RGBA8, buffer
|
||||
)
|
||||
cel.image_changed(image)
|
||||
elif cel is Cel3D:
|
||||
# Don't do anything with it, just read it so that the file can move on
|
||||
file.get_buffer(new_project.size.x * new_project.size.y * 4)
|
||||
|
||||
new_project.deserialize(result, null, file)
|
||||
if result.has("brushes"):
|
||||
for brush in result.brushes:
|
||||
var b_width = brush.size_x
|
||||
|
|
|
@ -359,7 +359,7 @@ func serialize() -> Dictionary:
|
|||
return project_data
|
||||
|
||||
|
||||
func deserialize(dict: Dictionary) -> void:
|
||||
func deserialize(dict: Dictionary, zip_reader: ZIPReader = null, file: FileAccess = null) -> void:
|
||||
about_to_deserialize.emit(dict)
|
||||
if dict.has("size_x") and dict.has("size_y"):
|
||||
size.x = dict.size_x
|
||||
|
@ -391,10 +391,26 @@ func deserialize(dict: Dictionary) -> void:
|
|||
for cel in frame.cels:
|
||||
match int(dict.layers[cel_i].get("type", Global.LayerTypes.PIXEL)):
|
||||
Global.LayerTypes.PIXEL:
|
||||
cels.append(PixelCel.new(Image.new()))
|
||||
var image := Image.new()
|
||||
if is_instance_valid(zip_reader): # For pxo files saved in 1.0+
|
||||
var image_data := zip_reader.read_file(
|
||||
"image_data/frames/%s/layer_%s" % [frame_i + 1, cel_i + 1]
|
||||
)
|
||||
image = Image.create_from_data(
|
||||
size.x, size.y, false, Image.FORMAT_RGBA8, image_data
|
||||
)
|
||||
elif is_instance_valid(file): # For pxo files saved in 0.x
|
||||
var buffer := file.get_buffer(size.x * size.y * 4)
|
||||
image = Image.create_from_data(
|
||||
size.x, size.y, false, Image.FORMAT_RGBA8, buffer
|
||||
)
|
||||
cels.append(PixelCel.new(image))
|
||||
Global.LayerTypes.GROUP:
|
||||
cels.append(GroupCel.new())
|
||||
Global.LayerTypes.THREE_D:
|
||||
if is_instance_valid(file): # For pxo files saved in 0.x
|
||||
# Don't do anything with it, just read it so that the file can move on
|
||||
file.get_buffer(size.x * size.y * 4)
|
||||
cels.append(Cel3D.new(size, true))
|
||||
if dict.has("pxo_version"):
|
||||
cel["pxo_version"] = dict["pxo_version"]
|
||||
|
|
Loading…
Reference in a new issue