Added QuestSystem and reworked how quest state is passed around.

main
Martin Felis 2024-08-16 00:24:27 +02:00
parent 3d3fd61f71
commit 730ee9e69b
12 changed files with 107 additions and 81 deletions

View File

@ -0,0 +1,15 @@
[remap]
importer="dialogue_manager_compiler_12"
type="Resource"
uid="uid://qgj4sfugsnav"
path="res://.godot/imported/bridge_builder_missing_tool.dialogue-a575250aecf80f00531ba8af1b054b06.tres"
[deps]
source_file="res://dialogue/bridge_builder_missing_tool.dialogue"
dest_files=["res://.godot/imported/bridge_builder_missing_tool.dialogue-a575250aecf80f00531ba8af1b054b06.tres"]
[params]
defaults=true

View File

@ -1,15 +0,0 @@
[remap]
importer="dialogue_manager_compiler_12"
type="Resource"
uid="uid://b1gd54koq1h7o"
path="res://.godot/imported/testdialogue.dialogue-d110de06b87504b7beec281f973d2007.tres"
[deps]
source_file="res://dialogue/testdialogue.dialogue"
dest_files=["res://.godot/imported/testdialogue.dialogue-d110de06b87504b7beec281f973d2007.tres"]
[params]
defaults=true

View File

@ -3,8 +3,9 @@ extends Area3D
@export var dialogue_resource: DialogueResource @export var dialogue_resource: DialogueResource
@export var dialogue_start: String = "start" @export var dialogue_start: String = "start"
func action(quest_state: QuestState) -> void: func action() -> void:
var balloon = load("res://ui/dialogue/balloon.tscn").instantiate() var balloon = load("res://ui/dialogue/balloon.tscn").instantiate() as DialogueBaloon
DialogueManager.connect("dialogue_ended", quest_state.on_dialogue_ended)
get_tree().current_scene.add_child(balloon) get_tree().current_scene.add_child(balloon)
balloon.start(dialogue_resource, dialogue_start, [quest_state]) var quest_states = get_tree().get_nodes_in_group("quest_state")
balloon.start(dialogue_resource, dialogue_start, quest_states)

View File

@ -6,8 +6,6 @@ const JUMP_VELOCITY = 2.5
@onready var geometry = %Geometry @onready var geometry = %Geometry
@onready var actionable_detector = %ActionableDetector @onready var actionable_detector = %ActionableDetector
@onready var quest_state = %BuilderMissingTool
@onready var bridge = %Bridge
# Get the gravity from the project settings to be synced with RigidBody nodes. # Get the gravity from the project settings to be synced with RigidBody nodes.
var gravity = ProjectSettings.get_setting("physics/3d/default_gravity") var gravity = ProjectSettings.get_setting("physics/3d/default_gravity")
@ -52,4 +50,4 @@ func _unhandled_input(_event: InputEvent) -> void:
if Input.is_action_just_pressed("ui_accept"): if Input.is_action_just_pressed("ui_accept"):
var actionables = actionable_detector.get_overlapping_areas() var actionables = actionable_detector.get_overlapping_areas()
if actionables.size() > 0: if actionables.size() > 0:
actionables[0].action(quest_state) actionables[0].action()

View File

