aboutsummaryrefslogtreecommitdiff
path: root/game/src/Game
diff options
context:
space:
mode:
author hop311 <hop3114@gmail.com>2023-10-12 01:36:22 +0200
committer hop311 <hop3114@gmail.com>2023-11-07 23:02:11 +0100
commitd113649c115b687a30a2040161d8570907c9141b (patch)
tree8941329c8f93a2214f42240b4458bd4255d45446 /game/src/Game
parent57822949341b86649614b343afa2c740efe00ac2 (diff)
Improved path CLI args + path caching setting
Diffstat (limited to 'game/src/Game')
-rw-r--r--game/src/Game/Autoload/Argument/ArgumentParser.tscn18
-rw-r--r--game/src/Game/GameStart.gd58
-rw-r--r--game/src/Game/Menu/OptionMenu/ScreenModeSelector.gd2
3 files changed, 62 insertions, 16 deletions
diff --git a/game/src/Game/Autoload/Argument/ArgumentParser.tscn b/game/src/Game/Autoload/Argument/ArgumentParser.tscn
index 84ebd50..32339ec 100644
--- a/game/src/Game/Autoload/Argument/ArgumentParser.tscn
+++ b/game/src/Game/Autoload/Argument/ArgumentParser.tscn
@@ -1,4 +1,4 @@
-[gd_scene load_steps=6 format=3 uid="uid://dayjmgc34tqo6"]
+[gd_scene load_steps=7 format=3 uid="uid://dayjmgc34tqo6"]
[ext_resource type="Script" path="res://src/Game/Autoload/Argument/ArgumentParser.gd" id="1_pc7xr"]
[ext_resource type="Script" path="res://src/Game/Autoload/Argument/ArgumentOption.gd" id="2_4hguj"]
@@ -21,13 +21,21 @@ default_value = false
[sub_resource type="Resource" id="Resource_tiax1"]
script = ExtResource("2_4hguj")
-name = &"compatibility-mode"
-aliases = Array[StringName]([&"compat"])
+name = &"base-path"
+aliases = Array[StringName]([])
type = 4
-description = "Load Victoria 2 assets from this path."
+description = "Load Victoria 2 assets from this exact path."
+default_value = ""
+
+[sub_resource type="Resource" id="Resource_sh3m3"]
+script = ExtResource("2_4hguj")
+name = &"search-path"
+aliases = Array[StringName]([])
+type = 4
+description = "Search for Victoria 2 assets at 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")])
+option_array = Array[ExtResource("2_4hguj")]([SubResource("Resource_tq3y4"), SubResource("Resource_j1to4"), SubResource("Resource_tiax1"), SubResource("Resource_sh3m3")])
diff --git a/game/src/Game/GameStart.gd b/game/src/Game/GameStart.gd
index 422a42a..1c230d1 100644
--- a/game/src/Game/GameStart.gd
+++ b/game/src/Game/GameStart.gd
@@ -6,6 +6,10 @@ const SoundTabScene = preload("res://src/Game/Menu/OptionMenu/SoundTab.tscn")
@export_subgroup("Nodes")
@export var loading_screen : LoadingScreen
+@export var section_name : String = "general"
+@export var setting_name : String = "base_defines_path"
+var _settings_base_path : String = ""
+
func _ready() -> void:
if ArgumentParser.get_argument(&"help"):
ArgumentParser._print_help()
@@ -20,30 +24,64 @@ func _ready() -> void:
var sound_tab := SoundTabScene.instantiate()
sound_tab.visible = false
add_child(sound_tab)
+ Events.Options.load_settings.connect(_load_setting)
+ Events.Options.save_settings.connect(_save_setting)
Events.Options.load_settings_from_file()
sound_tab.queue_free()
loading_screen.start_loading_screen(_initialize_game)
+func _load_setting(file : ConfigFile) -> void:
+ if file == null: return
+ _settings_base_path = file.get_value(section_name, setting_name, "")
+
+func _save_setting(file : ConfigFile) -> void:
+ if file == null: return
+ file.set_value(section_name, setting_name, _settings_base_path)
+
func _load_compatibility_mode():
# 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 = ArgumentParser.get_argument(&"compatibility-mode", "")
-
- if not compatibility_mode_path:
- # TODO - non-Windows default paths
- const default_path : String = "C:/Program Files (x86)/Steam/steamapps/common/Victoria 2"
- compatibility_mode_path = default_path
-
- var compatibility_mode_paths : PackedStringArray = [compatibility_mode_path]
+ var arg_base_path : String = ArgumentParser.get_argument(&"base-path", "")
+ var arg_search_path : String = ArgumentParser.get_argument(&"search-path", "")
+
+ var actual_base_path : String = ""
+
+ if arg_base_path:
+ if arg_search_path:
+ push_warning("Exact base path and search base path arguments both used:\nBase: ", arg_base_path, "\nSearch: ", arg_search_path)
+ actual_base_path = arg_base_path
+ elif arg_search_path:
+ actual_base_path = GameSingleton.search_for_game_path(arg_search_path)
+ if not actual_base_path:
+ push_warning("Failed to find assets using search hint: ", arg_search_path)
+
+ if not actual_base_path:
+ if _settings_base_path:
+ actual_base_path = _settings_base_path
+ else:
+ actual_base_path = GameSingleton.search_for_game_path()
+ if not actual_base_path:
+ var title : String = "Failed to find game asset path!"
+ var msg : String = "The path can be specified with the \"base-path\" command line option."
+ OS.alert(msg, title)
+ get_tree().quit()
+ return
+
+ if not _settings_base_path:
+ _settings_base_path = actual_base_path
+ # Save the path found in the search
+ Events.Options.save_settings_to_file()
+
+ var paths : PackedStringArray = [actual_base_path]
# Example for adding mod paths
- #compatibility_mode_paths.push_back("C:/Program Files (x86)/Steam/steamapps/common/Victoria 2/mod/TGC")
+ #paths.push_back(actual_base_path + "/mod/TGC")
- if GameSingleton.load_defines_compatibility_mode(compatibility_mode_paths) != OK:
+ if GameSingleton.load_defines_compatibility_mode(paths) != OK:
push_error("Errors loading game defines!")
# REQUIREMENTS
diff --git a/game/src/Game/Menu/OptionMenu/ScreenModeSelector.gd b/game/src/Game/Menu/OptionMenu/ScreenModeSelector.gd
index cb7566f..0d1836c 100644
--- a/game/src/Game/Menu/OptionMenu/ScreenModeSelector.gd
+++ b/game/src/Game/Menu/OptionMenu/ScreenModeSelector.gd
@@ -12,7 +12,7 @@ func get_screen_mode_from_window_mode(window_mode : Window.Mode) -> ScreenMode:
return ScreenMode.Fullscreen
Window.MODE_FULLSCREEN:
return ScreenMode.Borderless
- Window.MODE_WINDOWED:
+ Window.MODE_WINDOWED, Window.MODE_MINIMIZED:
return ScreenMode.Windowed
_:
return ScreenMode.Unknown