diff --git a/Babushka.csproj b/Babushka.csproj index 796f4da..e6eea3b 100644 --- a/Babushka.csproj +++ b/Babushka.csproj @@ -6,5 +6,6 @@ + \ No newline at end of file diff --git a/Babushka.sln.DotSettings.user b/Babushka.sln.DotSettings.user index c39fafb..225a89d 100644 --- a/Babushka.sln.DotSettings.user +++ b/Babushka.sln.DotSettings.user @@ -9,6 +9,7 @@ ForceIncluded ForceIncluded ForceIncluded + ForceIncluded ForceIncluded ForceIncluded ForceIncluded diff --git a/addons/dialogic/vesna_style.tres b/addons/dialogic/vesna_style.tres index 905f738..1bfe954 100644 --- a/addons/dialogic/vesna_style.tres +++ b/addons/dialogic/vesna_style.tres @@ -1,4 +1,4 @@ -[gd_resource type="Resource" script_class="DialogicStyle" load_steps=20 format=3 uid="uid://benfqi2myyn58"] +[gd_resource type="Resource" script_class="DialogicStyle" load_steps=21 format=3 uid="uid://benfqi2myyn58"] [ext_resource type="Script" uid="uid://dfx2htp24tuvm" path="res://addons/dialogic/Resources/dialogic_style_layer.gd" id="1_kc0s3"] [ext_resource type="PackedScene" uid="uid://c1k5m0w3r40xf" path="res://addons/dialogic/Modules/DefaultLayoutParts/Layer_FullBackground/full_background_layer.tscn" id="2_wjopr"] @@ -15,9 +15,8 @@ script = ExtResource("1_kc0s3") overrides = { "global_bg_color": "Color(0.898039, 0.917647, 0.835294, 1)", -"global_font": "\"res://fonts/ShantellSans/static/ShantellSans-Regular.ttf\"", "global_font_color": "Color(0.258824, 0.12549, 0.054902, 1)", -"global_font_size": "45.0" +"global_font_size": "30.0" } [sub_resource type="Resource" id="Resource_awdqn"] @@ -27,9 +26,6 @@ scene = ExtResource("2_wjopr") [sub_resource type="Resource" id="Resource_5pou4"] script = ExtResource("1_kc0s3") scene = ExtResource("3_depsi") -overrides = { -"portrait_size_mode": "0" -} [sub_resource type="Resource" id="Resource_6xrvb"] script = ExtResource("1_kc0s3") @@ -39,24 +35,14 @@ scene = ExtResource("4_wy5ku") script = ExtResource("1_kc0s3") scene = ExtResource("5_6srh5") overrides = { -"bold_font": "\"res://fonts/ShantellSans/static/ShantellSans-Bold.ttf\"", -"bold_italics_font": "\"res://fonts/ShantellSans/static/ShantellSans-BoldItalic.ttf\"", "box_animation_in": "1", "box_animation_out": "1", -"box_color_custom": "Color(0.88, 0.6688, 0.73568, 1)", -"box_color_use_global": "false", "box_panel": "\"vn_textbox_default_panel.tres\"", -"box_size": "Vector2(1920, 300)", -"italics_font": "\"res://fonts/ShantellSans/static/ShantellSans-Italic.ttf\"", "name_label_box_modulate": "Color(1, 1, 1, 1)", -"name_label_box_offset": "Vector2(200, 0)", -"name_label_box_panel": "\"Babushka_NPC_Namebox_background.tres\"", -"name_label_custom_font_size": "40.0", -"name_label_font": "\"res://fonts/HomemadeApple/HomemadeApple-Regular.ttf\"", +"name_label_box_panel": "\"res://dialog/Babushka_NPC_Namebox_background.tres\"", +"name_label_custom_font_size": "30.0", "name_label_use_global_color": "false", -"name_label_use_global_font": "false", -"next_indicator_texture": "\"res://addons/dialogic/Example Assets/next-indicator/next-indicator-dialogic-2.png\"", -"normal_font": "\"res://fonts/ShantellSans/static/ShantellSans-Regular.ttf\"", +"next_indicator_enabled": "false", "text_alignment": "1", "text_size": "40.0", "typing_sounds_end_sound": "\"res://audio/sfx/UI/Dialog/SFX_Dialog_Open_01.wav\"", @@ -87,10 +73,14 @@ scene = ExtResource("8_4ig6v") script = ExtResource("1_kc0s3") scene = ExtResource("9_gni8k") +[sub_resource type="Resource" id="Resource_uu1x2"] +script = ExtResource("1_kc0s3") +scene = ExtResource("6_iipq0") + [resource] script = ExtResource("10_l174f") name = "vesna_style" -layer_list = Array[String](["10", "11", "12", "13", "14", "15", "16", "17"]) +layer_list = Array[String](["10", "11", "12", "13", "14", "15", "16", "17", "18"]) layer_info = { "": SubResource("Resource_qnla8"), "10": SubResource("Resource_awdqn"), @@ -100,6 +90,7 @@ layer_info = { "14": SubResource("Resource_qtijl"), "15": SubResource("Resource_nalij"), "16": SubResource("Resource_ymn1b"), -"17": SubResource("Resource_8j3qh") +"17": SubResource("Resource_8j3qh"), +"18": SubResource("Resource_uu1x2") } metadata/_latest_layer = "13" diff --git a/dialog/NPC_narrative.tres b/dialog/NPC_narrative.tres index 9beb54c..8acc773 100644 --- a/dialog/NPC_narrative.tres +++ b/dialog/NPC_narrative.tres @@ -1,4 +1,4 @@ -[gd_resource type="Resource" script_class="DialogicStyle" load_steps=21 format=3 uid="uid://f7q6jac5tsk8"] +[gd_resource type="Resource" script_class="DialogicStyle" load_steps=22 format=3 uid="uid://f7q6jac5tsk8"] [ext_resource type="Script" uid="uid://dfx2htp24tuvm" path="res://addons/dialogic/Resources/dialogic_style_layer.gd" id="1_0jwhi"] [ext_resource type="PackedScene" uid="uid://cqpb3ie51rwl5" path="res://addons/dialogic/Modules/DefaultLayoutParts/Base_Default/default_layout_base.tscn" id="1_8wrfq"] @@ -17,9 +17,8 @@ script = ExtResource("1_0jwhi") scene = ExtResource("1_8wrfq") overrides = { "global_bg_color": "Color(0.898375, 0.917922, 0.835355, 1)", -"global_font": "\"res://fonts/ShantellSans/static/ShantellSans-Regular.ttf\"", "global_font_color": "Color(0.257812, 0.125248, 0.0533752, 1)", -"global_font_size": "45.0" +"global_font_size": "30.0" } [sub_resource type="Resource" id="Resource_uxnk3"] @@ -29,9 +28,6 @@ scene = ExtResource("2_8wrfq") [sub_resource type="Resource" id="Resource_ihoat"] script = ExtResource("1_0jwhi") scene = ExtResource("3_t7aeg") -overrides = { -"portrait_size_mode": "0" -} [sub_resource type="Resource" id="Resource_pw0bl"] script = ExtResource("1_0jwhi") @@ -41,27 +37,17 @@ scene = ExtResource("4_85y6g") script = ExtResource("1_0jwhi") scene = ExtResource("5_reo2u") overrides = { -"bold_font": "\"res://fonts/ShantellSans/static/ShantellSans-Bold.ttf\"", -"bold_italics_font": "\"res://fonts/ShantellSans/static/ShantellSans-BoldItalic.ttf\"", "box_animation_in": "1", "box_animation_out": "1", "box_panel": "\"vn_textbox_default_panel.tres\"", -"box_size": "Vector2(1920, 300)", -"italics_font": "\"res://fonts/ShantellSans/static/ShantellSans-Italic.ttf\"", "name_label_alignment": "2", "name_label_box_modulate": "Color(1, 1, 1, 1)", -"name_label_box_offset": "Vector2(-200, 0)", "name_label_box_panel": "\"res://dialog/Babushka_NPC_Namebox_background.tres\"", "name_label_custom_font_size": "30.0", -"name_label_font": "\"res://fonts/HomemadeApple/HomemadeApple-Regular.ttf\"", "name_label_use_global_color": "false", -"name_label_use_global_font": "false", -"next_indicator_texture": "\"res://addons/dialogic/Example Assets/next-indicator/next-indicator-dialogic-2.png\"", -"normal_font": "\"res://fonts/ShantellSans/static/ShantellSans-Regular.ttf\"", +"next_indicator_enabled": "false", "text_alignment": "1", -"text_custom_color": "Color(0.8980392, 0.91764706, 0.8352941, 1)", "text_size": "40.0", -"text_use_global_font": "false", "typing_sounds_end_sound": "\"res://audio/sfx/UI/Dialog/SFX_Dialog_Open_01.wav\"", "typing_sounds_sounds_folder": "\"res://audio/sfx/typing\"" } @@ -90,10 +76,14 @@ scene = ExtResource("8_h83v4") script = ExtResource("1_0jwhi") scene = ExtResource("9_4c2uo") +[sub_resource type="Resource" id="Resource_0jwhi"] +script = ExtResource("1_0jwhi") +scene = ExtResource("6_i6h15") + [resource] script = ExtResource("10_e3ue2") name = "NPC_narrative" -layer_list = Array[String](["10", "11", "12", "13", "14", "15", "16", "17"]) +layer_list = Array[String](["10", "11", "12", "13", "14", "15", "16", "17", "18"]) layer_info = { "": SubResource("Resource_wg0yj"), "10": SubResource("Resource_uxnk3"), @@ -103,6 +93,7 @@ layer_info = { "14": SubResource("Resource_clhbu"), "15": SubResource("Resource_umvdi"), "16": SubResource("Resource_ci2ul"), -"17": SubResource("Resource_sadu5") +"17": SubResource("Resource_sadu5"), +"18": SubResource("Resource_0jwhi") } -metadata/_latest_layer = "14" +metadata/_latest_layer = "13" diff --git a/project.godot b/project.godot index c7a810f..177a1b4 100644 --- a/project.godot +++ b/project.godot @@ -144,6 +144,8 @@ directories/tres_directory={ "default_bus_layout": "res://audio/default_bus_layout.tres", "default_stylebox": "res://addons/dialogic/Modules/DefaultLayoutParts/Layer_SpeakerPortraitTextbox/default_stylebox.tres", "default_vn_style": "res://addons/dialogic/Modules/DefaultLayoutParts/Style_VN_Default/default_vn_style.tres", +"event_colorButtonClicked": "res://resources/low code/test/event_colorButtonClicked.tres", +"event_textLabelClicked": "res://resources/low code/test/event_textLabelClicked.tres", "farming_equipment_glossary": "res://dialog/farming_equipment_glossary.tres", "hoe": "res://resources/items/hoe.tres", "inventory_interactable_outline": "res://art/materials/inventory_interactable_outline.tres", @@ -166,6 +168,8 @@ directories/tres_directory={ "tomato": "res://resources/items/tomato.tres", "tomato_seed": "res://resources/items/tomato_seed.tres", "unselected_stylebox": "res://addons/dialogic/Editor/Events/styles/unselected_stylebox.tres", +"var_ColorTestValue": "res://resources/low code/test/var_ColorTestValue.tres", +"var_Counter": "res://resources/low code/test/var_Counter.tres", "vesna_style": "res://addons/dialogic/vesna_style.tres", "vn_textbox_default_panel": "res://addons/dialogic/Modules/DefaultLayoutParts/Layer_VN_Textbox/vn_textbox_default_panel.tres", "vn_textbox_name_label_panel": "res://addons/dialogic/Modules/DefaultLayoutParts/Layer_VN_Textbox/vn_textbox_name_label_panel.tres", diff --git a/resources/low code/test/event_colorButtonClicked.tres b/resources/low code/test/event_colorButtonClicked.tres new file mode 100644 index 0000000..39d8efc --- /dev/null +++ b/resources/low code/test/event_colorButtonClicked.tres @@ -0,0 +1,7 @@ +[gd_resource type="Resource" script_class="EventResource" load_steps=2 format=3 uid="uid://bfw1dfd0r8avr"] + +[ext_resource type="Script" uid="uid://ci3t5mvnopntg" path="res://scripts/CSharp/Low Code/Events/EventResource.cs" id="1_yg3mc"] + +[resource] +script = ExtResource("1_yg3mc") +metadata/_custom_type_script = "uid://ci3t5mvnopntg" diff --git a/resources/low code/test/event_textLabelClicked.tres b/resources/low code/test/event_textLabelClicked.tres new file mode 100644 index 0000000..1c2fe6f --- /dev/null +++ b/resources/low code/test/event_textLabelClicked.tres @@ -0,0 +1,7 @@ +[gd_resource type="Resource" script_class="EventResource" load_steps=2 format=3 uid="uid://boijwlxmth68v"] + +[ext_resource type="Script" uid="uid://ci3t5mvnopntg" path="res://scripts/CSharp/Low Code/Events/EventResource.cs" id="1_vfqv2"] + +[resource] +script = ExtResource("1_vfqv2") +metadata/_custom_type_script = "uid://ci3t5mvnopntg" diff --git a/resources/low code/test/var_ColorTestValue.tres b/resources/low code/test/var_ColorTestValue.tres new file mode 100644 index 0000000..1c579b1 --- /dev/null +++ b/resources/low code/test/var_ColorTestValue.tres @@ -0,0 +1,8 @@ +[gd_resource type="Resource" script_class="VariableResource" load_steps=2 format=3 uid="uid://dpnre2bn041jm"] + +[ext_resource type="Script" uid="uid://dtvx2cakx0bey" path="res://scripts/CSharp/Low Code/Variables/VariableResource.cs" id="1_h8big"] + +[resource] +script = ExtResource("1_h8big") +Payload = Color(0, 0, 0, 1) +metadata/_custom_type_script = "uid://dtvx2cakx0bey" diff --git a/resources/low code/test/var_Counter.tres b/resources/low code/test/var_Counter.tres new file mode 100644 index 0000000..02a605b --- /dev/null +++ b/resources/low code/test/var_Counter.tres @@ -0,0 +1,8 @@ +[gd_resource type="Resource" script_class="VariableResource" load_steps=2 format=3 uid="uid://c6iw30ydc0qa0"] + +[ext_resource type="Script" uid="uid://dtvx2cakx0bey" path="res://scripts/CSharp/Low Code/Variables/VariableResource.cs" id="1_sbnhb"] + +[resource] +script = ExtResource("1_sbnhb") +Payload = 0 +metadata/_custom_type_script = "uid://dtvx2cakx0bey" diff --git a/scenes/Babushka_scene_indoor_vesnas_room.tscn b/scenes/Babushka_scene_indoor_vesnas_room.tscn index c2dc3f3..c2b4f8d 100644 --- a/scenes/Babushka_scene_indoor_vesnas_room.tscn +++ b/scenes/Babushka_scene_indoor_vesnas_room.tscn @@ -98,7 +98,6 @@ _followNode = NodePath("../Vesna/CharacterBody2D") [node name="BedInteraction" parent="." instance=ExtResource("8_phqdf")] position = Vector2(-1429, 487) -_useOutline = true _useSprite = false _id = 1 @@ -109,7 +108,6 @@ toStatus = 2 [node name="DoorInteraction" parent="." instance=ExtResource("8_phqdf")] position = Vector2(777, 201) -_useOutline = true _useSprite = false _id = 0 diff --git a/scenes/testing/eventTest.tscn b/scenes/testing/eventTest.tscn new file mode 100644 index 0000000..f6dae4b --- /dev/null +++ b/scenes/testing/eventTest.tscn @@ -0,0 +1,101 @@ +[gd_scene load_steps=10 format=3 uid="uid://6n3p3psmxovj"] + +[ext_resource type="Script" uid="uid://pqemey80frcq" path="res://scripts/CSharp/Low Code/Variables/VariableListener.cs" id="1_4h3ry"] +[ext_resource type="Script" uid="uid://bc6uaaxsx5k5p" path="res://scripts/CSharp/Low Code/Events/EventListener.cs" id="1_w5ykc"] +[ext_resource type="Resource" uid="uid://dpnre2bn041jm" path="res://resources/low code/test/var_ColorTestValue.tres" id="2_bj4kf"] +[ext_resource type="Script" uid="uid://b5dotkx17gvxg" path="res://scripts/CSharp/Low Code/Events/EventRaiser.cs" id="3_bj4kf"] +[ext_resource type="Resource" uid="uid://boijwlxmth68v" path="res://resources/low code/test/event_textLabelClicked.tres" id="5_4h3ry"] +[ext_resource type="Script" uid="uid://co1b320qemg1i" path="res://scripts/CSharp/Low Code/Randomizer/VariantRandomizer.cs" id="5_nm8dh"] +[ext_resource type="Script" uid="uid://dco37q6ddm8kv" path="res://scripts/CSharp/Low Code/Variables/VariantValueChanger/VariantToString.cs" id="7_nm8dh"] +[ext_resource type="Resource" uid="uid://c6iw30ydc0qa0" path="res://resources/low code/test/var_Counter.tres" id="9_44nfx"] +[ext_resource type="Script" uid="uid://d1y23ytkt1w2j" path="res://scripts/CSharp/Low Code/Variables/VariantValueChanger/VariantIncrementor.cs" id="10_p6d2q"] + +[node name="EventTest" type="Node2D"] + +[node name="Control" type="Control" parent="."] +layout_mode = 3 +anchors_preset = 0 +offset_top = -1.0 +offset_right = 513.0 +offset_bottom = 329.0 + +[node name="ColorRect" type="ColorRect" parent="Control"] +layout_mode = 0 +offset_right = 178.0 +offset_bottom = 145.0 +script = ExtResource("1_4h3ry") +_variableResources = Array[Object]([ExtResource("2_bj4kf")]) + +[node name="ChangeColorButton" type="Button" parent="Control"] +layout_mode = 0 +offset_top = 148.0 +offset_right = 112.0 +offset_bottom = 179.0 +text = "Change Color +" +script = ExtResource("5_nm8dh") +_variableResource = ExtResource("2_bj4kf") + +[node name="LabelTextEventButton" type="Button" parent="Control"] +layout_mode = 0 +offset_left = 194.0 +offset_top = 148.0 +offset_right = 351.0 +offset_bottom = 179.0 +text = "Show Event Text +" +script = ExtResource("3_bj4kf") +_eventResources = Array[Object]([ExtResource("5_4h3ry")]) + +[node name="TestLabel" type="Label" parent="Control"] +visible = false +layout_mode = 0 +offset_left = 237.0 +offset_top = 54.0 +offset_right = 277.0 +offset_bottom = 77.0 +text = "[Dieser Text erscheint, +wenn das Event richtig +verknüpft ist]" +script = ExtResource("1_w5ykc") +_eventResources = Array[Object]([ExtResource("5_4h3ry")]) + +[node name="LabelTextEventButton2" type="Button" parent="Control"] +layout_mode = 0 +offset_left = 361.0 +offset_top = 148.0 +offset_right = 518.0 +offset_bottom = 179.0 +text = "get current number +" + +[node name="TestLabel2" type="Label" parent="Control"] +layout_mode = 0 +offset_left = 432.0 +offset_top = 117.0 +offset_right = 472.0 +offset_bottom = 166.0 +text = "0 +" +script = ExtResource("7_nm8dh") +_resource = ExtResource("9_44nfx") + +[node name="Camera2D" type="Camera2D" parent="."] +position = Vector2(239, 110) +zoom = Vector2(3.4, 3.4) + +[node name="Timer" type="Timer" parent="."] +wait_time = 0.5 +autostart = true + +[node name="CountLoop" type="Node" parent="Timer"] +script = ExtResource("10_p6d2q") +_resource = ExtResource("9_44nfx") + +[connection signal="NewEventPayload" from="Control/ColorRect" to="Control/ColorRect" method="set_color"] +[connection signal="pressed" from="Control/ChangeColorButton" to="Control/ChangeColorButton" method="RandomizeEventResource"] +[connection signal="pressed" from="Control/LabelTextEventButton" to="Control/LabelTextEventButton" method="RaiseEvents"] +[connection signal="EventRaised" from="Control/TestLabel" to="Control/TestLabel" method="show"] +[connection signal="pressed" from="Control/LabelTextEventButton2" to="Control/TestLabel2" method="ConvertToString"] +[connection signal="PayloadAsString" from="Control/TestLabel2" to="Control/TestLabel2" method="set_text"] +[connection signal="timeout" from="Timer" to="Timer/CountLoop" method="Increment"] diff --git a/scripts/CSharp/Low Code/Events/EventListener.cs b/scripts/CSharp/Low Code/Events/EventListener.cs new file mode 100644 index 0000000..085fbf4 --- /dev/null +++ b/scripts/CSharp/Low Code/Events/EventListener.cs @@ -0,0 +1,62 @@ +using Godot; +using Godot.Collections; + +namespace Babushka.scripts.CSharp.Low_Code.Events; + +/// +/// Listens to an as long as this node is in the tree (i.e., during playtime). +/// +public partial class EventListener : Node +{ + /// + /// The event resource to listen to. + /// + [Export] private Array _eventResources; + + /// + /// Log to console when this event is being raised. + /// + [Export] private bool _showLog; + + /// + /// The signal that is triggered when this listener is called by one of the . + /// + [Signal] public delegate void EventRaisedEventHandler(); + + /// + /// Subscribes to all s present in the array. + /// + /// + public override void _EnterTree() + { + foreach (var eventRes in _eventResources) + { + eventRes.RegisterListener(this); + } + } + + /// + /// Unsubscribes from all s present in the array. + /// + /// + public override void _ExitTree() + { + foreach (var eventRes in _eventResources) + { + eventRes.UnregisterListener(this); + } + } + + /// + /// Called by a s from the array. + /// Propagates the event by emitting signal. + /// + public void EventInvoked() + { + if(_showLog) + GD.Print("Event Raised on: " + Name); + EmitSignal(SignalName.EventRaised); + } + + +} \ No newline at end of file diff --git a/scripts/CSharp/Low Code/Events/EventListener.cs.uid b/scripts/CSharp/Low Code/Events/EventListener.cs.uid new file mode 100644 index 0000000..a140a15 --- /dev/null +++ b/scripts/CSharp/Low Code/Events/EventListener.cs.uid @@ -0,0 +1 @@ +uid://bc6uaaxsx5k5p diff --git a/scripts/CSharp/Low Code/Events/EventRaiser.cs b/scripts/CSharp/Low Code/Events/EventRaiser.cs new file mode 100644 index 0000000..07e419e --- /dev/null +++ b/scripts/CSharp/Low Code/Events/EventRaiser.cs @@ -0,0 +1,26 @@ +using Godot; +using Godot.Collections; + +namespace Babushka.scripts.CSharp.Low_Code.Events; + +/// +/// Raises one or more s from the scene. +/// +public partial class EventRaiser : Node +{ + /// + /// The s to call + /// + [Export] Array _eventResources; + + /// + /// Raises all s present in . + /// + public void RaiseEvents() + { + foreach (var eventRes in _eventResources) + { + eventRes.Raise(); + } + } +} \ No newline at end of file diff --git a/scripts/CSharp/Low Code/Events/EventRaiser.cs.uid b/scripts/CSharp/Low Code/Events/EventRaiser.cs.uid new file mode 100644 index 0000000..5c245d3 --- /dev/null +++ b/scripts/CSharp/Low Code/Events/EventRaiser.cs.uid @@ -0,0 +1 @@ +uid://b5dotkx17gvxg diff --git a/scripts/CSharp/Low Code/Events/EventResource.cs b/scripts/CSharp/Low Code/Events/EventResource.cs new file mode 100644 index 0000000..4b829a3 --- /dev/null +++ b/scripts/CSharp/Low Code/Events/EventResource.cs @@ -0,0 +1,65 @@ +using System.Collections.Generic; +using Godot; + +namespace Babushka.scripts.CSharp.Low_Code.Events; + +/// +/// Represents an event in the project space. +/// Can be called by and subscribed to by . +/// +[GlobalClass] [Tool] +public partial class EventResource : Resource +{ + /// + /// Log into console when this event resource is adding or removing listeners, and when it's raised. + /// + [Export] private bool _showLog; + + /// + /// Raise-Button Call with Editor Export for easier debugging. + /// Beware: This will only work with custom event listeners that register at edit-time. + /// Standard register and deregister during playtime. + /// + [ExportToolButton("Raise")] Callable _raiseAction => Callable.From(Raise); + + private List _eventListeners = new (); + + /// + /// Adds an EventListener to the calling list for this event. + /// + /// + public void RegisterListener(EventListener listener) + { + if(_showLog) + GD.Print("Registering listener " + listener); + _eventListeners.Add(listener); + } + + /// + /// Removes an Eventlistener from the calling list for this event. + /// + /// + public void UnregisterListener(EventListener listener) + { + if(_showLog) + GD.Print("Unregistering listener " + listener); + _eventListeners.Remove(listener); + } + + /// + /// Raises this event on all current listeners. + /// + public void Raise() + { + if(_showLog) + GD.Print("Raising event: " + ResourcePath.GetFile().TrimSuffix(".tres")); + + foreach (var eventListener in _eventListeners) + { + eventListener.EventInvoked(); + } + } + + + +} \ No newline at end of file diff --git a/scripts/CSharp/Low Code/Events/EventResource.cs.uid b/scripts/CSharp/Low Code/Events/EventResource.cs.uid new file mode 100644 index 0000000..207618d --- /dev/null +++ b/scripts/CSharp/Low Code/Events/EventResource.cs.uid @@ -0,0 +1 @@ +uid://ci3t5mvnopntg diff --git a/scripts/CSharp/Low Code/Randomizer/VariantRandomizer.cs b/scripts/CSharp/Low Code/Randomizer/VariantRandomizer.cs new file mode 100644 index 0000000..140b400 --- /dev/null +++ b/scripts/CSharp/Low Code/Randomizer/VariantRandomizer.cs @@ -0,0 +1,55 @@ +using System; +using Babushka.scripts.CSharp.Low_Code.Events; +using Babushka.scripts.CSharp.Low_Code.Variables; +using Godot; + + +namespace Babushka.scripts.CSharp.Low_Code.Randomizer; + +/// +/// A class to randomize the payload value of select types of s. +/// +public partial class VariantRandomizer : Node +{ + /// + /// The event resource to work on. + /// + [Export] public VariableResource _variableResource; + + /// + /// Sets the payload of a randomizable event resource to a random value. + /// + public void RandomizeEventResource() + { + switch (_variableResource.Payload.VariantType) + { + case Variant.Type.Color: + _variableResource.Payload= GetRandomColor(); + break; + case Variant.Type.Int: + _variableResource.Payload= GetRandomInt(); + break; + case Variant.Type.Float: + _variableResource.Payload= GetRandomFloat(); + break; + } + } + + private Color GetRandomColor() + { + Random rand = new Random(); + return new Color(rand.NextSingle(), rand.NextSingle(), rand.NextSingle(), 1.0f); + } + + private int GetRandomInt() + { + Random rand = new Random(); + return rand.Next(); + } + + private float GetRandomFloat() + { + Random rand = new Random(); + return rand.NextSingle(); + } +} \ No newline at end of file diff --git a/scripts/CSharp/Low Code/Randomizer/VariantRandomizer.cs.uid b/scripts/CSharp/Low Code/Randomizer/VariantRandomizer.cs.uid new file mode 100644 index 0000000..ece8168 --- /dev/null +++ b/scripts/CSharp/Low Code/Randomizer/VariantRandomizer.cs.uid @@ -0,0 +1 @@ +uid://co1b320qemg1i diff --git a/scripts/CSharp/Low Code/Variables/VariableGetter.cs b/scripts/CSharp/Low Code/Variables/VariableGetter.cs new file mode 100644 index 0000000..d5138f9 --- /dev/null +++ b/scripts/CSharp/Low Code/Variables/VariableGetter.cs @@ -0,0 +1,30 @@ +using Godot; + +namespace Babushka.scripts.CSharp.Low_Code.Variables; + +/// +/// An active getter component for calling the payload value of a . +/// +public partial class VariableGetter : Node +{ + /// + /// The event resource to listen to. + /// + [Export] private VariableResource _variableResource; + + /// + /// A signal that is triggered when the payload of one of the is called. + /// + [Signal] public delegate void GetPayloadEventHandler(Variant payload); + + /// + /// Gets the Variant payload of a VariableResource on demand. + /// + /// + public Variant Get() + { + Variant payload = _variableResource.Payload; + EmitSignal(SignalName.GetPayload, payload); + return payload; + } +} \ No newline at end of file diff --git a/scripts/CSharp/Low Code/Variables/VariableGetter.cs.uid b/scripts/CSharp/Low Code/Variables/VariableGetter.cs.uid new file mode 100644 index 0000000..1a4682f --- /dev/null +++ b/scripts/CSharp/Low Code/Variables/VariableGetter.cs.uid @@ -0,0 +1 @@ +uid://34okoih6wkmu diff --git a/scripts/CSharp/Low Code/Variables/VariableListener.cs b/scripts/CSharp/Low Code/Variables/VariableListener.cs new file mode 100644 index 0000000..2576015 --- /dev/null +++ b/scripts/CSharp/Low Code/Variables/VariableListener.cs @@ -0,0 +1,72 @@ +using Godot; +using Godot.Collections; + +namespace Babushka.scripts.CSharp.Low_Code.Variables; + +/// +/// A passive Node that listens to valuechange-events on a . +/// +public partial class VariableListener : Node +{ + /// + /// The event resource to listen to. + /// + [Export] private Array _variableResources; + + /// + /// Log to console when this event is being raised. + /// + [Export] private bool _showLog; + + /// + /// A signal that is triggered when the payload of one of the changed. + /// + [Signal] public delegate void PayloadChangedEventHandler(Variant payload, Variant oldPayload); + + /// + /// A signal that is triggered when the payload of one of the changed. + /// + [Signal] public delegate void NewEventPayloadEventHandler(Variant payload); + + /// + /// A signal that is triggered when the payload of one of the changed. + /// + [Signal] public delegate void OldEventPayloadEventHandler(Variant oldPayload); + + /// + /// Subscribes to all s present in the array. + /// + /// + public override void _EnterTree() + { + foreach (var resource in _variableResources) + { + resource.RegisterListener(this); + } + } + + /// + /// Unsubscribes from all s present in the array. + /// + /// + public override void _ExitTree() + { + foreach (var variableResource in _variableResources) + { + variableResource.UnregisterListener(this); + } + } + + /// + /// Called by a s from the array. + /// Propagates the event by emitting signal. + /// + public void EventPayloadChanged(Variant payload, Variant oldPayload) + { + if(_showLog) + GD.Print($"Calling Event Payload Changed Signals on: " + Name); + EmitSignal(SignalName.PayloadChanged, payload, oldPayload); + EmitSignal(SignalName.NewEventPayload, payload); + EmitSignal(SignalName.OldEventPayload, oldPayload); + } +} \ No newline at end of file diff --git a/scripts/CSharp/Low Code/Variables/VariableListener.cs.uid b/scripts/CSharp/Low Code/Variables/VariableListener.cs.uid new file mode 100644 index 0000000..8ed0b0c --- /dev/null +++ b/scripts/CSharp/Low Code/Variables/VariableListener.cs.uid @@ -0,0 +1 @@ +uid://pqemey80frcq diff --git a/scripts/CSharp/Low Code/Variables/VariableResource.cs b/scripts/CSharp/Low Code/Variables/VariableResource.cs new file mode 100644 index 0000000..20d5240 --- /dev/null +++ b/scripts/CSharp/Low Code/Variables/VariableResource.cs @@ -0,0 +1,76 @@ +using System.Collections.Generic; +using Godot; + +namespace Babushka.scripts.CSharp.Low_Code.Variables; + +/// +/// A value wrapper resource used to store state values and notify ingame scripts. +/// +[GlobalClass] +public partial class VariableResource : Resource +{ + /// + /// Log into console when this event resource is adding or removing listeners, and when it's raised. + /// + [Export] private bool _showLog; + + /// + /// Public property that manages the access to the payload. + /// Triggers the ValueChange-function when set to a new value. + /// + [Export] + public Variant Payload + { + get { return _payload; } + set + { + if (!_payload.Equals(value)) + { + _lastPayload = _payload; + _payload = value; + ValueChangeHandler(); + } + } + } + + private Variant _payload; + private Variant _lastPayload; + + private List _varListeners = new (); + + /// + /// Adds an EventListener to the calling list for this event. + /// + /// + public void RegisterListener(VariableListener listener) + { + if(_showLog) + GD.Print("Registering listener " + listener); + _varListeners.Add(listener); + } + + /// + /// Removes an Eventlistener from the calling list for this event. + /// + /// + public void UnregisterListener(VariableListener listener) + { + if(_showLog) + GD.Print("Unregistering listener " + listener); + _varListeners.Remove(listener); + } + + /// + /// Called when the Payload value changed. + /// + public void ValueChangeHandler() + { + if(_showLog) + GD.Print($"Event payload changed from {_lastPayload} to {_payload} on event resource: " + ResourcePath.GetFile().TrimSuffix(".tres")); + + foreach (var eventListener in _varListeners) + { + eventListener.EventPayloadChanged(_payload, _lastPayload); + } + } +} \ No newline at end of file diff --git a/scripts/CSharp/Low Code/Variables/VariableResource.cs.uid b/scripts/CSharp/Low Code/Variables/VariableResource.cs.uid new file mode 100644 index 0000000..dc3a112 --- /dev/null +++ b/scripts/CSharp/Low Code/Variables/VariableResource.cs.uid @@ -0,0 +1 @@ +uid://dtvx2cakx0bey diff --git a/scripts/CSharp/Low Code/Variables/VariantValueChanger/VariantIncrementor.cs b/scripts/CSharp/Low Code/Variables/VariantValueChanger/VariantIncrementor.cs new file mode 100644 index 0000000..3118535 --- /dev/null +++ b/scripts/CSharp/Low Code/Variables/VariantValueChanger/VariantIncrementor.cs @@ -0,0 +1,22 @@ +using Godot; + +namespace Babushka.scripts.CSharp.Low_Code.Variables.VariantValueChanger; + +public partial class VariantIncrementor : Node +{ + [Export] private VariableResource _resource; + + public void Increment() + { + int integerValue = _resource.Payload.AsInt32(); + integerValue++; + _resource.Payload = integerValue; + } + + public void Decrement() + { + int integerValue = _resource.Payload.AsInt32(); + integerValue--; + _resource.Payload = integerValue; + } +} \ No newline at end of file diff --git a/scripts/CSharp/Low Code/Variables/VariantValueChanger/VariantIncrementor.cs.uid b/scripts/CSharp/Low Code/Variables/VariantValueChanger/VariantIncrementor.cs.uid new file mode 100644 index 0000000..f6133c0 --- /dev/null +++ b/scripts/CSharp/Low Code/Variables/VariantValueChanger/VariantIncrementor.cs.uid @@ -0,0 +1 @@ +uid://d1y23ytkt1w2j diff --git a/scripts/CSharp/Low Code/Variables/VariantValueChanger/VariantToString.cs b/scripts/CSharp/Low Code/Variables/VariantValueChanger/VariantToString.cs new file mode 100644 index 0000000..1219487 --- /dev/null +++ b/scripts/CSharp/Low Code/Variables/VariantValueChanger/VariantToString.cs @@ -0,0 +1,16 @@ +using Godot; + +namespace Babushka.scripts.CSharp.Low_Code.Variables.VariantValueChanger; + +public partial class VariantToString : Node +{ + [Export] private VariableResource _resource; + + [Signal] public delegate void PayloadAsStringEventHandler(string payloadAsString); + + + public void ConvertToString() + { + EmitSignal(SignalName.PayloadAsString, _resource.Payload.AsString()); + } +} \ No newline at end of file diff --git a/scripts/CSharp/Low Code/Variables/VariantValueChanger/VariantToString.cs.uid b/scripts/CSharp/Low Code/Variables/VariantValueChanger/VariantToString.cs.uid new file mode 100644 index 0000000..9aced51 --- /dev/null +++ b/scripts/CSharp/Low Code/Variables/VariantValueChanger/VariantToString.cs.uid @@ -0,0 +1 @@ +uid://dco37q6ddm8kv