From 751adc312e59235b83a21d9e0b8efaa7a39457bd Mon Sep 17 00:00:00 2001 From: JeremyStarTM Date: Tue, 16 Jan 2024 21:27:13 +0100 Subject: [PATCH] Update loader & misc - [src/misc.gd] Add get_sign() function - [src/misc.gd] Add get_sign_float() function - [src/loader.gd] Change variable order (that makes a bit more sense) - [src/loader.gd] Fix path resolution - [src/loader.gd] Prefix all logger.error() calls in initialize() with "await" to prevent Godot debugger errors --- src/loader.gd | 10 +++++----- src/misc.gd | 14 +++++++++++++- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/loader.gd b/src/loader.gd index 9900fc2..82375c8 100644 --- a/src/loader.gd +++ b/src/loader.gd @@ -24,11 +24,11 @@ extends Control # Loader configuration -## Skip malicious scripts warning if running as debug build -var config_skipwarning: bool = true ## Window size support ### This is/was used for configuring scaling var config_window_size_support: bool = false +## Skip malicious scripts warning if running as debug build +var config_skipwarning: bool = true ## Slow init ### I don't know why I put this here lol var config_slow_init: bool = false @@ -129,9 +129,9 @@ ONLY VIEW PRESENCODE PRESENTATIONS IF YOU TRUST THE get_tree().root.add_child.call_deferred(console) if config_slow_init: await get_tree().create_timer(randf_range(0.1, 0.15)).timeout # Open presentation archive/directory - var path: String = "".join(OS.get_cmdline_user_args()) + var path: String = " ".join(OS.get_cmdline_user_args()) if OS.get_cmdline_user_args().size() == 0: - logger.error("No presentation was passed to Presencode") + await logger.error("No presentation was passed to Presencode") if FileAccess.file_exists(path) and path.ends_with(".zip") or path.ends_with(".pcpa"): # .pcpa = presencode presentation archive logger.info("Opening presentation archive") preader.open_presentation(path, true) @@ -139,7 +139,7 @@ ONLY VIEW PRESENCODE PRESENTATIONS IF YOU TRUST THE logger.info("Opening presentation directory") preader.open_presentation(path, false) else: - logger.error("Presentation file/directory \"" + path + "\" not found") + await logger.error("Presentation file/directory \"" + path + "\" not found") if config_slow_init: await get_tree().create_timer(randf_range(0.6, 1)).timeout # Read manifest & entrypoint files preader.read_manifest() diff --git a/src/misc.gd b/src/misc.gd index a4550f6..a28ab47 100644 --- a/src/misc.gd +++ b/src/misc.gd @@ -81,7 +81,7 @@ func shutdown(exitcode: int = 0) -> void: await get_tree().create_timer(0.25, true).timeout print("Exiting!") get_tree().quit(exitcode) - # Insanely long timer as Godot executes code further even while it's exiting + # Insanely long timer to prevent Godot from executing code during exit await get_tree().create_timer(999, true).timeout # Calculate the center of a child inside its parent (Vector2i) @@ -93,6 +93,18 @@ func get_center(parent_size: Vector2i, child_size: Vector2i) -> Vector2i: func get_center_float(parent_size: Vector2, child_size: Vector2) -> Vector2: return Vector2(parent_size.x/2-child_size.x/2, parent_size.y/2-child_size.y/2) +# Returns the sign (-1, +1, 0) of an int +func get_sign(number: int) -> int: + if number > 0: return +1 + elif number < 0: return -1 + else: return 0 + +# Returns the sign (-1, +1, 0) of a float +func get_sign_float(number: float) -> float: + if number > 0: return +1 + elif number < 0: return -1 + else: return 0 + # Return path to temporary directory ## This function tries to utilize the operating system's temporary directory. ## If all of them can't be used, it falls back to "user://temp" instead.