From 5246d8481dabc56635d4b95909d8a6e566a94059 Mon Sep 17 00:00:00 2001 From: Rendo Date: Sat, 26 Jul 2025 18:32:16 +0500 Subject: [PATCH] numeric mods --- .../float_mods_property.tscn | 57 ++++++++++++++++ addons/numeric-modifiers/numeric_modifiers.gd | 21 ++++++ .../numeric_modifiers.gd.uid | 1 + .../numeric_mods_inspector.gd | 13 ++++ .../numeric_mods_inspector.gd.uid | 1 + .../numeric_mods_property.gd | 66 +++++++++++++++++++ .../numeric_mods_property.gd.uid | 1 + addons/numeric-modifiers/plugin.cfg | 7 ++ addons/numeric-modifiers/plugin.gd | 13 ++++ addons/numeric-modifiers/plugin.gd.uid | 1 + project.godot | 4 ++ 11 files changed, 185 insertions(+) create mode 100644 addons/numeric-modifiers/float_mods_property.tscn create mode 100644 addons/numeric-modifiers/numeric_modifiers.gd create mode 100644 addons/numeric-modifiers/numeric_modifiers.gd.uid create mode 100644 addons/numeric-modifiers/numeric_mods_inspector.gd create mode 100644 addons/numeric-modifiers/numeric_mods_inspector.gd.uid create mode 100644 addons/numeric-modifiers/numeric_mods_property.gd create mode 100644 addons/numeric-modifiers/numeric_mods_property.gd.uid create mode 100644 addons/numeric-modifiers/plugin.cfg create mode 100644 addons/numeric-modifiers/plugin.gd create mode 100644 addons/numeric-modifiers/plugin.gd.uid diff --git a/addons/numeric-modifiers/float_mods_property.tscn b/addons/numeric-modifiers/float_mods_property.tscn new file mode 100644 index 0000000..c842ea7 --- /dev/null +++ b/addons/numeric-modifiers/float_mods_property.tscn @@ -0,0 +1,57 @@ +[gd_scene format=3 uid="uid://d2ne6ml10xgcl"] + +[node name="FloatModsProperty" type="VBoxContainer"] +offset_right = 163.0 +offset_bottom = 104.0 + +[node name="FlatContainer" type="HBoxContainer" parent="."] +layout_mode = 2 + +[node name="Label" type="Label" parent="FlatContainer"] +layout_mode = 2 +size_flags_horizontal = 3 +text = "Flat" + +[node name="Flat" type="SpinBox" parent="FlatContainer"] +unique_name_in_owner = true +custom_minimum_size = Vector2(128, 0) +layout_mode = 2 +step = 0.001 +allow_greater = true +allow_lesser = true + +[node name="PercentageContainer" type="HBoxContainer" parent="."] +layout_mode = 2 + +[node name="Label" type="Label" parent="PercentageContainer"] +layout_mode = 2 +size_flags_horizontal = 3 +text = "%" + +[node name="Percentage" type="SpinBox" parent="PercentageContainer"] +unique_name_in_owner = true +custom_minimum_size = Vector2(128, 0) +layout_mode = 2 +max_value = 10.0 +step = 0.001 +allow_greater = true +allow_lesser = true +prefix = "+" + +[node name="MultContainer" type="HBoxContainer" parent="."] +layout_mode = 2 + +[node name="Label" type="Label" parent="MultContainer"] +layout_mode = 2 +size_flags_horizontal = 3 +text = "Mult" + +[node name="Mult" type="SpinBox" parent="MultContainer"] +unique_name_in_owner = true +custom_minimum_size = Vector2(128, 0) +layout_mode = 2 +step = 0.001 +value = 1.0 +allow_greater = true +allow_lesser = true +prefix = "*" diff --git a/addons/numeric-modifiers/numeric_modifiers.gd b/addons/numeric-modifiers/numeric_modifiers.gd new file mode 100644 index 0000000..a1b1f07 --- /dev/null +++ b/addons/numeric-modifiers/numeric_modifiers.gd @@ -0,0 +1,21 @@ +extends Resource + +class_name NumericModifiers + +@export var flat_value : float +@export var percentage_value : float +@export var mult_value : float + +var value: + get(): + return get_value() + +func _init(flat : float = 0, per : float = 0, mult : float = 1) -> void: + flat_value = flat + percentage_value = per + mult_value = mult + + resource_local_to_scene = true + +func get_value() -> float: + return flat_value * mult_value * (1.0 + percentage_value) diff --git a/addons/numeric-modifiers/numeric_modifiers.gd.uid b/addons/numeric-modifiers/numeric_modifiers.gd.uid new file mode 100644 index 0000000..39b6759 --- /dev/null +++ b/addons/numeric-modifiers/numeric_modifiers.gd.uid @@ -0,0 +1 @@ +uid://bupbncytu4jo6 diff --git a/addons/numeric-modifiers/numeric_mods_inspector.gd b/addons/numeric-modifiers/numeric_mods_inspector.gd new file mode 100644 index 0000000..6b26da4 --- /dev/null +++ b/addons/numeric-modifiers/numeric_mods_inspector.gd @@ -0,0 +1,13 @@ +@tool +extends EditorInspectorPlugin + +class_name NumericModsInspector + +func _can_handle(object: Object) -> bool: + return true + +func _parse_property(object: Object, type: Variant.Type, name: String, hint_type: PropertyHint, hint_string: String, usage_flags: int, wide: bool) -> bool: + if hint_string == "NumericModifiers": + add_property_editor(name,NumericModsProperty.new()) + return true + return false diff --git a/addons/numeric-modifiers/numeric_mods_inspector.gd.uid b/addons/numeric-modifiers/numeric_mods_inspector.gd.uid new file mode 100644 index 0000000..7fb66b3 --- /dev/null +++ b/addons/numeric-modifiers/numeric_mods_inspector.gd.uid @@ -0,0 +1 @@ +uid://bxfxecofojsqk diff --git a/addons/numeric-modifiers/numeric_mods_property.gd b/addons/numeric-modifiers/numeric_mods_property.gd new file mode 100644 index 0000000..1ea4ff0 --- /dev/null +++ b/addons/numeric-modifiers/numeric_mods_property.gd @@ -0,0 +1,66 @@ +@tool +extends EditorProperty + +class_name NumericModsProperty + +var control : VBoxContainer +var mod : NumericModifiers +var updating : bool + +func _init() -> void: + control = preload("uid://d2ne6ml10xgcl").instantiate() + add_child(control) + add_focusable(control) + + refresh_control() + + control.get_node("%Flat").value_changed.connect(update_flat) + control.get_node("%Percentage").value_changed.connect(update_percentage) + control.get_node("%Mult").value_changed.connect(update_mult) + +func refresh_control(): + if mod == null: return + + control.get_node("%Flat").set_value_no_signal(mod.flat_value) + control.get_node("%Percentage").set_value_no_signal(mod.percentage_value) + control.get_node("%Mult").set_value_no_signal(mod.mult_value) + +func update_flat(value : float): + if updating: return + + mod.flat_value = value + + refresh_control() + emit_changed(get_edited_property(),mod) + +func update_percentage(value : float): + if updating: return + + mod.percentage_value = value + + refresh_control() + emit_changed(get_edited_property(),mod) + +func update_mult(value : float): + if updating: return + + mod.mult_value = value + + refresh_control() + emit_changed(get_edited_property(),mod) + +func _update_property() -> void: + var new_value = get_edited_object().get(get_edited_property()) as NumericModifiers + if new_value == null: + new_value = NumericModifiers.new() + new_value.resource_local_to_scene = true + emit_changed(get_edited_property(),new_value) + if new_value.resource_local_to_scene == false: + new_value.resource_local_to_scene = true + if new_value == mod: + return + + updating = true + mod = new_value + refresh_control() + updating = false diff --git a/addons/numeric-modifiers/numeric_mods_property.gd.uid b/addons/numeric-modifiers/numeric_mods_property.gd.uid new file mode 100644 index 0000000..487f26d --- /dev/null +++ b/addons/numeric-modifiers/numeric_mods_property.gd.uid @@ -0,0 +1 @@ +uid://d0cs3kbl7cvwc diff --git a/addons/numeric-modifiers/plugin.cfg b/addons/numeric-modifiers/plugin.cfg new file mode 100644 index 0000000..5f4c9a8 --- /dev/null +++ b/addons/numeric-modifiers/plugin.cfg @@ -0,0 +1,7 @@ +[plugin] + +name="Numeric Modifiers" +description="Adds a way to export numeric modifiers resource" +author="R34nd0" +version="1.0" +script="plugin.gd" diff --git a/addons/numeric-modifiers/plugin.gd b/addons/numeric-modifiers/plugin.gd new file mode 100644 index 0000000..6ad66b0 --- /dev/null +++ b/addons/numeric-modifiers/plugin.gd @@ -0,0 +1,13 @@ +@tool +extends EditorPlugin + +class_name NumericModifiersPlugin + +var inspector : NumericModsInspector + +func _enter_tree() -> void: + inspector = NumericModsInspector.new() + add_inspector_plugin(inspector) + +func _exit_tree() -> void: + remove_inspector_plugin(inspector) diff --git a/addons/numeric-modifiers/plugin.gd.uid b/addons/numeric-modifiers/plugin.gd.uid new file mode 100644 index 0000000..6af70c4 --- /dev/null +++ b/addons/numeric-modifiers/plugin.gd.uid @@ -0,0 +1 @@ +uid://50hsyqdhr2pe diff --git a/project.godot b/project.godot index 372934c..d1135e0 100644 --- a/project.godot +++ b/project.godot @@ -19,6 +19,10 @@ config/icon="uid://3tgkfxqayrbo" project/assembly_name="Revenge of the Red Dragon Pon of the Red Dragon Pon of the Red Dragon Pon" +[editor_plugins] + +enabled=PackedStringArray("res://addons/numeric-modifiers/plugin.cfg") + [global_group] enemy="Group for all enemy objects. This group should contain Entity node as child."