From 8333b93664b9a38e3ee857c00645a9fad4d8af3c Mon Sep 17 00:00:00 2001 From: Emmanouil Papadeas Date: Thu, 4 Jan 2024 15:55:30 +0200 Subject: [PATCH] Export palettes as images on the Web version --- src/Palette/EditPaletteDialog.gd | 5 ++++- src/Palette/PalettePanel.gd | 10 ++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/Palette/EditPaletteDialog.gd b/src/Palette/EditPaletteDialog.gd index 9a56b676c..820a46126 100644 --- a/src/Palette/EditPaletteDialog.gd +++ b/src/Palette/EditPaletteDialog.gd @@ -89,7 +89,10 @@ func _on_EditPaletteDialog_custom_action(action: String) -> void: if action == DELETE_ACTION: delete_confirmation.popup_centered() elif action == EXPORT_ACTION: - export_file_dialog.popup_centered() + if OS.get_name() == "HTML5": + emit_signal("exported") + else: + export_file_dialog.popup_centered() func _on_delete_confirmation_confirmed() -> void: diff --git a/src/Palette/PalettePanel.gd b/src/Palette/PalettePanel.gd index 5762e3e1d..b68846603 100644 --- a/src/Palette/PalettePanel.gd +++ b/src/Palette/PalettePanel.gd @@ -225,9 +225,15 @@ func _color_changed(_color: Color, button: int) -> void: palette_grid.unselect_swatch(button, swatch_to_unselect) -func _on_EditPaletteDialog_exported(path: String) -> void: +func _on_EditPaletteDialog_exported(path := "") -> void: + var image: Image = Palettes.current_palette.convert_to_image() + if OS.get_name() == "HTML5": + JavaScript.download_buffer( + image.save_png_to_buffer(), Palettes.current_palette.name, "image/png" + ) + if path.empty(): + return var extension := path.get_extension() match extension: "png": - var image: Image = Palettes.current_palette.convert_to_image() image.save_png(path)