mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-01-31 07:29:49 +00:00
Change OpenSave.handle_loading_file to handle a single path
OpenSave.handle_loading_files() has been renamed to OpenSave.handle_loading_file and it now takes a single string as a parameter, instead of a PoolStringArray. This was needed for Main.gd's new _handle_cmdline_arguments() method. This method does not add any new functionality for now, but it will in the future.
This commit is contained in:
parent
5478d320dc
commit
7768bc92dd
|
@ -19,48 +19,47 @@ func _ready() -> void:
|
|||
update_autosave()
|
||||
|
||||
|
||||
func handle_loading_files(files: PoolStringArray) -> void:
|
||||
for file in files:
|
||||
file = file.replace("\\", "/")
|
||||
var file_ext: String = file.get_extension().to_lower()
|
||||
if file_ext == "pxo": # Pixelorama project file
|
||||
open_pxo_file(file)
|
||||
func handle_loading_file(file: String) -> void:
|
||||
file = file.replace("\\", "/")
|
||||
var file_ext: String = file.get_extension().to_lower()
|
||||
if file_ext == "pxo": # Pixelorama project file
|
||||
open_pxo_file(file)
|
||||
|
||||
elif file_ext == "tres": # Godot resource file
|
||||
var resource = load(file)
|
||||
if resource is Palette:
|
||||
Palettes.import_palette(resource, file.get_file())
|
||||
else:
|
||||
var file_name: String = file.get_file()
|
||||
Global.error_dialog.set_text(tr("Can't load file '%s'.") % [file_name])
|
||||
Global.error_dialog.popup_centered()
|
||||
Global.dialog_open(true)
|
||||
elif file_ext == "tres": # Godot resource file
|
||||
var resource = load(file)
|
||||
if resource is Palette:
|
||||
Palettes.import_palette(resource, file.get_file())
|
||||
else:
|
||||
var file_name: String = file.get_file()
|
||||
Global.error_dialog.set_text(tr("Can't load file '%s'.") % [file_name])
|
||||
Global.error_dialog.popup_centered()
|
||||
Global.dialog_open(true)
|
||||
|
||||
elif file_ext == "gpl" or file_ext == "pal" or file_ext == "json":
|
||||
Palettes.import_palette_from_path(file)
|
||||
elif file_ext == "gpl" or file_ext == "pal" or file_ext == "json":
|
||||
Palettes.import_palette_from_path(file)
|
||||
|
||||
elif file_ext in ["pck", "zip"]: # Godot resource pack file
|
||||
Global.preferences_dialog.extensions.install_extension(file)
|
||||
elif file_ext in ["pck", "zip"]: # Godot resource pack file
|
||||
Global.preferences_dialog.extensions.install_extension(file)
|
||||
|
||||
elif file_ext == "shader" or file_ext == "gdshader": # Godot shader file
|
||||
var shader = load(file)
|
||||
if !shader is Shader:
|
||||
continue
|
||||
var file_name: String = file.get_file().get_basename()
|
||||
Global.control.find_node("ShaderEffect").change_shader(shader, file_name)
|
||||
elif file_ext == "shader" or file_ext == "gdshader": # Godot shader file
|
||||
var shader = load(file)
|
||||
if !shader is Shader:
|
||||
return
|
||||
var file_name: String = file.get_file().get_basename()
|
||||
Global.control.find_node("ShaderEffect").change_shader(shader, file_name)
|
||||
|
||||
else: # Image files
|
||||
var image := Image.new()
|
||||
var err := image.load(file)
|
||||
if err != OK: # An error occured
|
||||
var file_name: String = file.get_file()
|
||||
Global.error_dialog.set_text(
|
||||
tr("Can't load file '%s'.\nError code: %s") % [file_name, str(err)]
|
||||
)
|
||||
Global.error_dialog.popup_centered()
|
||||
Global.dialog_open(true)
|
||||
continue
|
||||
handle_loading_image(file, image)
|
||||
else: # Image files
|
||||
var image := Image.new()
|
||||
var err := image.load(file)
|
||||
if err != OK: # An error occured
|
||||
var file_name: String = file.get_file()
|
||||
Global.error_dialog.set_text(
|
||||
tr("Can't load file '%s'.\nError code: %s") % [file_name, str(err)]
|
||||
)
|
||||
Global.error_dialog.popup_centered()
|
||||
Global.dialog_open(true)
|
||||
return
|
||||
handle_loading_image(file, image)
|
||||
|
||||
|
||||
func handle_loading_image(file: String, image: Image) -> void:
|
||||
|
|
26
src/Main.gd
26
src/Main.gd
|
@ -68,10 +68,7 @@ func _ready() -> void:
|
|||
|
||||
_handle_backup()
|
||||
|
||||
# If the user wants to run Pixelorama with arguments in terminal mode
|
||||
# or open files with Pixelorama directly, then handle that
|
||||
if OS.get_cmdline_args():
|
||||
OpenSave.handle_loading_files(OS.get_cmdline_args())
|
||||
_handle_cmdline_arguments()
|
||||
get_tree().connect("files_dropped", self, "_on_files_dropped")
|
||||
|
||||
if OS.get_name() == "Android":
|
||||
|
@ -197,6 +194,19 @@ func _handle_backup() -> void:
|
|||
load_last_project()
|
||||
|
||||
|
||||
func _handle_cmdline_arguments() -> void:
|
||||
var args := OS.get_cmdline_args()
|
||||
if args.empty():
|
||||
return
|
||||
|
||||
for arg in args:
|
||||
if arg.begins_with("-") or arg.begins_with("--"):
|
||||
# TODO: Add code to handle custom command line arguments
|
||||
continue
|
||||
else:
|
||||
OpenSave.handle_loading_file(arg)
|
||||
|
||||
|
||||
func _notification(what: int) -> void:
|
||||
match what:
|
||||
MainLoop.NOTIFICATION_WM_QUIT_REQUEST:
|
||||
|
@ -224,7 +234,8 @@ func _notification(what: int) -> void:
|
|||
|
||||
|
||||
func _on_files_dropped(files: PoolStringArray, _screen: int) -> void:
|
||||
OpenSave.handle_loading_files(files)
|
||||
for file in files:
|
||||
OpenSave.handle_loading_file(file)
|
||||
var splash_dialog = Global.control.get_node("Dialogs/SplashDialog")
|
||||
if splash_dialog.visible:
|
||||
splash_dialog.hide()
|
||||
|
@ -258,7 +269,7 @@ func load_recent_project_file(path: String) -> void:
|
|||
# Check if file still exists on disk
|
||||
var file_check := File.new()
|
||||
if file_check.file_exists(path): # If yes then load the file
|
||||
OpenSave.handle_loading_files([path])
|
||||
OpenSave.handle_loading_file(path)
|
||||
# Sync file dialogs
|
||||
Global.save_sprites_dialog.current_dir = path.get_base_dir()
|
||||
Global.open_sprites_dialog.current_dir = path.get_base_dir()
|
||||
|
@ -271,7 +282,8 @@ func load_recent_project_file(path: String) -> void:
|
|||
|
||||
|
||||
func _on_OpenSprite_files_selected(paths: PoolStringArray) -> void:
|
||||
OpenSave.handle_loading_files(paths)
|
||||
for path in paths:
|
||||
OpenSave.handle_loading_file(path)
|
||||
Global.save_sprites_dialog.current_dir = paths[0].get_base_dir()
|
||||
Global.config_cache.set_value("data", "current_dir", paths[0].get_base_dir())
|
||||
|
||||
|
|
Loading…
Reference in a new issue