From 03ecd41a38acff5588f01568bdf5d61067a266ce Mon Sep 17 00:00:00 2001 From: hop311 Date: Sat, 13 Jan 2024 22:04:26 +0000 Subject: Added mod command line option --- game/src/Game/Autoload/Argument/ArgumentOption.gd | 4 ++- game/src/Game/Autoload/Argument/ArgumentParser.gd | 30 ++++++++++++++-------- .../src/Game/Autoload/Argument/ArgumentParser.tscn | 16 +++++++++--- 3 files changed, 34 insertions(+), 16 deletions(-) (limited to 'game/src/Game/Autoload') 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 "" @@ -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")]) -- cgit v1.2.3-56-ga3b1