From 830f0ccd9c139138dc0a81510299b04006736e4a Mon Sep 17 00:00:00 2001 From: Slashscreen Date: Sun, 16 Jul 2023 02:48:09 -0700 Subject: [PATCH] hotfix: screwed up goapcomponent --- .../Editor/Editor/editor_quest_goal.gd | 43 ---- .../Editor/Editor/editor_quest_step.gd | 151 ------------ .../journalgd/Editor/Editor/goal_prefab.tscn | 61 ----- .../journalgd/Editor/Editor/quest_editor.gd | 118 --------- .../Editor/Editor/quest_editor_screen.tscn | 56 ----- addons/journalgd/Editor/Editor/quest_step.gd | 4 - .../journalgd/Editor/Editor/step_prefab.tscn | 136 ----------- .../QuestNode/QuestNode/quest_engine.gd | 230 ------------------ .../QuestNode/QuestNode/quest_goal.gd | 85 ------- .../QuestNode/QuestNode/quest_node.gd | 71 ------ .../QuestNode/QuestNode/quest_step.gd | 89 ------- addons/journalgd/Saved/Saved/saved_goal.gd | 19 -- addons/journalgd/Saved/Saved/saved_quest.gd | 12 - addons/journalgd/Saved/Saved/saved_step.gd | 47 ---- .../scripts/components/goap_component.gd | 2 +- 15 files changed, 1 insertion(+), 1123 deletions(-) delete mode 100644 addons/journalgd/Editor/Editor/editor_quest_goal.gd delete mode 100644 addons/journalgd/Editor/Editor/editor_quest_step.gd delete mode 100644 addons/journalgd/Editor/Editor/goal_prefab.tscn delete mode 100644 addons/journalgd/Editor/Editor/quest_editor.gd delete mode 100644 addons/journalgd/Editor/Editor/quest_editor_screen.tscn delete mode 100644 addons/journalgd/Editor/Editor/quest_step.gd delete mode 100644 addons/journalgd/Editor/Editor/step_prefab.tscn delete mode 100644 addons/journalgd/QuestNode/QuestNode/quest_engine.gd delete mode 100644 addons/journalgd/QuestNode/QuestNode/quest_goal.gd delete mode 100644 addons/journalgd/QuestNode/QuestNode/quest_node.gd delete mode 100644 addons/journalgd/QuestNode/QuestNode/quest_step.gd delete mode 100644 addons/journalgd/Saved/Saved/saved_goal.gd delete mode 100644 addons/journalgd/Saved/Saved/saved_quest.gd delete mode 100644 addons/journalgd/Saved/Saved/saved_step.gd diff --git a/addons/journalgd/Editor/Editor/editor_quest_goal.gd b/addons/journalgd/Editor/Editor/editor_quest_goal.gd deleted file mode 100644 index 23b3bcd..0000000 --- a/addons/journalgd/Editor/Editor/editor_quest_goal.gd +++ /dev/null @@ -1,43 +0,0 @@ -@tool -class_name EditorQuestGoal -extends Control - - -var goal_key:String: - get: - return ($VBoxContainer/GoalName as LineEdit).text - set(val): - ($VBoxContainer/GoalName as LineEdit).text = val -var optional:bool: - get: - return ($VBoxContainer/OptionalButton as CheckButton).button_pressed - set(val): - ($VBoxContainer/OptionalButton as CheckButton).button_pressed = val -var filter:String: - get: - return ($VBoxContainer/BaseID as LineEdit).text - set(val): - ($VBoxContainer/BaseID as LineEdit).text = val -var amount:int: - get: - return ($VBoxContainer/HBoxContainer/AmountBox as SpinBox).value - set(val): - ($VBoxContainer/HBoxContainer/AmountBox as SpinBox).value = val -var only_while_active:bool: - get: - return ($VBoxContainer/OnlyWhileActive as CheckBox).button_pressed - set(val): - ($VBoxContainer/OnlyWhileActive as CheckBox).button_pressed = val - - -func _on_delete_pressed() -> void: - queue_free() - $"../../../"._on_delete_goal_pressed() - - -func setup(eg:SavedGoal) -> void: - goal_key = eg.goal_key - optional = eg.optional - filter = eg.filter - amount = eg.amount - only_while_active = eg.only_while_active diff --git a/addons/journalgd/Editor/Editor/editor_quest_step.gd b/addons/journalgd/Editor/Editor/editor_quest_step.gd deleted file mode 100644 index 7eec5b0..0000000 --- a/addons/journalgd/Editor/Editor/editor_quest_step.gd +++ /dev/null @@ -1,151 +0,0 @@ -@tool - -class_name EditorQuestStep -extends GraphNode - - -const GOAL_PREFAB = preload("res://addons/journalgd/Editor/goal_prefab.tscn") -const STEP_COLORS = { - "all" : 0xFF5400FF, # orange - "any" : 0x9E0059FF, # magenta - "branch" : 0xFFBD00FF, # yellow - "start" : 0xABE188FF, # green - "end" : 0xFF0054FF, # pinkish -} - -var is_exit:bool: - get: - return $IsExitButton.button_pressed - set(val): - $IsExitButton.button_pressed = val - _set_title_color() -var step_name:String: - get: - return ($StepName as LineEdit).text - set(val): - ($StepName as LineEdit).text = val - title = val -var next_connections:Array[String] -var step_type:QuestStep.StepType: - get: - match $StepType.get_item_text($StepType.get_selected_id()): - "All": - return QuestStep.StepType.ALL - "Any": - return QuestStep.StepType.ANY - "Branch": - return QuestStep.StepType.BRANCH - _: - return QuestStep.StepType.ALL - set(val): - _set_is_branch(val == QuestStep.StepType.BRANCH) - match val: - QuestStep.StepType.ALL: - $StepType.select(0) - QuestStep.StepType.ANY: - $StepType.select(1) - QuestStep.StepType.BRANCH: - $StepType.select(2) - _: - $StepType.select(0) - _set_title_color() -var mapped_goals:Array: - get: - return get_goals().map(func(x:EditorQuestGoal): return x.name) -var is_entry_step:bool: - get: - return $IsEntryButton.button_pressed - set(val): - $IsEntryButton.button_pressed = val - set_slot_enabled_left(4, not val) - _set_title_color() - - -func setup(qs:SavedStep) -> void: - is_exit = qs.is_final_step - step_name = qs.step_name - position_offset = qs.editor_coordinates - print(position) - is_entry_step = qs.is_entry_step - for g in qs.goals: - add_goal(g) - step_type = qs.step_type # put this at end because we need to have the goals count - _set_title_color() - - -func _update_is_exit(val:bool): - print("update is exit") - set_slot_enabled_right(0, not val) - _set_title_color() - - -func _on_delete_node_button_up() -> void: - print("Delete step") - get_parent().delete_node(name) - - -func _set_title_color() -> void: - if is_exit: - theme.set_color(&"title_color", &"GraphNode", Color.hex(STEP_COLORS.end)) - return - if is_entry_step: - theme.set_color(&"title_color", &"GraphNode", Color.hex(STEP_COLORS.start)) - return - match step_type: - QuestStep.StepType.ALL: - theme.set_color(&"title_color", &"GraphNode", Color.hex(STEP_COLORS.all)) - QuestStep.StepType.ANY: - theme.set_color( &"title_color", &"GraphNode", Color.hex(STEP_COLORS.any)) - QuestStep.StepType.BRANCH: - theme.set_color(&"title_color", &"GraphNode", Color.hex(STEP_COLORS.branch)) - - -## Handles dealing with multiple output points with branches. -func _set_is_branch(state:bool) -> void: - print("set is goal") - var conn_count = get_connection_output_count() - if state: - if is_exit: - return - var goal_amount = get_goals().size() - for i in conn_count: - set_slot_enabled_right(i, false) - for i in goal_amount: - set_slot_enabled_right(i, true) - else: - for i in conn_count: - set_slot_enabled_right(i, false) - set_slot_enabled_right(0, not is_exit) - - -func get_goals() -> Array: - return $Scroll/GoalsContainer.get_children() - - -func _on_add_goal() -> EditorQuestGoal: - var n = GOAL_PREFAB.instantiate() - $Scroll/GoalsContainer.add_child(n) - n.owner = self - _set_is_branch(step_type == QuestStep.StepType.BRANCH) - return n - - -func _on_delete_goal_pressed() -> void: - _set_is_branch(step_type == QuestStep.StepType.BRANCH) - - -func add_goal(g:SavedGoal) -> EditorQuestGoal: - var n = GOAL_PREFAB.instantiate() - n.setup(g) - $Scroll/GoalsContainer.add_child(n) - n.owner = self - return n - - -func _ready() -> void: - theme = theme.duplicate(true) - $StepType.item_selected.connect(func(x:int): _set_is_branch(x == 2)) - $IsEntryButton.toggled.connect(func(state:bool): set_slot_enabled_left(4, not state)) - $StepName.text_changed.connect(func(x): title = x) - resize_request.connect(func(new_minsize:Vector2):size = new_minsize) - close_request.connect(_on_delete_node_button_up.bind()) diff --git a/addons/journalgd/Editor/Editor/goal_prefab.tscn b/addons/journalgd/Editor/Editor/goal_prefab.tscn deleted file mode 100644 index 6a21d46..0000000 --- a/addons/journalgd/Editor/Editor/goal_prefab.tscn +++ /dev/null @@ -1,61 +0,0 @@ -[gd_scene load_steps=2 format=3 uid="uid://dr81icok2kmy0"] - -[ext_resource type="Script" path="res://addons/journalgd/Editor/editor_quest_goal.gd" id="1_h4rvw"] - -[node name="Goal" type="PanelContainer"] -anchors_preset = 15 -anchor_right = 1.0 -anchor_bottom = 1.0 -offset_right = -992.0 -offset_bottom = -399.0 -grow_horizontal = 2 -grow_vertical = 2 -size_flags_horizontal = 3 -size_flags_vertical = 3 -script = ExtResource("1_h4rvw") - -[node name="VBoxContainer" type="VBoxContainer" parent="."] -layout_mode = 2 - -[node name="GoalName" type="LineEdit" parent="VBoxContainer"] -layout_mode = 2 -placeholder_text = "Goal Name" -expand_to_text_length = true -caret_blink = true -caret_blink_interval = 0.5 - -[node name="OptionalButton" type="CheckButton" parent="VBoxContainer"] -layout_mode = 2 -text = "Optional?" - -[node name="BaseID" type="LineEdit" parent="VBoxContainer"] -layout_mode = 2 -placeholder_text = "Filter" - -[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer"] -layout_mode = 2 - -[node name="Label" type="Label" parent="VBoxContainer/HBoxContainer"] -layout_mode = 2 -text = "Amount" - -[node name="AmountBox" type="SpinBox" parent="VBoxContainer/HBoxContainer"] -layout_mode = 2 -min_value = 1.0 -value = 1.0 -rounded = true -custom_arrow_step = 1.0 - -[node name="OnlyWhileActive" type="CheckBox" parent="VBoxContainer"] -layout_mode = 2 -button_pressed = true -text = "Only while active" - -[node name="Delete" type="Button" parent="VBoxContainer"] -layout_mode = 2 -text = "Remove step" - -[node name="HSeparator" type="HSeparator" parent="VBoxContainer"] -layout_mode = 2 - -[connection signal="pressed" from="VBoxContainer/Delete" to="." method="_on_delete_pressed"] diff --git a/addons/journalgd/Editor/Editor/quest_editor.gd b/addons/journalgd/Editor/Editor/quest_editor.gd deleted file mode 100644 index b5efdb3..0000000 --- a/addons/journalgd/Editor/Editor/quest_editor.gd +++ /dev/null @@ -1,118 +0,0 @@ -@tool - -class_name QuestEditor -extends GraphEdit - - -var STEP_PREFAB = preload("res://addons/journalgd/Editor/step_prefab.tscn") - -var q_name_input:LineEdit - - -func _ready(): - q_name_input = $"../HBoxContainer/QName" - connection_request.connect(make_connection.bind()) - disconnection_request.connect(make_disconnection.bind()) - - -func _on_add_new_button_down() -> EditorQuestStep: - var n = STEP_PREFAB.instantiate() - n.position_offset = scroll_offset - add_child(n) - return n - - -func _on_save_button_up(): - save() - - -func make_connection(from_node, from_port, to_node, to_port): - print("Made connection request: from %s port %s to %s port %s" % [from_node, from_port, to_node, to_port]) - connect_node(from_node, from_port, to_node, to_port) - - -func make_disconnection(from_node, from_port, to_node, to_port): - print("Made disconnection request: from %s port %s to %s port %s" % [from_node, from_port, to_node, to_port]) - disconnect_node(from_node, from_port, to_node, to_port) - - -func delete_node(n:String): - # { from_port: 0, from: "GraphNode name 0", to_port: 1, to: "GraphNode name 1" }. - var connections_for_n:Array[Dictionary] = get_connection_list().filter(func(x): return x.from == n || x.to == n) # get all connections with this involved - for node in connections_for_n: # for each in connections - disconnect_node(node.from, node.from_port, node.to, node.to_port) # disconnect - print("Deleting node $s", n) - get_node(n).queue_free() - - -func find_step(sname:StringName) -> EditorQuestStep: - for c in get_children(): - if c.name == sname: - return c - return null - - -func save() -> void: - if q_name_input.text == "": - print("Write a quest name to save.") - return - - var quest = SavedQuest.new() - quest.quest_id = q_name_input.text - # Get steps - for s in get_children(): - quest.add_step(SavedStep.new(s)) - - print(quest.steps) - for conn in get_connection_list(): - print(conn) - quest.steps[_get_step_name_for_node(conn["from"])].add_named_connection(conn["from_port"], _get_step_name_for_node(conn["to"])) - - # Pack and save - ResourceSaver.save(quest, (ProjectSettings.get_setting("journalgd/quests_directory") + "/%s.tres" % quest.quest_id)) - - -func open(q:SavedQuest) -> void: - # Get rid of all children - clear() - - if not q: - return - - # Create steps - q_name_input.text = q.quest_id # set quest ID - var to_connect:Array[Dictionary] = [] - - for step in q.steps: - var e_step = _on_add_new_button_down() - e_step.setup(q.steps[step]) - for c in q.steps[step].connections: - to_connect.append({ - "from" : step, - "to" : q.steps[step].connections[c], - "from_port" : q.steps[step].port_for_goal_key(c) - }) - # Connect all - for conn in to_connect: - print("Connecting %s to %s from port %s" % [conn["from"], conn["to"], conn["from_port"]] ) - make_connection(_get_node_for_step_name(conn["from"]), conn["from_port"], _get_node_for_step_name(conn["to"]), 0) - - -func _get_step_name_for_node(n:String) -> StringName: - return get_node(n).step_name - - -func _get_node_for_step_name(n:StringName) -> StringName: - return get_children().filter(func(x:EditorQuestStep): return x.step_name == n).front().name - - -func _on_clear_pressed() -> void: - clear() - - -func clear(): - q_name_input.text = "" - clear_connections() - for s in get_children(): - delete_node(s.name) - queue_redraw() diff --git a/addons/journalgd/Editor/Editor/quest_editor_screen.tscn b/addons/journalgd/Editor/Editor/quest_editor_screen.tscn deleted file mode 100644 index 5f886c7..0000000 --- a/addons/journalgd/Editor/Editor/quest_editor_screen.tscn +++ /dev/null @@ -1,56 +0,0 @@ -[gd_scene load_steps=2 format=3 uid="uid://cpim3fonsxtr4"] - -[ext_resource type="Script" path="res://addons/journalgd/Editor/quest_editor.gd" id="1_1ktoh"] - -[node name="quest_editor_screen" type="Control"] -process_mode = 3 -layout_mode = 3 -anchors_preset = 15 -anchor_right = 1.0 -anchor_bottom = 1.0 -grow_horizontal = 2 -grow_vertical = 2 -size_flags_horizontal = 3 -size_flags_vertical = 3 - -[node name="Vbox" type="VBoxContainer" parent="."] -layout_mode = 1 -anchors_preset = 15 -anchor_right = 1.0 -anchor_bottom = 1.0 -grow_horizontal = 2 -grow_vertical = 2 - -[node name="HBoxContainer" type="HBoxContainer" parent="Vbox"] -layout_mode = 2 - -[node name="Clear" type="Button" parent="Vbox/HBoxContainer"] -layout_mode = 2 -text = "Clear -" -flat = true - -[node name="Add_new" type="Button" parent="Vbox/HBoxContainer"] -layout_mode = 2 -text = "Add Node" -flat = true - -[node name="Save" type="Button" parent="Vbox/HBoxContainer"] -layout_mode = 2 -text = "Save" -flat = true - -[node name="QName" type="LineEdit" parent="Vbox/HBoxContainer"] -layout_mode = 2 -placeholder_text = "Quest name" -expand_to_text_length = true - -[node name="GraphEdit" type="GraphEdit" parent="Vbox"] -layout_mode = 2 -size_flags_vertical = 3 -right_disconnects = true -script = ExtResource("1_1ktoh") - -[connection signal="pressed" from="Vbox/HBoxContainer/Clear" to="Vbox/GraphEdit" method="_on_clear_pressed"] -[connection signal="button_down" from="Vbox/HBoxContainer/Add_new" to="Vbox/GraphEdit" method="_on_add_new_button_down"] -[connection signal="button_up" from="Vbox/HBoxContainer/Save" to="Vbox/GraphEdit" method="_on_save_button_up"] diff --git a/addons/journalgd/Editor/Editor/quest_step.gd b/addons/journalgd/Editor/Editor/quest_step.gd deleted file mode 100644 index 769ee58..0000000 --- a/addons/journalgd/Editor/Editor/quest_step.gd +++ /dev/null @@ -1,4 +0,0 @@ - - -func _on_delete_node_button_up(): - pass # Replace with function body. diff --git a/addons/journalgd/Editor/Editor/step_prefab.tscn b/addons/journalgd/Editor/Editor/step_prefab.tscn deleted file mode 100644 index e93a3a7..0000000 --- a/addons/journalgd/Editor/Editor/step_prefab.tscn +++ /dev/null @@ -1,136 +0,0 @@ -[gd_scene load_steps=3 format=3 uid="uid://vpv70w0bqhoa"] - -[ext_resource type="Script" path="res://addons/journalgd/Editor/editor_quest_step.gd" id="1_kwd5h"] - -[sub_resource type="Theme" id="Theme_akb1w"] -Color/colors/title_color = Color(0, 0.733333, 0.247059, 0.231373) -GraphNode/colors/title_color = Color(1, 1, 1, 1) -color/colors/title_color = Color(0, 0.733333, 0.247059, 0.231373) - -[node name="step" type="GraphNode"] -process_mode = 3 -offset_right = 268.0 -offset_bottom = 324.0 -mouse_filter = 1 -theme = SubResource("Theme_akb1w") -show_close = true -resizable = true -slot/0/left_enabled = false -slot/0/left_type = 1 -slot/0/left_color = Color(1, 1, 1, 1) -slot/0/left_icon = null -slot/0/right_enabled = true -slot/0/right_type = 1 -slot/0/right_color = Color(1, 1, 1, 1) -slot/0/right_icon = null -slot/0/draw_stylebox = true -slot/1/left_enabled = false -slot/1/left_type = 1 -slot/1/left_color = Color(1, 1, 1, 1) -slot/1/left_icon = null -slot/1/right_enabled = false -slot/1/right_type = 1 -slot/1/right_color = Color(1, 1, 1, 1) -slot/1/right_icon = null -slot/1/draw_stylebox = true -slot/2/left_enabled = false -slot/2/left_type = 1 -slot/2/left_color = Color(1, 1, 1, 1) -slot/2/left_icon = null -slot/2/right_enabled = false -slot/2/right_type = 1 -slot/2/right_color = Color(1, 1, 1, 1) -slot/2/right_icon = null -slot/2/draw_stylebox = true -slot/3/left_enabled = false -slot/3/left_type = 0 -slot/3/left_color = Color(1, 1, 1, 1) -slot/3/left_icon = null -slot/3/right_enabled = false -slot/3/right_type = 0 -slot/3/right_color = Color(1, 1, 1, 1) -slot/3/right_icon = null -slot/3/draw_stylebox = true -slot/4/left_enabled = true -slot/4/left_type = 1 -slot/4/left_color = Color(1, 1, 1, 1) -slot/4/left_icon = null -slot/4/right_enabled = false -slot/4/right_type = 1 -slot/4/right_color = Color(1, 1, 1, 1) -slot/4/right_icon = null -slot/4/draw_stylebox = true -slot/5/left_enabled = false -slot/5/left_type = 0 -slot/5/left_color = Color(1, 1, 1, 1) -slot/5/left_icon = null -slot/5/right_enabled = false -slot/5/right_type = 0 -slot/5/right_color = Color(1, 1, 1, 1) -slot/5/right_icon = null -slot/5/draw_stylebox = true -slot/6/left_enabled = false -slot/6/left_type = 0 -slot/6/left_color = Color(1, 1, 1, 1) -slot/6/left_icon = null -slot/6/right_enabled = false -slot/6/right_type = 0 -slot/6/right_color = Color(1, 1, 1, 1) -slot/6/right_icon = null -slot/6/draw_stylebox = true -slot/7/left_enabled = false -slot/7/left_type = 0 -slot/7/left_color = Color(1, 1, 1, 1) -slot/7/left_icon = null -slot/7/right_enabled = false -slot/7/right_type = 0 -slot/7/right_color = Color(1, 1, 1, 1) -slot/7/right_icon = null -slot/7/draw_stylebox = true -script = ExtResource("1_kwd5h") - -[node name="StepName" type="LineEdit" parent="."] -layout_mode = 2 -placeholder_text = "Step Name" - -[node name="Label" type="Label" parent="."] -layout_mode = 2 -text = "Step type:" - -[node name="StepType" type="OptionButton" parent="."] -layout_mode = 2 -item_count = 3 -selected = 0 -popup/item_0/text = "All" -popup/item_0/id = 0 -popup/item_1/text = "Any" -popup/item_1/id = 1 -popup/item_2/text = "Branch" -popup/item_2/id = 2 - -[node name="IsEntryButton" type="CheckButton" parent="."] -layout_mode = 2 -text = "Is starting step" - -[node name="IsExitButton" type="CheckButton" parent="."] -layout_mode = 2 -text = "Is last step" - -[node name="AddGoalButton" type="Button" parent="."] -layout_mode = 2 -text = "Add Goal" - -[node name="HSeparator" type="HSeparator" parent="."] -layout_mode = 2 - -[node name="Scroll" type="ScrollContainer" parent="."] -layout_mode = 2 -size_flags_vertical = 3 -follow_focus = true -vertical_scroll_mode = 2 - -[node name="GoalsContainer" type="VBoxContainer" parent="Scroll"] -layout_mode = 2 - -[connection signal="toggled" from="IsExitButton" to="." method="_update_is_exit"] -[connection signal="pressed" from="AddGoalButton" to="." method="_on_add_goal"] diff --git a/addons/journalgd/QuestNode/QuestNode/quest_engine.gd b/addons/journalgd/QuestNode/QuestNode/quest_engine.gd deleted file mode 100644 index 5c52262..0000000 --- a/addons/journalgd/QuestNode/QuestNode/quest_engine.gd +++ /dev/null @@ -1,230 +0,0 @@ -class_name QuestEngine -extends Node -## This keeps track of all of the quests. -## Quests will be instantiated as [QuestObject]s underneath this node. -## Registering a quest event will update the tree downwards. What does this mean? I don't know, I'm tired. -## When functions ask for a "Quest path", they are referring to a string in the format of [code]quest_name/step_name/goal_name[/code]. - - -## Array of IDs of all the quests that are currently active. -var active_quests: Array[String] -## Array of IDs of all the quests the player has completed. -var complete_quests:Array[String] - -## Emitted when a quest has started. -signal quest_started(q_id:String) -## Emitted when a quest is complete. -signal quest_complete(q_id:String) -## Emitted when a quest goal has been updated - the amount has been increased, or it is marked as complete. -signal goal_updated(quest_path:String, data:Dictionary) -## Emitted when a step is updated - when a step is marked as complete. -signal step_updated(quest_path:String, data:Dictionary) -## Emitted when a quest updates. -signal quest_updated(quest_path:String, data:Dictionary) - - -## Loads all quests from the [code]biznasty/quests_directory[/code] project setting, and then instantiates them as child [QuestObject]s. -func load_quest_objects(): - _load_dir(ProjectSettings.get_setting("journalgd/quests_path")) - - -func _load_dir(path:String): - var dir = DirAccess.open(path) - dir.list_dir_begin() - var file_name = dir.get_next() - while file_name != "": - if dir.current_is_dir(): - _load_dir(file_name) - else: - add_quest_from_path("%s/%s" % [path, file_name]) - file_name = dir.get_next() - - -## Load a quest resource at a path, and load it into the system. -func add_quest_from_path(path:String): - var q = load(path) as SavedQuest - add_node_from_saved(q) - - -## Mark a quest as started. -func start_quest(q_id:String) -> bool: - if get_node_or_null(q_id): - active_quests.append(q_id) - quest_started.emit(q_id) - return true - return false - - -## Add a quest from a [SavedQuest] resource. -func add_node_from_saved(q:SavedQuest) -> void: - var q_node = QuestNode.new() - q_node.qID = q.quest_id - q_node.name = q.quest_id - - # Create steps - for s in q.steps: - var s_node = QuestStep.new(q.steps[s], step_updated, goal_updated) - if q.steps[s].is_entry_step: - q_node._active_step = s_node - q_node.add_child(s_node) - - add_child(q_node) - if q.entry_point == &"": - q_node._active_step = q_node.get_child(0) - print(q_node._active_step) - else: - q_node = q.entry_point - - -## Is a member currently in progress? -func is_member_active(q_path) -> bool: - var path_info = _parse_quest_path(q_path) if q_path is String else q_path - - match path_info: - {"quest": var quest}: - return active_quests.has(quest) - {"quest": var quest, "step": var step}: - var q:QuestNode = _get_member_node(quest) - return q._active_step.name == step - {"goal", ..}: - var g:QuestGoal = _get_member_node(path_info) - return g.already_satisfied - _: - return false - - -## Has a member reached their completion state- a quest has reached a step marked as the end, a step has all goals completed, or a goal has been satisfied. -func is_member_complete(q_path) -> bool: - var path_info = _parse_quest_path(q_path) if q_path is String else q_path - - match path_info: - {"quest": var quest}: - return complete_quests.has(quest) - {"quest": var quest, "step": var step}: - var p = "%s/%s" % [quest, step] - var s:QuestStep = _get_member_node(p) - return s.is_already_complete - {"goal", ..}: - var g:QuestGoal = _get_member_node(path_info) - return g.already_satisfied - _: - return false - - -## Is a member active, or has it been completed. Inverting this can tell if the player hasn't started a quest. -func has_member_been_started(q_path) -> bool: - var path_info = _parse_quest_path(q_path) if q_path is String else q_path - return is_member_active(path_info) or is_member_complete(path_info) - - -## Get a [QuestNode], [QuestStep], or [QuestGoal]'s data from the quest path. Returns a dictionary: -## [CodeBlock] -## Goal: -## { -## "progress": int <- how many times this event has been triggered -## "target": int <- the amount of times to be triggered to be considered completed -## "filter": String -## "optional": bool -## "only_while_active": bool -## } -## Step: -## { -## "type": StepType <- All, Any, Branch -## "is_first_step": bool -## "is_last_step": bool -## "goal_keys": Array[String] <- Keys of all goals -## } -## Quest: -## { -## "steps": Array[String] <- Names of all steps -## } -## [/CodeBlock] -func get_member(q_path) -> Dictionary: - var path_info = q_path if q_path is String else _fuse_path(q_path) - var n = get_node_or_null(path_info) - if n: - return n.data - else: - return {} - - -func _get_member_node(q_path) -> Variant: - var path_info = q_path if q_path is String else _fuse_path(q_path) - return get_node_or_null(path_info) - - -## Register a quest event. This function has unique behavior based on the path you give it: [br] -## [code]goal_key[/code] - Apply the event to all quests loaded in the system, active or not. [br] -## [code]quest_name/goal_key[/code] - Apply the event to all steps in a quest. [br] -## [code]quest_name/step_name/goal_key[/code] - Apply the event only to a specific step of a specific quest. [br] -## [code]args[/code] is an optional dictionary with the shape of -## [CodeBlock] -## { -## "filter" : String <- Optional, filter to check against for goal conditions. -## } -## [/CodeBlock] -## Use "undo" to instad un-register an event, if you need to do that. -func register_quest_event(path:String, args:Dictionary = {}, undo:bool = false): - match _parse_quest_path(path): - {"quest": var key}: - propagate_call("register_step_event", [path, args, undo]) - {"quest": var quest, "step": var key}: - var qnode = _get_member_node({"quest": quest}) - if not qnode: - return - qnode.register_step_event(key, args, undo) - {"quest": var quest, "step": var step, "goal": var key}: - var snode:QuestStep = _get_member_node({"quest": quest, "step": step}) - if not snode: - return - snode.register_event(key, args, undo) - _: - return - _update_all_quests() - - -func _update_all_quests(): - for q in get_children(): - q.update() - if q.complete and not complete_quests.has(q.name): - complete_quests.append(q.name) - quest_complete.emit(q.name) - - -func _parse_quest_path(path:String) -> Dictionary: - var chunks = path.split("/") - var output:Dictionary = {"quest":chunks[0]} - if chunks.size() > 1: - output["step"] = chunks[1] - if chunks.size() > 2: - output["goal"] = chunks[2] - return output - - -func _fuse_path(path:Dictionary) -> String: - var output = "" - if path.has("quest"): - output += path["quest"] - if path.has("step"): - output += "/" + path["step"] - if path.has("goal"): - output += "/" + path["goal"] - return output - - -func save() -> Dictionary: - var quest_data = {} - for quest in get_children(): - quest_data[quest.name] = quest.save() - return { - "active_quests": active_quests, - "complete_quests": complete_quests, - "quest_data": quest_data - } - - -func load_data(data:Dictionary) -> void: - active_quests = data.active_quests - complete_quests = data.complete_quests - for quest in data.quest_data: - get_node(quest).load_data(data.quest_data[quest]) diff --git a/addons/journalgd/QuestNode/QuestNode/quest_goal.gd b/addons/journalgd/QuestNode/QuestNode/quest_goal.gd deleted file mode 100644 index 160d6fc..0000000 --- a/addons/journalgd/QuestNode/QuestNode/quest_goal.gd +++ /dev/null @@ -1,85 +0,0 @@ -@tool - -class_name QuestGoal -extends Node - -var optional:bool = false -var update_signal:Signal -var internal_amount:int = 0: - get: - return internal_amount - set(val): - _emit_updated() - internal_amount = val -var already_satisfied:bool = false: - get: - return already_satisfied - set(val): - _emit_updated() - already_satisfied = val -var data:Dictionary: - get: - return { - "progress": internal_amount, - "target": amount, - "filter": filter, - "optional": optional, - "only_while_active": only_while_active - } -@export var amount:int = 1 -@export var filter:String -@export var only_while_active:bool = true -# TODO: Multiple events to satisfy, match against refID -# TODO: Allow undoing events - - -func _init(eqg:SavedGoal = null, goal_update_signal:Signal = Signal()) -> void: - if not eqg: - return - optional = eqg.optional - amount = eqg.amount - filter = eqg.filter - only_while_active = eqg.only_while_active - update_signal = goal_update_signal - name = eqg.goal_key - - -## Evaluate whether this has been satisfied or not. -func evaluate(is_active_step:bool) -> bool: - if already_satisfied: # if we've satisfied it before - return true - if only_while_active and not is_active_step: # if not the active step and we need it to be, go false - return false - already_satisfied = amount <= internal_amount # every time it's satisfied, internal_amount goes up by 1, so we only need to check that. - return already_satisfied - - -## Attempt to register an event with this goal. -func attempt_register(r_key:String, args:Dictionary, undo:bool): # TODO: only_while_active - # check event name - if not r_key == name: - return - # check for invalid filter - if not filter == "": - if args.has("filter") and not args["filter"] == filter: - return - # all checks passed, increase amount - internal_amount += -1 if undo else 1 - if undo and already_satisfied: - already_satisfied = false - - -func save() -> Dictionary: - return { - "already_satisfied" : already_satisfied, - "internal_amount" : internal_amount - } - - -func load_data(data:Dictionary) -> void: - already_satisfied = data.already_satisfied - internal_amount = data.internal_amount - - -func _emit_updated() -> void: - update_signal.emit("%s/%s/%s" % [get_parent().get_parent().name, get_parent().name, name], data) diff --git a/addons/journalgd/QuestNode/QuestNode/quest_node.gd b/addons/journalgd/QuestNode/QuestNode/quest_node.gd deleted file mode 100644 index 4eddc62..0000000 --- a/addons/journalgd/QuestNode/QuestNode/quest_node.gd +++ /dev/null @@ -1,71 +0,0 @@ -@tool - -class_name QuestNode -extends Node -## This is an instance of a [Quest] within the scene. - - -## The quest data. -var qID:String -var complete:bool = false -var _active_step:QuestStep -var data:Dictionary: - get: - return{ - "active_step": _active_step.name, - "steps": get_children().map(func(x): return x.name) - } -var update_signal:Signal - - -# Might be useless -## Evaluate whether the quest is complete or not. -func evaluate() -> bool: - if complete: # if we are already complete, skip this - return true - - var results:Array[bool] = [] - for g in get_children().map(func(x): x as QuestStep): - results.append(g.evaluate(g == _active_step)) # pass in whether this is the active step, important for goals later on. - return results.all(func(x): x) - - -func update(): - if complete: - return - if _active_step.evaluate(true): #if active step is true, move to the next one - if _active_step.is_final_step: - complete = true - update_signal.emit(name, data) - return - _active_step = _active_step.next_step - - -func register_step_event(key:String, args:Dictionary = {}, undo:bool = false): - for g in get_children(): - g.register_event(key, args, undo) - - -func is_step_complete(id:String): - var st = find_child(id) as QuestStep - if not st: - return false - return st.evaluate(false) - - -func save() -> Dictionary: - var step_data = {} - for s in get_children(): - step_data[s.name] = s.save() - return { - "complete": complete, - "active_step": _active_step.name, - "step_data": step_data - } - - -func load_data(data:Dictionary) -> void: - complete = data.complete - _active_step = get_node(data.active_step) - for s_name in data.step_data: - get_node(s_name).load_data(data.step_data[s_name]) diff --git a/addons/journalgd/QuestNode/QuestNode/quest_step.gd b/addons/journalgd/QuestNode/QuestNode/quest_step.gd deleted file mode 100644 index e88b2c3..0000000 --- a/addons/journalgd/QuestNode/QuestNode/quest_step.gd +++ /dev/null @@ -1,89 +0,0 @@ -@tool - -class_name QuestStep -extends Node - -var type:StepType = StepType.ALL -var is_final_step:bool = false -var is_already_complete:bool: - get: - return is_already_complete - set(val): - update_signal.emit("%s/%s" % [get_parent().name, name], data) - is_already_complete = val -var next_steps:Dictionary = {} -var next_step:QuestStep: - get: - if not type == StepType.BRANCH: - return get_parent().get_node_or_null(next_steps.values()[0] as String) - for g in get_children(): - if(g.evaluate(false)): - return get_parent().get_node_or_null(next_steps[g.name] as String) - return null -var data:Dictionary: - get: - return { - "type": type, - "is_final_step": is_final_step, - "goal_keys": get_children().map(func(x:Node): return x.name) - } -var update_signal:Signal - - -func _init(eqs:SavedStep = null, step_update_signal:Signal = Signal(), goal_update_signal:Signal = Signal()) -> void: - if not eqs: - return - type = eqs.step_type - is_final_step = eqs.is_final_step - name = eqs.step_name - next_steps = eqs.connections - update_signal = step_update_signal - for g in eqs.goals: - add_child(QuestGoal.new(g, goal_update_signal)) - - -func evaluate(is_active_step:bool) -> bool: - if is_already_complete: - return true - var results:Array[bool] = [] - for g in get_children(): - results.append(g.evaluate(is_active_step) || g.optional) # if evaluate or optional - if type == StepType.ALL: - var check = results.all(func(x): return x) - if check: - is_already_complete = true - return check - else: - var check = results.any(func(x): return x) - if check: - is_already_complete = true - return check - - -## Register a goal event. -func register_event(key:String, args:Dictionary, undo:bool): - for g in get_children(): - g.attempt_register(key, args, undo) - - -func save() -> Dictionary: - var goal_data = {} - for g in get_children(): - goal_data[g.name] = g.save() - return { - "is_already_complete": is_already_complete, - "goal_data" : goal_data - } - - -func load_data(data:Dictionary) -> void: - is_already_complete = data.is_already_complete - for g_key in data.goal_data: - get_node(g_key).load_data(data.goal_data[g_key]) - - -enum StepType { - ALL, - ANY, - BRANCH, -} diff --git a/addons/journalgd/Saved/Saved/saved_goal.gd b/addons/journalgd/Saved/Saved/saved_goal.gd deleted file mode 100644 index 6c4c7cd..0000000 --- a/addons/journalgd/Saved/Saved/saved_goal.gd +++ /dev/null @@ -1,19 +0,0 @@ -class_name SavedGoal -extends Resource - - -@export var goal_key:StringName -@export var amount:int = 1 -@export var filter:String -@export var only_while_active:bool = true -@export var optional:bool - - -func _init(eqg:EditorQuestGoal = null) -> void: - if not eqg: - return - goal_key = eqg.goal_key - amount = eqg.amount - filter = eqg.filter - only_while_active = eqg.only_while_active - optional = eqg.optional diff --git a/addons/journalgd/Saved/Saved/saved_quest.gd b/addons/journalgd/Saved/Saved/saved_quest.gd deleted file mode 100644 index a297788..0000000 --- a/addons/journalgd/Saved/Saved/saved_quest.gd +++ /dev/null @@ -1,12 +0,0 @@ -class_name SavedQuest -extends Resource - - -@export var quest_id:StringName -@export var steps:Dictionary = {} -@export var entry_point:StringName - - -func add_step(step:SavedStep) -> SavedStep: - steps[step.step_name] = step - return step diff --git a/addons/journalgd/Saved/Saved/saved_step.gd b/addons/journalgd/Saved/Saved/saved_step.gd deleted file mode 100644 index 261df90..0000000 --- a/addons/journalgd/Saved/Saved/saved_step.gd +++ /dev/null @@ -1,47 +0,0 @@ -@tool -class_name SavedStep -extends Resource - - -@export var step_name:StringName -@export var step_type:QuestStep.StepType = QuestStep.StepType.ALL -## {goal_key:to_node} -@export var connections:Dictionary = {} -@export var goals:Array[SavedGoal] = [] -@export var is_final_step:bool -@export var editor_coordinates:Vector2 -@export var is_entry_step:bool - - -func _init(eqs:EditorQuestStep = null) -> void: - if not eqs: - return - step_name = eqs.step_name - step_type = eqs.step_type - is_final_step = eqs.is_exit - editor_coordinates = eqs.position - is_entry_step = eqs.is_entry_step - for g in eqs.get_goals(): - add_goal(SavedGoal.new(g)) - - -func add_goal(goal:SavedGoal) -> SavedGoal: - goals.append(goal) - return goal - - -func add_named_connection(port:int, to:StringName) -> void: - if not step_type == QuestStep.StepType.BRANCH: - set_default_connection(to) - return - connections[goals[port].goal_key] = to - - -func set_default_connection(to:StringName) -> void: - connections[goals[0].goal_key] = to - - -func port_for_goal_key(key:StringName) -> int: - if not step_type == QuestStep.StepType.BRANCH: - return 0 - return goals.find(goals.filter(func(x:SavedGoal): return x.goal_key == key)[0]) # this Sucks but it's fine. diff --git a/addons/skelerealms/scripts/components/goap_component.gd b/addons/skelerealms/scripts/components/goap_component.gd index 43c887a..e9a7c8c 100644 --- a/addons/skelerealms/scripts/components/goap_component.gd +++ b/addons/skelerealms/scripts/components/goap_component.gd @@ -49,7 +49,7 @@ func _process(delta): break # if we are done with the plan - if _current_objective and not _rebuild_plan and action_queue.is_empty(): + if _current_objective and not _rebuild_plan and action_queue.is_empty() and not _current_action: # if we need to remove the objective, remove it if _current_objective.remove_after_satisfied: objectives.erase(_current_objective)