1
0
Fork 0
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:
Emmanouil Papadeas 2024-03-08 02:15:58 +02:00
parent 90f7df0f5d
commit c225553042
2 changed files with 20 additions and 29 deletions

View file

@ -217,20 +217,7 @@ func open_pxo_file(path: String, untitled_backup := false, replace_empty := true
zip_reader.close() zip_reader.close()
return return
new_project.deserialize(result) new_project.deserialize(result, zip_reader)
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)
if result.has("brushes"): if result.has("brushes"):
var brush_index := 0 var brush_index := 0
for brush in result.brushes: 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() new_project.name = path.get_file()
else: else:
new_project = Project.new([], path.get_file()) new_project = Project.new([], path.get_file())
new_project.deserialize(result) new_project.deserialize(result, null, file)
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)
if result.has("brushes"): if result.has("brushes"):
for brush in result.brushes: for brush in result.brushes:
var b_width = brush.size_x var b_width = brush.size_x

View file

@ -359,7 +359,7 @@ func serialize() -> Dictionary:
return project_data 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) about_to_deserialize.emit(dict)
if dict.has("size_x") and dict.has("size_y"): if dict.has("size_x") and dict.has("size_y"):
size.x = dict.size_x size.x = dict.size_x
@ -391,10 +391,26 @@ func deserialize(dict: Dictionary) -> void:
for cel in frame.cels: for cel in frame.cels:
match int(dict.layers[cel_i].get("type", Global.LayerTypes.PIXEL)): match int(dict.layers[cel_i].get("type", Global.LayerTypes.PIXEL)):
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: Global.LayerTypes.GROUP:
cels.append(GroupCel.new()) cels.append(GroupCel.new())
Global.LayerTypes.THREE_D: 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)) cels.append(Cel3D.new(size, true))
if dict.has("pxo_version"): if dict.has("pxo_version"):
cel["pxo_version"] = dict["pxo_version"] cel["pxo_version"] = dict["pxo_version"]