aboutsummaryrefslogtreecommitdiff
path: root/game/src/Game/LoadingScreen.gd
diff options
context:
space:
mode:
author Spartan322 <Megacake1234@gmail.com>2023-07-06 22:28:55 +0200
committer Spartan322 <Megacake1234@gmail.com>2023-07-09 01:24:10 +0200
commit86bee7b44c7cc7adaef8cdf441667a99223dd98a (patch)
tree5004d04dbe607dedf273afdee7dff783f4d980ed /game/src/Game/LoadingScreen.gd
parent5838c2508682bc3f6e35e44056f9ba229bca4571 (diff)
Add GameLoader Autoload to handle global loading data
Remove GameDebug, Localization, and ShaderManager from Events.gd Renamed OptionsSingleton class_name to OptionsEventsObject Add Events.Loader to handle Loader events (which are global signals) Make GameDebug singleton with static functions and property Make Localization functions static Move ShaderManager variable to GameLoader Move Events._define_filepaths_dict to GameLoader.define_filepaths_dict Move game initialization from LoadingScreen.gd and Events.gd to GameStart.gd Attach GameStart.gd to GameStart.tscn root Make LoadingScreen generalized and so it is reusable Remove class_name from LoaderingScreen.gd
Diffstat (limited to 'game/src/Game/LoadingScreen.gd')
-rw-r--r--game/src/Game/LoadingScreen.gd44
1 files changed, 32 insertions, 12 deletions
diff --git a/game/src/Game/LoadingScreen.gd b/game/src/Game/LoadingScreen.gd
index 9d44b41..3cbf199 100644
--- a/game/src/Game/LoadingScreen.gd
+++ b/game/src/Game/LoadingScreen.gd
@@ -1,32 +1,52 @@
extends Control
-class_name LoadingScreen
+signal load_started()
+signal load_changed(percentage : float)
+signal load_ended()
+
+@export var quote_file_path : String = "res://common/quotes.txt"
+
+@export_subgroup("Nodes")
@export var progress_bar: ProgressBar
@export var quote_label: Label
-var loadthread: Thread
+var thread: Thread
var quotes: PackedStringArray = []
-func update_loading_screen(percent_complete: int, quote_should_change = false):
+func start_loading_screen(thread_safe_function : Callable) -> void:
+ if not is_node_ready():
+ await ready
+ # set first quote
+ progress_bar.value = 0
+ quote_label.text = quotes[randi() % quotes.size()]
+
+ if thread != null and thread.is_started():
+ thread.wait_to_finish()
+
+ thread.start(thread_safe_function)
+ load_started.emit()
+
+func try_update_loading_screen(percent_complete: float, quote_should_change = false):
# forces the function to behave as if deferred
await get_tree().process_frame
progress_bar.value = percent_complete
if quote_should_change:
quote_label.text = quotes[randi() % quotes.size()]
-
-func _on_splash_container_splash_end():
- show()
+ if is_equal_approx(percent_complete, 100):
+ thread.wait_to_finish()
+ load_ended.emit()
+ else:
+ load_changed.emit(percent_complete)
func _ready():
+ if Engine.is_editor_hint(): return
+ thread = Thread.new()
# FS-3, UI-30, UIFUN-35
- loadthread = Thread.new()
- loadthread.start(Events.load_events.bind(self))
- var quotes_file = FileAccess.open("res://common/quotes.txt", FileAccess.READ).get_as_text()
+ var quotes_file := FileAccess.open(quote_file_path, FileAccess.READ).get_as_text()
quotes = quotes_file.split("\n",false)
if quotes.is_empty():
quotes = [""]
- # set first quote
- quote_label.text = quotes[randi() % quotes.size()]
func _exit_tree():
- loadthread.wait_to_finish()
+ if thread != null and thread.is_started():
+ thread.wait_to_finish()