@ -61,7 +61,7 @@ toggle_inventory={
[internationalization] [internationalization]
locale/translations_pot_files=PackedStringArray("res://dialogue/testdialogue.dialogue") locale/translations_pot_files=PackedStringArray("res://dialogue/bridge_builder_missing_tool.dialogue")
[layer_names] [layer_names]

View File

@ -1,16 +1,16 @@
class_name QuestState class_name QuestBuilderMissingTool
extends Node extends Node
@export var is_wrench_found:bool = false @export var is_wrench_found:bool = false
@export var is_wrench_delivered:bool = false @export var is_wrench_delivered:bool = false
@export var is_bridge_built:bool = false @export var is_bridge_built:bool = false
@onready var player:Player = %Player
@onready var merchant = %Merchant @onready var merchant = %Merchant
@onready var bridge = %Bridge @onready var bridge = %Bridge
var _bridge_transform:Transform3D = Transform3D.IDENTITY var _bridge_transform:Transform3D = Transform3D.IDENTITY
var _player:Player = null
signal wrench_delivered signal wrench_delivered
@ -18,15 +18,17 @@ func _ready():
_bridge_transform = bridge.global_transform _bridge_transform = bridge.global_transform
bridge.global_transform = Transform3D.IDENTITY.translated(Vector3.UP * -1000) bridge.global_transform = Transform3D.IDENTITY.translated(Vector3.UP * -1000)
_player = get_tree().root.find_child("Player", true, false)
func on_dialogue_ended(_dialog_resource: DialogueResource) -> void: func on_dialogue_ended(_dialog_resource: DialogueResource) -> void:
if is_wrench_delivered: if is_wrench_delivered and not is_bridge_built:
print ("Will build bridge!") print ("Will build bridge!")
emit_signal("wrench_delivered") emit_signal("wrench_delivered")
func _process(_delta): func _process(_delta):
for item in player.inventory.get_items(): for item in _player.inventory.get_items():
if item.name == "Wrench": if item.name == "Wrench":
is_wrench_found = true is_wrench_found = true

View File

@ -1,14 +1,9 @@
[gd_scene load_steps=19 format=3 uid="uid://cqie4cy0uy1t0"] [gd_scene load_steps=12 format=3 uid="uid://cqie4cy0uy1t0"]
[ext_resource type="Texture2D" uid="uid://bq3b1hxl5ojh6" path="res://assets/icons/npc_emotes/attention.tres" id="2_4dxur"] [ext_resource type="Script" path="res://systems/QuestSystem.gd" id="4_8oxap"]
[ext_resource type="PackedScene" uid="uid://2q8dhf61a7os" path="res://assets/characters/engineer.tscn" id="3_gf736"]
[ext_resource type="PackedScene" uid="uid://dhpc2xvlfln7o" path="res://objects/actionable.tscn" id="4_pths5"]
[ext_resource type="Resource" uid="uid://b1gd54koq1h7o" path="res://dialogue/testdialogue.dialogue" id="5_i1opu"]
[ext_resource type="PackedScene" uid="uid://dmagdl5pi6jdj" path="res://world/level.tscn" id="6_svjo8"] [ext_resource type="PackedScene" uid="uid://dmagdl5pi6jdj" path="res://world/level.tscn" id="6_svjo8"]
[ext_resource type="Script" path="res://player.gd" id="13_2wo8v"] [ext_resource type="Script" path="res://player.gd" id="13_2wo8v"]
[ext_resource type="Script" path="res://quests/builder_missing_tool_quest.gd" id="14_g3xjj"]
[ext_resource type="PackedScene" uid="uid://dy8vjf760prhq" path="res://assets/characters/rogue.tscn" id="15_2476h"] [ext_resource type="PackedScene" uid="uid://dy8vjf760prhq" path="res://assets/characters/rogue.tscn" id="15_2476h"]
[ext_resource type="Script" path="res://quests/scared_to_walk_in_the_dark.gd" id="18_7v3bk"]
[sub_resource type="ProceduralSkyMaterial" id="ProceduralSkyMaterial_y65pc"] [sub_resource type="ProceduralSkyMaterial" id="ProceduralSkyMaterial_y65pc"]
@ -21,12 +16,6 @@ sky = SubResource("Sky_tw7u4")
ambient_light_source = 3 ambient_light_source = 3
ambient_light_color = Color(0.662452, 0.662452, 0.662452, 1) ambient_light_color = Color(0.662452, 0.662452, 0.662452, 1)
[sub_resource type="CylinderShape3D" id="CylinderShape3D_vq44x"]
height = 0.6
radius = 0.158352
[sub_resource type="SphereShape3D" id="SphereShape3D_6nrvr"]
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_jd31k"] [sub_resource type="StandardMaterial3D" id="StandardMaterial3D_jd31k"]
albedo_color = Color(1, 1, 0.698039, 1) albedo_color = Color(1, 1, 0.698039, 1)
@ -51,38 +40,8 @@ environment = SubResource("Environment_v85yo")
transform = Transform3D(0.836133, 0.124138, 0.534295, -0.548527, 0.189226, 0.81444, 0, -0.974055, 0.226311, 5.06819, 4.51394, 0) transform = Transform3D(0.836133, 0.124138, 0.534295, -0.548527, 0.189226, 0.81444, 0, -0.974055, 0.226311, 5.06819, 4.51394, 0)
shadow_enabled = true shadow_enabled = true
[node name="Merchant" type="CharacterBody3D" parent="."]
unique_name_in_owner = true
transform = Transform3D(-4.37114e-08, 0, -1, 0, 1, 0, 1, 0, -4.37114e-08, 3.64783, 0, -1.58598)
[node name="CollisionShape3D" type="CollisionShape3D" parent="Merchant"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.310637, 0)
shape = SubResource("CylinderShape3D_vq44x")
[node name="StateMarker" type="Sprite3D" parent="Merchant"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.0272007, 0.901301, 0.168392)
centered = false
billboard = 1
texture_filter = 0
texture = ExtResource("2_4dxur")
[node name="Geometry" type="Node3D" parent="Merchant"]
transform = Transform3D(0.4, 0, 0, 0, 0.4, 0, 0, 0, 0.4, 0, 0, 0)
[node name="Engineer" parent="Merchant/Geometry" instance=ExtResource("3_gf736")]
[node name="Actionable" parent="Merchant" instance=ExtResource("4_pths5")]
dialogue_resource = ExtResource("5_i1opu")
[node name="CollisionShape3D" type="CollisionShape3D" parent="Merchant/Actionable"]
shape = SubResource("SphereShape3D_6nrvr")
[node name="Level" parent="." instance=ExtResource("6_svjo8")] [node name="Level" parent="." instance=ExtResource("6_svjo8")]
[node name="Bridge" type="Node3D" parent="."]
unique_name_in_owner = true
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.375699, -0.115042, 0)
[node name="Player" type="CharacterBody3D" parent="."] [node name="Player" type="CharacterBody3D" parent="."]
unique_name_in_owner = true unique_name_in_owner = true
script = ExtResource("13_2wo8v") script = ExtResource("13_2wo8v")
@ -116,11 +75,5 @@ unique_name_in_owner = true
transform = Transform3D(1, 0, 0, 0, 0.460138, 0.887848, 0, -0.887848, 0.460138, 0, 2.91421, 1.186) transform = Transform3D(1, 0, 0, 0, 0.460138, 0.887848, 0, -0.887848, 0.460138, 0, 2.91421, 1.186)
current = true current = true
[node name="Quests" type="Node" parent="."] [node name="QuestSystem" type="Node" parent="."]
script = ExtResource("4_8oxap")
[node name="BuilderMissingTool" type="Node" parent="Quests" groups=["quest_state"]]
unique_name_in_owner = true
script = ExtResource("14_g3xjj")
[node name="ScaredToWalkInTheDark" type="Node" parent="Quests" groups=["quest_state"]]
script = ExtResource("18_7v3bk")

