diff options
Diffstat (limited to 'game/src/Game')
-rw-r--r-- | game/src/Game/Autoload/Argument/ArgumentParser.gd | 80 | ||||
-rw-r--r-- | game/src/Game/Autoload/Argument/ArgumentParser.tscn | 5 | ||||
-rw-r--r-- | game/src/Game/Autoload/Events.gd | 35 | ||||
-rw-r--r-- | game/src/Game/Autoload/Events/GameDebug.gd | 18 | ||||
-rw-r--r-- | game/src/Game/Autoload/Events/Localisation.gd | 1 | ||||
-rw-r--r-- | game/src/Game/Autoload/Events/Options.gd | 1 | ||||
-rw-r--r-- | game/src/Game/Autoload/Events/ShaderManager.gd | 1 | ||||
-rw-r--r-- | game/src/Game/GameMenu.gd | 5 | ||||
-rw-r--r-- | game/src/Game/GameStart.tscn | 6 | ||||
-rw-r--r-- | game/src/Game/LoadingScreen.gd | 30 | ||||
-rw-r--r-- | game/src/Game/LoadingScreen.tscn | 70 |
11 files changed, 200 insertions, 52 deletions
diff --git a/game/src/Game/Autoload/Argument/ArgumentParser.gd b/game/src/Game/Autoload/Argument/ArgumentParser.gd index ce89dd8..123a733 100644 --- a/game/src/Game/Autoload/Argument/ArgumentParser.gd +++ b/game/src/Game/Autoload/Argument/ArgumentParser.gd @@ -44,6 +44,48 @@ const color_name_array : PackedStringArray =[ "whitesmoke", "yellow", "yellowgreen" ] +func has_argument_support(arg_name : StringName, include_aliases : bool = false) -> bool: + return option_array.any( + func(opt): + if include_aliases and arg_name in opt.aliases: + return true + return opt.name == arg_name + ) + +func get_argument(arg_name : StringName, default_val : Variant = null) -> Variant: + if ProjectSettings.has_setting(argument_setting_path): + var arg_setting = ProjectSettings.get_setting_with_override(argument_setting_path) + if not arg_setting is Dictionary: + push_error("Argument setting is not a dictionary.") + return default_val + return arg_setting.get(arg_name, default_val) + else: + return default_val + +func set_argument(arg_name : StringName, value : Variant) -> void: + if ProjectSettings.has_setting(argument_setting_path): + var arg_setting = null + arg_setting = ProjectSettings.get_setting_with_override(argument_setting_path) + if not arg_setting is Dictionary: + push_error("Argument setting is not a dictionary.") + return + arg_setting[arg_name] = value + ProjectSettings.set_setting(argument_setting_path, arg_setting) + return + push_error("Argument setting has not been set yet.") + +func _set_argument_setting() -> void: + var argument_dictionary : Dictionary = {} + if ProjectSettings.has_setting(argument_setting_path): + argument_dictionary = ProjectSettings.get_setting_with_override(argument_setting_path) + for option in option_array: + argument_dictionary[option.name] = option.default_value + + _parse_argument_list(argument_dictionary, OS.get_cmdline_args()) + _parse_argument_list(argument_dictionary, OS.get_cmdline_user_args()) + + ProjectSettings.set_setting(argument_setting_path, argument_dictionary) + func _parse_value(arg_name : StringName, value_string : String, type : Variant.Type) -> Variant: match type: TYPE_NIL: return null @@ -183,22 +225,36 @@ func _parse_argument_list(dictionary : Dictionary, arg_list : PackedStringArray) # eg: "-abc" means a == true, b == true, c == true if arg.length() > 1 and arg[0] != "-" and arg[1] != "=": for c in arg: + if not ((c >= "a" and c <= "z") or (c >= "A" and c <= "Z")): + push_warning("Parsing shorthand alias containing '%s', perhaps you meant '--%s'? Skipping argument." % [c, arg]) + break + var alias_found := false for o in option_array: if o.aliases.any(func(v): return c == v): - dictionary[o.name] = true + if o.type == TYPE_BOOL: + dictionary[o.name] = true + else: + push_warning("Shorthand alias '%s is not boolean, skipping." % c) + # TODO: Support POSIX 12.1 2.b? + # https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap12.html + break + alias_found = true + break + if not alias_found: + push_warning("Shorthand alias '%s' not found, skipping." % c) continue # Support for = key/value split # eg: "-v=5" and "--value=5" means v == 5 and value == 5 var first_equal := arg.find("=") if first_equal > -1: - key = arg.substr(0, first_equal - 1) + key = arg.substr(0, first_equal) value = arg.substr(first_equal + 1) else: key = arg # Removes - for full name arguments - if key.begins_with("-"): + if key.length() > 2 and key.begins_with("-"): key = key.substr(1) for o in option_array: @@ -216,6 +272,10 @@ func _parse_argument_list(dictionary : Dictionary, arg_list : PackedStringArray) if arg_result != null: dictionary[current_option.name] = arg_result current_option = null + elif current_option.type == TYPE_BOOL: + dictionary[current_option.name] = true + else: + push_warning("Argument '%s' treated like a boolean but does not support a boolean value, skipping." % key) return dictionary @@ -251,17 +311,7 @@ Options: ]) func _ready(): if Engine.is_editor_hint(): return - - var argument_dictionary : Dictionary = {} - if ProjectSettings.has_setting(argument_setting_path): - argument_dictionary = ProjectSettings.get_setting_with_override(argument_setting_path) - for option in option_array: - argument_dictionary[option.name] = option.default_value - - _parse_argument_list(argument_dictionary, OS.get_cmdline_args()) - _parse_argument_list(argument_dictionary, OS.get_cmdline_user_args()) - - ProjectSettings.set_setting(argument_setting_path, argument_dictionary) - if argument_dictionary[&"help"]: + _set_argument_setting() + if get_argument(&"help"): _print_help() get_tree().quit() diff --git a/game/src/Game/Autoload/Argument/ArgumentParser.tscn b/game/src/Game/Autoload/Argument/ArgumentParser.tscn index 09e5e6c..84ebd50 100644 --- a/game/src/Game/Autoload/Argument/ArgumentParser.tscn +++ b/game/src/Game/Autoload/Argument/ArgumentParser.tscn @@ -14,7 +14,7 @@ default_value = false [sub_resource type="Resource" id="Resource_j1to4"] script = ExtResource("2_4hguj") name = &"game-debug" -aliases = Array[StringName]([&"d", &"-debug", &"-debug-mode"]) +aliases = Array[StringName]([&"d", &"debug", &"debug-mode"]) type = 1 description = "Start in debug mode." default_value = false @@ -22,11 +22,12 @@ default_value = false [sub_resource type="Resource" id="Resource_tiax1"] script = ExtResource("2_4hguj") name = &"compatibility-mode" -aliases = Array[StringName]([&"-compat"]) +aliases = Array[StringName]([&"compat"]) type = 4 description = "Load Victoria 2 assets from this path." default_value = "" [node name="ArgumentParser" type="Node"] +editor_description = "SS-56" script = ExtResource("1_pc7xr") option_array = Array[ExtResource("2_4hguj")]([SubResource("Resource_tq3y4"), SubResource("Resource_j1to4"), SubResource("Resource_tiax1")]) diff --git a/game/src/Game/Autoload/Events.gd b/game/src/Game/Autoload/Events.gd index 4387cc7..f979301 100644 --- a/game/src/Game/Autoload/Events.gd +++ b/game/src/Game/Autoload/Events.gd @@ -1,9 +1,9 @@ extends Node -var GameDebug = preload("Events/GameDebug.gd").new() -var Options = preload("Events/Options.gd").new() -var Localisation = preload("Events/Localisation.gd").new() -var ShaderManager = preload("Events/ShaderManager.gd").new() +var GameDebug: GameDebugSingleton +var Options: OptionsSingleton +var Localisation: LocalisationSingleton +var ShaderManager: ShaderManagerSingleton var _define_filepaths_dict : Dictionary = { GameSingleton.get_province_identifier_file_key(): "res://common/map/provinces.json", @@ -19,27 +19,38 @@ var _define_filepaths_dict : Dictionary = { # REQUIREMENTS # * FS-333, FS-334, FS-335, FS-341 -func _ready(): +func load_events(loading_screen: LoadingScreen): GameSingleton.setup_logger() - + loading_screen.update_loading_screen(5) + # Set this to your Vic2 install dir or a mod's dir to enable compatibility mode # (this won't work for mods which rely on vanilla map assets, copy missing assets # into the mod's dir for a temporary fix) # Usage: OpenVic --compatibility-mode <path> - var compatibility_mode_path : String - if ProjectSettings.has_setting(ArgumentParser.argument_setting_path): - var arg_dictionary : Dictionary = ProjectSettings.get_setting(ArgumentParser.argument_setting_path) - compatibility_mode_path = arg_dictionary.get(&"compatibility-mode", compatibility_mode_path) + var compatibility_mode_path : String = ArgumentParser.get_argument(&"compatibility-mode") var start := Time.get_ticks_usec() - + + GameDebug = GameDebugSingleton.new() + loading_screen.update_loading_screen(15) + Options = OptionsSingleton.new() + loading_screen.update_loading_screen(25) + Localisation = LocalisationSingleton.new() + loading_screen.update_loading_screen(45) + ShaderManager = ShaderManagerSingleton.new() + loading_screen.update_loading_screen(50, true) + if compatibility_mode_path: if GameSingleton.load_defines_compatibility_mode(compatibility_mode_path) != OK: push_error("Errors loading game defines!") else: if GameSingleton.load_defines(_define_filepaths_dict) != OK: push_error("Errors loading game defines!") - + + loading_screen.update_loading_screen(100) var end := Time.get_ticks_usec() print("Loading took ", float(end - start) / 1000000, " seconds") + + # change scene in a thread-safe way + get_tree().call_deferred("change_scene_to_file", "res://src/Game/GameMenu.tscn") diff --git a/game/src/Game/Autoload/Events/GameDebug.gd b/game/src/Game/Autoload/Events/GameDebug.gd index df7a23a..9e18343 100644 --- a/game/src/Game/Autoload/Events/GameDebug.gd +++ b/game/src/Game/Autoload/Events/GameDebug.gd @@ -1,21 +1,9 @@ extends RefCounted - -# REQUIREMENTS: -# * SS-56 -func _init(): - for engine_args in OS.get_cmdline_args(): - match(engine_args): - "--game-debug": - set_debug_mode(true) - - for engine_args in OS.get_cmdline_user_args(): - match(engine_args): - "--game-debug", "-d", "--debug", "--debug-mode": - set_debug_mode(true) +class_name GameDebugSingleton func set_debug_mode(value : bool) -> void: - ProjectSettings.set_setting("openvic/debug/enabled", value) + ArgumentParser.set_argument(&"game-debug", value) print("Set debug mode to: ", value) func is_debug_mode() -> bool: - return ProjectSettings.get_setting("openvic/debug/enabled", false) + return ArgumentParser.get_argument(&"game-debug", false) diff --git a/game/src/Game/Autoload/Events/Localisation.gd b/game/src/Game/Autoload/Events/Localisation.gd index 9048b7a..37b550d 100644 --- a/game/src/Game/Autoload/Events/Localisation.gd +++ b/game/src/Game/Autoload/Events/Localisation.gd @@ -1,4 +1,5 @@ extends RefCounted +class_name LocalisationSingleton # REQUIREMENTS # * SS-59, SS-60, SS-61 diff --git a/game/src/Game/Autoload/Events/Options.gd b/game/src/Game/Autoload/Events/Options.gd index fbeccef..2e9b90b 100644 --- a/game/src/Game/Autoload/Events/Options.gd +++ b/game/src/Game/Autoload/Events/Options.gd @@ -1,4 +1,5 @@ extends RefCounted +class_name OptionsSingleton signal save_settings(save_file: ConfigFile) signal load_settings(load_file: ConfigFile) diff --git a/game/src/Game/Autoload/Events/ShaderManager.gd b/game/src/Game/Autoload/Events/ShaderManager.gd index a503c52..731dc3c 100644 --- a/game/src/Game/Autoload/Events/ShaderManager.gd +++ b/game/src/Game/Autoload/Events/ShaderManager.gd @@ -1,4 +1,5 @@ extends RefCounted +class_name ShaderManagerSingleton const param_province_shape_tex : StringName = &"province_shape_tex" const param_province_shape_subdivisions : StringName = &"province_shape_subdivisions" diff --git a/game/src/Game/GameMenu.gd b/game/src/Game/GameMenu.gd index 4b589f9..8e3239f 100644 --- a/game/src/Game/GameMenu.gd +++ b/game/src/Game/GameMenu.gd @@ -40,8 +40,3 @@ func _on_credits_back_button_pressed(): func _on_main_menu_credits_button_pressed(): _credits_menu.show() _main_menu.hide() - - - -func _on_splash_container_splash_end(): - show() diff --git a/game/src/Game/GameStart.tscn b/game/src/Game/GameStart.tscn index dd683e8..6cc358d 100644 --- a/game/src/Game/GameStart.tscn +++ b/game/src/Game/GameStart.tscn @@ -1,6 +1,6 @@ [gd_scene load_steps=6 format=3 uid="uid://1udsn4mggep2"] -[ext_resource type="PackedScene" uid="uid://o4u142w4qkln" path="res://src/Game/GameMenu.tscn" id="1_vadki"] +[ext_resource type="PackedScene" uid="uid://3kktdpfnc0sn" path="res://src/Game/LoadingScreen.tscn" id="2_h0oiw"] [ext_resource type="Script" path="res://src/Game/SplashContainer.gd" id="2_xmcgv"] [ext_resource type="Texture2D" uid="uid://deef5hufq0j61" path="res://splash_assets/splash_end.png" id="3_qfv12"] [ext_resource type="Texture2D" uid="uid://cgdnixsyh7bja" path="res://splash_assets/splash_image.png" id="4_5b6yq"] @@ -14,7 +14,7 @@ anchor_bottom = 1.0 grow_horizontal = 2 grow_vertical = 2 -[node name="GameMenu" parent="." instance=ExtResource("1_vadki")] +[node name="LoadingScreen" parent="." instance=ExtResource("2_h0oiw")] visible = false layout_mode = 1 @@ -48,5 +48,5 @@ stream = ExtResource("5_8euyy") autoplay = true expand = true -[connection signal="splash_end" from="SplashContainer" to="GameMenu" method="_on_splash_container_splash_end"] +[connection signal="splash_end" from="SplashContainer" to="LoadingScreen" method="_on_splash_container_splash_end"] [connection signal="finished" from="SplashContainer/SplashVideo" to="SplashContainer" method="_on_splash_startup_finished"] diff --git a/game/src/Game/LoadingScreen.gd b/game/src/Game/LoadingScreen.gd new file mode 100644 index 0000000..14acbd7 --- /dev/null +++ b/game/src/Game/LoadingScreen.gd @@ -0,0 +1,30 @@ +extends Control +class_name LoadingScreen + +@export var progress_bar: ProgressBar +@export var quote_label: Label + +var loadthread: Thread +var quotes: PackedStringArray = [] + +func update_loading_screen(percent_complete: int, quote_should_change = false): + progress_bar.value = percent_complete + if quote_should_change: + quote_label.text = quotes[randi() % quotes.size()] + +func _on_splash_container_splash_end(): + show() + +func _ready(): + # 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() + 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() diff --git a/game/src/Game/LoadingScreen.tscn b/game/src/Game/LoadingScreen.tscn new file mode 100644 index 0000000..d6068c8 --- /dev/null +++ b/game/src/Game/LoadingScreen.tscn @@ -0,0 +1,70 @@ +[gd_scene load_steps=6 format=3 uid="uid://3kktdpfnc0sn"] + +[ext_resource type="Script" path="res://src/Game/LoadingScreen.gd" id="1_b0p3w"] +[ext_resource type="Texture2D" uid="uid://doji17mxxmikl" path="res://theme/assets/loading_screen.png" id="2_ny153"] + +[sub_resource type="StyleBoxTexture" id="StyleBoxTexture_3fggo"] +texture = ExtResource("2_ny153") + +[sub_resource type="Theme" id="Theme_f5c3e"] +PanelContainer/styles/panel = SubResource("StyleBoxTexture_3fggo") + +[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_yaf7e"] +content_margin_left = 16.0 +content_margin_top = 16.0 +content_margin_right = 16.0 +content_margin_bottom = 16.0 +bg_color = Color(0.129412, 0.129412, 0.129412, 1) +corner_radius_top_left = 16 +corner_radius_top_right = 16 +corner_radius_bottom_right = 16 +corner_radius_bottom_left = 16 + +[node name="LoadingScreen" type="Control" node_paths=PackedStringArray("progress_bar", "quote_label")] +layout_mode = 3 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +script = ExtResource("1_b0p3w") +progress_bar = NodePath("PanelContainer/MarginContainer/ProgressBar") +quote_label = NodePath("PanelContainer/MarginContainer/PanelContainer/QuoteLabel") + +[node name="PanelContainer" type="PanelContainer" parent="."] +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +theme = SubResource("Theme_f5c3e") + +[node name="MarginContainer" type="MarginContainer" parent="PanelContainer"] +layout_mode = 2 +theme_override_constants/margin_left = 16 +theme_override_constants/margin_top = 16 +theme_override_constants/margin_right = 16 +theme_override_constants/margin_bottom = 16 + +[node name="ProgressBar" type="ProgressBar" parent="PanelContainer/MarginContainer"] +layout_mode = 2 +size_flags_vertical = 8 +step = 1.0 +rounded = true + +[node name="PanelContainer" type="PanelContainer" parent="PanelContainer/MarginContainer"] +layout_mode = 2 +size_flags_horizontal = 4 +size_flags_vertical = 0 +theme_override_styles/panel = SubResource("StyleBoxFlat_yaf7e") + +[node name="QuoteLabel" type="Label" parent="PanelContainer/MarginContainer/PanelContainer"] +custom_minimum_size = Vector2(700, 80) +layout_mode = 2 +size_flags_horizontal = 4 +size_flags_vertical = 0 +horizontal_alignment = 1 +vertical_alignment = 1 +autowrap_mode = 3 +text_overrun_behavior = 3 |