diff --git a/ConversationElement.gd b/ConversationElement.gd deleted file mode 100644 index c658aaf..0000000 --- a/ConversationElement.gd +++ /dev/null @@ -1,5 +0,0 @@ -extends Resource -class_name ConversationElement - -@export_node_path("Entity") var entity:NodePath -@export_multiline var label: String \ No newline at end of file diff --git a/cutscene/Cutscene.gd b/cutscene/Cutscene.gd new file mode 100644 index 0000000..4e35aa4 --- /dev/null +++ b/cutscene/Cutscene.gd @@ -0,0 +1,37 @@ +class_name CutsceneSingleton extends Node + +const CUTSCENE_CONTINUE = -1 +const CUTSCENE_END = -2 + +var running:bool = false + +func setConversation(conversation:Array[ConversationElement]) -> void: + var functions:Array[Callable] = [] + for element in conversation: + functions.append(element.sceneItem) + setScene(functions) + +func setScene(functions:Array[Callable]) -> void: + if functions.size() == 0: + return + + running = true + + var index = 0 + while true: + var result = await functions[index].call() + + match result: + CUTSCENE_CONTINUE: + index += 1 + + CUTSCENE_END: + break + + _: + index = result + + if index >= functions.size() || index < 0: + break + + running = false diff --git a/cutscene/Cutscene.gd.uid b/cutscene/Cutscene.gd.uid new file mode 100644 index 0000000..c974f50 --- /dev/null +++ b/cutscene/Cutscene.gd.uid @@ -0,0 +1 @@ +uid://pbitw4oq8pni diff --git a/cutscene/CutsceneScene.gd.uid b/cutscene/CutsceneScene.gd.uid new file mode 100644 index 0000000..4d49b55 --- /dev/null +++ b/cutscene/CutsceneScene.gd.uid @@ -0,0 +1 @@ +uid://d1crdj75ap0kx diff --git a/cutscene/conversation/ConversationElement.gd b/cutscene/conversation/ConversationElement.gd new file mode 100644 index 0000000..812ff65 --- /dev/null +++ b/cutscene/conversation/ConversationElement.gd @@ -0,0 +1,9 @@ +extends Resource +class_name ConversationElement + +@export_node_path("Entity") var entity:NodePath +@export_multiline var label: String + +func sceneItem() -> int: + await UI.TEXTBOX.setTextAndWait(label) + return CutsceneSingleton.CUTSCENE_CONTINUE diff --git a/ConversationElement.gd.uid b/cutscene/conversation/ConversationElement.gd.uid similarity index 100% rename from ConversationElement.gd.uid rename to cutscene/conversation/ConversationElement.gd.uid diff --git a/item/Backpack.gd.uid b/item/Backpack.gd.uid new file mode 100644 index 0000000..0f42ef9 --- /dev/null +++ b/item/Backpack.gd.uid @@ -0,0 +1 @@ +uid://d16p8hn52bby7 diff --git a/overworld/entity/Entity.gd b/overworld/entity/Entity.gd index e7b9206..ddab5c6 100644 --- a/overworld/entity/Entity.gd +++ b/overworld/entity/Entity.gd @@ -1,5 +1,5 @@ class_name Entity extends CharacterBody3D -const ConversationElement = preload("res://ConversationElement.gd") +const ConversationElement = preload("res://cutscene/conversation/ConversationElement.gd") enum MovementType { NONE, diff --git a/overworld/entity/EntityInteractableArea.gd b/overworld/entity/EntityInteractableArea.gd index e3e8bbf..0d41c41 100644 --- a/overworld/entity/EntityInteractableArea.gd +++ b/overworld/entity/EntityInteractableArea.gd @@ -17,8 +17,7 @@ func isInteractable() -> bool: return true func _onConversationInteract(_other:Entity) -> void: - print("Starting conversation with ", entity.name) - pass + CUTSCENE.setConversation(entity.conversation) func onInteract(other:Entity) -> void: if entity.interactType == Entity.InteractType.NONE: @@ -29,4 +28,4 @@ func onInteract(other:Entity) -> void: _onConversationInteract(other) return _: - pass \ No newline at end of file + pass diff --git a/overworld/map/TestMap.tscn b/overworld/map/TestMap.tscn index f6bec24..248b936 100644 --- a/overworld/map/TestMap.tscn +++ b/overworld/map/TestMap.tscn @@ -3,7 +3,7 @@ [ext_resource type="Script" uid="uid://xe6pcuq741xi" path="res://overworld/map/TestMap.gd" id="1_6ms5s"] [ext_resource type="PackedScene" uid="uid://cluuhtfjeodwb" path="res://overworld/map/TestMapBase.tscn" id="1_ox0si"] [ext_resource type="PackedScene" uid="uid://by4a0r2hp0w6s" path="res://overworld/entity/Entity.tscn" id="2_jmygs"] -[ext_resource type="Script" uid="uid://b40rstjkpompc" path="res://ConversationElement.gd" id="3_p7git"] +[ext_resource type="Script" uid="uid://b40rstjkpompc" path="res://cutscene/conversation/ConversationElement.gd" id="3_p7git"] [sub_resource type="Resource" id="Resource_p7git"] script = ExtResource("3_p7git") diff --git a/project.godot b/project.godot index dfe3ae1..2969797 100644 --- a/project.godot +++ b/project.godot @@ -23,6 +23,7 @@ UI="*res://ui/UI.tscn" QUEST="*res://quest/Quest.tscn" OVERWORLD="*res://overworld/Overworld.gd" SCENE="*res://scene/Scene.gd" +CUTSCENE="*res://cutscene/Cutscene.gd" ControllerIcons="*res://addons/controller_icons/ControllerIcons.gd" [debug] diff --git a/ui/component/VNTextbox.gd b/ui/component/VNTextbox.gd index 726623d..d053a92 100644 --- a/ui/component/VNTextbox.gd +++ b/ui/component/VNTextbox.gd @@ -71,3 +71,7 @@ func setText(text:String) -> void: await get_tree().process_frame# Absolutely needed to make the text wrap label.text = text; label.visible_characters = 0; + +func setTextAndWait(text:String) -> void: + await setText(text); + await self.textboxClosing