aboutsummaryrefslogtreecommitdiff
path: root/game
diff options
context:
space:
mode:
author Hop311 <Hop3114@gmail.com>2024-01-15 01:24:17 +0100
committer GitHub <noreply@github.com>2024-01-15 01:24:17 +0100
commit92267a046506077418823a16ac8748579cf7905c (patch)
treeac4893e2a7cc33a5f60d910717da51962a9ceef7 /game
parentdd008b3c0aa27be0cbe9a0ed5a9811c76f9cb13a (diff)
parent03ecd41a38acff5588f01568bdf5d61067a266ce (diff)
Merge pull request #192 from OpenVicProject/mod-paths
Added mod command line option
Diffstat (limited to 'game')
-rw-r--r--game/src/Game/Autoload/Argument/ArgumentOption.gd4
-rw-r--r--game/src/Game/Autoload/Argument/ArgumentParser.gd30
-rw-r--r--game/src/Game/Autoload/Argument/ArgumentParser.tscn16
-rw-r--r--game/src/Game/GameStart.gd11
4 files changed, 42 insertions, 19 deletions
diff --git a/game/src/Game/Autoload/Argument/ArgumentOption.gd b/game/src/Game/Autoload/Argument/ArgumentOption.gd
index a9b7000..9c0e731 100644
--- a/game/src/Game/Autoload/Argument/ArgumentOption.gd
+++ b/game/src/Game/Autoload/Argument/ArgumentOption.gd
@@ -14,6 +14,7 @@ extends Resource
TYPE_FLOAT: default_value = 0.0
TYPE_STRING: default_value = ""
TYPE_STRING_NAME: default_value = &""
+ TYPE_PACKED_STRING_ARRAY: default_value = PackedStringArray()
TYPE_COLOR: default_value = Color()
_: default_value = null
notify_property_list_changed()
@@ -38,6 +39,7 @@ func get_type_string() -> StringName:
TYPE_INT: return "integer"
TYPE_FLOAT: return "float"
TYPE_STRING, TYPE_STRING_NAME: return "string"
+ TYPE_PACKED_STRING_ARRAY: return "string array"
TYPE_COLOR: return "color"
return "<invalid type>"
@@ -52,7 +54,7 @@ func _set(property : StringName, value : Variant) -> bool:
return false
func _get_property_list() -> Array[Dictionary]:
- var properties := []
+ var properties := [] as Array[Dictionary]
properties.append({
"name": "default_value",
diff --git a/game/src/Game/Autoload/Argument/ArgumentParser.gd b/game/src/Game/Autoload/Argument/ArgumentParser.gd
index b3e8632..96b6631 100644
--- a/game/src/Game/Autoload/Argument/ArgumentParser.gd
+++ b/game/src/Game/Autoload/Argument/ArgumentParser.gd
@@ -107,7 +107,7 @@ func _parse_value(arg_name : StringName, value_string : String, type : Variant.T
return value_string.to_float()
push_error("'%s' must be a valid float, '%s' is an invalid value." % [arg_name, value_string])
return null
- TYPE_STRING, TYPE_STRING_NAME:
+ TYPE_STRING, TYPE_STRING_NAME, TYPE_PACKED_STRING_ARRAY:
return value_string
TYPE_COLOR:
if Color.html_is_valid(value_string) or value_string.to_lower() in color_name_array:
@@ -196,24 +196,30 @@ func _parse_value(arg_name : StringName, value_string : String, type : Variant.T
# TYPE_PACKED_INT64_ARRAY = 31
# TYPE_PACKED_FLOAT32_ARRAY = 32
# TYPE_PACKED_FLOAT64_ARRAY = 33
-# TYPE_PACKED_STRING_ARRAY = 34
# TYPE_PACKED_VECTOR2_ARRAY = 35
# TYPE_PACKED_VECTOR3_ARRAY = 36
# TYPE_PACKED_COLOR_ARRAY = 37
+func _add_argument(dictionary : Dictionary, option : ArgumentOption, argument : Variant) -> void:
+ if option.type == TYPE_PACKED_STRING_ARRAY:
+ dictionary[option.name] += PackedStringArray([argument])
+ else:
+ dictionary[option.name] = argument
+
+
func _parse_argument_list(dictionary : Dictionary, arg_list : PackedStringArray) -> Dictionary:
var current_key : String = ""
var current_option : ArgumentOption = null
for arg in arg_list:
- if current_option != null and not arg.begins_with("-"):
- var result : Variant = _parse_value(current_key, arg, current_option.type)
- if result != null:
- dictionary[current_option.name] = result
- current_option = null
- continue
-
if current_option != null:
- push_warning("Valid argument '%s' was not set as a value, skipping." % current_key)
+ if not arg.begins_with("-"):
+ var result : Variant = _parse_value(current_key, arg, current_option.type)
+ if result != null:
+ _add_argument(dictionary, current_option, result)
+ current_option = null
+ continue
+ else:
+ push_warning("Valid argument '%s' was not set as a value, skipping." % current_key)
if arg.begins_with("-"):
current_option = null
@@ -270,12 +276,14 @@ func _parse_argument_list(dictionary : Dictionary, arg_list : PackedStringArray)
if first_equal > -1:
var arg_result : Variant = _parse_value(key, value, current_option.type)
if arg_result != null:
- dictionary[current_option.name] = arg_result
+ _add_argument(dictionary, current_option, 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)
+ else:
+ push_warning("Non argument '%s' found, skipping." % arg)
return dictionary
diff --git a/game/src/Game/Autoload/Argument/ArgumentParser.tscn b/game/src/Game/Autoload/Argument/ArgumentParser.tscn
index 32339ec..4da5cab 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=7 format=3 uid="uid://dayjmgc34tqo6"]
+[gd_scene load_steps=8 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"]
@@ -22,7 +22,7 @@ default_value = false
[sub_resource type="Resource" id="Resource_tiax1"]
script = ExtResource("2_4hguj")
name = &"base-path"
-aliases = Array[StringName]([])
+aliases = Array[StringName]([&"b"])
type = 4
description = "Load Victoria 2 assets from this exact path."
default_value = ""
@@ -30,12 +30,20 @@ default_value = ""
[sub_resource type="Resource" id="Resource_sh3m3"]
script = ExtResource("2_4hguj")
name = &"search-path"
-aliases = Array[StringName]([])
+aliases = Array[StringName]([&"s"])
type = 4
description = "Search for Victoria 2 assets at this path."
default_value = ""
+[sub_resource type="Resource" id="Resource_8ab4j"]
+script = ExtResource("2_4hguj")
+name = &"mod"
+aliases = Array[StringName]([&"m"])
+type = 34
+description = "Load Victoria 2 mods with these names."
+default_value = PackedStringArray()
+
[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"), SubResource("Resource_sh3m3")])
+option_array = Array[ExtResource("2_4hguj")]([SubResource("Resource_tq3y4"), SubResource("Resource_j1to4"), SubResource("Resource_tiax1"), SubResource("Resource_sh3m3"), SubResource("Resource_8ab4j")])
diff --git a/game/src/Game/GameStart.gd b/game/src/Game/GameStart.gd
index 4b93077..3a98dca 100644
--- a/game/src/Game/GameStart.gd
+++ b/game/src/Game/GameStart.gd
@@ -57,6 +57,7 @@ func _load_compatibility_mode() -> void:
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:
+ # This will also search for a Steam install if the hint doesn't help
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)
@@ -65,7 +66,9 @@ func _load_compatibility_mode() -> void:
if _settings_base_path:
actual_base_path = _settings_base_path
else:
- actual_base_path = GameSingleton.search_for_game_path()
+ # Check if the program is being run from inside the install directory,
+ # and if not also search for a Steam install
+ 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."
@@ -80,8 +83,10 @@ func _load_compatibility_mode() -> void:
var paths : PackedStringArray = [actual_base_path]
- # Example for adding mod paths
- #paths.push_back(actual_base_path + "/mod/TGC")
+ # Add mod paths
+ var settings_mod_names : PackedStringArray = ArgumentParser.get_argument(&"mod", "")
+ for mod_name : String in settings_mod_names:
+ paths.push_back(actual_base_path + "/mod/" + mod_name)
if GameSingleton.load_defines_compatibility_mode(paths) != OK:
push_error("Errors loading game defines!")