15
systems/QuestSystem.gd Normal file
View File

@ -0,0 +1,15 @@
class_name QuestSystem
extends Node
var _quest_states:Array = []
# Called when the node enters the scene tree for the first time.
func _ready():
_quest_states = get_tree().get_nodes_in_group("quest_state")
DialogueManager.connect("dialogue_ended", _on_dialogue_ended)
func _on_dialogue_ended(_dialog_resource: DialogueResource):
for quest_state in _quest_states:
if quest_state.has_method("on_dialogue_ended"):
quest_state.on_dialogue_ended(_dialog_resource)

View File

@ -1,3 +1,4 @@
class_name DialogueBaloon
extends CanvasLayer extends CanvasLayer
## The action to use for advancing the dialogue ## The action to use for advancing the dialogue

View File

@ -8,8 +8,6 @@
[node name="ExampleBalloon" type="CanvasLayer"] [node name="ExampleBalloon" type="CanvasLayer"]
layer = 100 layer = 100
script = ExtResource("1_36de5") script = ExtResource("1_36de5")
next_action = null
skip_action = null
[node name="Balloon" type="Control" parent="."] [node name="Balloon" type="Control" parent="."]
unique_name_in_owner = true unique_name_in_owner = true

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=12 format=3 uid="uid://dmagdl5pi6jdj"] [gd_scene load_steps=21 format=3 uid="uid://dmagdl5pi6jdj"]
[ext_resource type="MeshLibrary" uid="uid://dcpuitbu16j1a" path="res://assets/mesh_library.tres" id="1_q0eym"] [ext_resource type="MeshLibrary" uid="uid://dcpuitbu16j1a" path="res://assets/mesh_library.tres" id="1_q0eym"]
[ext_resource type="PackedScene" uid="uid://da5r82nvypfk4" path="res://objects/pickup_item.tscn" id="2_qurr0"] [ext_resource type="PackedScene" uid="uid://da5r82nvypfk4" path="res://objects/pickup_item.tscn" id="2_qurr0"]
@ -7,10 +7,23 @@
[ext_resource type="Resource" uid="uid://coser1y1y5unl" path="res://data/items/door.tres" id="5_twsf3"] [ext_resource type="Resource" uid="uid://coser1y1y5unl" path="res://data/items/door.tres" id="5_twsf3"]
[ext_resource type="Resource" uid="uid://c1ll2snhgv3m1" path="res://data/items/treelog.tres" id="8_pafka"] [ext_resource type="Resource" uid="uid://c1ll2snhgv3m1" path="res://data/items/treelog.tres" id="8_pafka"]
[ext_resource type="PackedScene" uid="uid://dnobr4inhiskv" path="res://assets/3rdparty/kenney/platformer-kit/Models/GLB format/tree-pine.glb" id="11_ldjca"] [ext_resource type="PackedScene" uid="uid://dnobr4inhiskv" path="res://assets/3rdparty/kenney/platformer-kit/Models/GLB format/tree-pine.glb" id="11_ldjca"]
[ext_resource type="Texture2D" uid="uid://bq3b1hxl5ojh6" path="res://assets/icons/npc_emotes/attention.tres" id="12_3vn8y"]
[ext_resource type="PackedScene" uid="uid://m4tk7vhjy310" path="res://assets/3rdparty/kenney/platformer-kit/Models/GLB format/tree.glb" id="12_l5e57"] [ext_resource type="PackedScene" uid="uid://m4tk7vhjy310" path="res://assets/3rdparty/kenney/platformer-kit/Models/GLB format/tree.glb" id="12_l5e57"]
[ext_resource type="PackedScene" uid="uid://cgde10y3e7w86" path="res://assets/3rdparty/kenney/platformer-kit/Models/GLB format/rocks.glb" id="13_dbop6"] [ext_resource type="PackedScene" uid="uid://cgde10y3e7w86" path="res://assets/3rdparty/kenney/platformer-kit/Models/GLB format/rocks.glb" id="13_dbop6"]
[ext_resource type="PackedScene" uid="uid://2q8dhf61a7os" path="res://assets/characters/engineer.tscn" id="13_t16lh"]
[ext_resource type="PackedScene" uid="uid://dg1rtct0vrk3p" path="res://assets/3rdparty/kenney/platformer-kit/Models/GLB format/poles.glb" id="14_8e8cl"] [ext_resource type="PackedScene" uid="uid://dg1rtct0vrk3p" path="res://assets/3rdparty/kenney/platformer-kit/Models/GLB format/poles.glb" id="14_8e8cl"]
[ext_resource type="PackedScene" uid="uid://dhpc2xvlfln7o" path="res://objects/actionable.tscn" id="14_8oq2l"]
[ext_resource type="Resource" uid="uid://qgj4sfugsnav" path="res://dialogue/bridge_builder_missing_tool.dialogue" id="15_mqfyi"]
[ext_resource type="PackedScene" uid="uid://cej0a41nm3eh7" path="res://assets/3rdparty/kenney/platformer-kit/Models/GLB format/mushrooms.glb" id="15_y1ifw"] [ext_resource type="PackedScene" uid="uid://cej0a41nm3eh7" path="res://assets/3rdparty/kenney/platformer-kit/Models/GLB format/mushrooms.glb" id="15_y1ifw"]
[ext_resource type="Script" path="res://quests/builder_missing_tool_quest.gd" id="16_dr1ca"]
[ext_resource type="Script" path="res://quests/scared_to_walk_in_the_dark.gd" id="17_nupwt"]
[ext_resource type="PackedScene" uid="uid://kpyvcyklt68g" path="res://assets/scene_props/bridge.tscn" id="18_yqn1p"]
[sub_resource type="CylinderShape3D" id="CylinderShape3D_0soe6"]
height = 0.6
radius = 0.158352
[sub_resource type="SphereShape3D" id="SphereShape3D_ugkqa"]
[node name="Level" type="Node3D"] [node name="Level" type="Node3D"]
@ -59,3 +72,48 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 1.56186, 0, -3.13331)
[node name="mushrooms2" parent="Decorations" instance=ExtResource("15_y1ifw")] [node name="mushrooms2" parent="Decorations" instance=ExtResource("15_y1ifw")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 2.851, 0, 0.798104) transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 2.851, 0, 0.798104)
[node name="Quests" type="Node" parent="."]
[node name="BuilderMissingTool" type="Node" parent="Quests" groups=["quest_state"]]
unique_name_in_owner = true
script = ExtResource("16_dr1ca")
[node name="Bridge" type="Node3D" parent="Quests/BuilderMissingTool"]
unique_name_in_owner = true
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 4.84904, 0.325371, -1.81888)
[node name="poles2" parent="Quests/BuilderMissingTool/Bridge" instance=ExtResource("18_yqn1p")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.400034, 0)
[node name="poles3" parent="Quests/BuilderMissingTool/Bridge" instance=ExtResource("18_yqn1p")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.398493, 0.670723)
[node name="Merchant" type="CharacterBody3D" parent="Quests/BuilderMissingTool"]
unique_name_in_owner = true
transform = Transform3D(-4.37114e-08, 0, -1, 0, 1, 0, 1, 0, -4.37114e-08, 3.64783, 0, -1.58598)
[node name="CollisionShape3D" type="CollisionShape3D" parent="Quests/BuilderMissingTool/Merchant"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.310637, 0)
shape = SubResource("CylinderShape3D_0soe6")
[node name="StateMarker" type="Sprite3D" parent="Quests/BuilderMissingTool/Merchant"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.0272007, 0.901301, 0.168392)
centered = false
billboard = 1
texture_filter = 0
texture = ExtResource("12_3vn8y")
[node name="Geometry" type="Node3D" parent="Quests/BuilderMissingTool/Merchant"]
transform = Transform3D(0.4, 0, 0, 0, 0.4, 0, 0, 0, 0.4, 0, 0, 0)
[node name="Engineer" parent="Quests/BuilderMissingTool/Merchant/Geometry" instance=ExtResource("13_t16lh")]
[node name="Actionable" parent="Quests/BuilderMissingTool/Merchant" instance=ExtResource("14_8oq2l")]
dialogue_resource = ExtResource("15_mqfyi")
[node name="CollisionShape3D" type="CollisionShape3D" parent="Quests/BuilderMissingTool/Merchant/Actionable"]
shape = SubResource("SphereShape3D_ugkqa")
[node name="ScaredToWalkInTheDark" type="Node" parent="Quests" groups=["quest_state"]]
script = ExtResource("17_nupwt")