diff --git a/project.godot b/project.godot index 360bca1..c5bcd06 100644 --- a/project.godot +++ b/project.godot @@ -8,14 +8,9 @@ config_version=4 -_global_script_classes=[ { -"base": "Node", -"class": "DialogueLoader", -"language": "GDScript", -"path": "res://resources/script/DialogueLoader.gd" -} ] +_global_script_classes=[ ] _global_script_class_icons={ -"DialogueLoader": "" + } [application] @@ -27,6 +22,7 @@ config/icon="res://icon.png" [autoload] ProgressManager="*res://scenes/ProgressManager.tscn" +DialogueLoader="*res://scenes/DialogueLoader.tscn" [rendering] diff --git a/resources/dialogue/lesson1.json b/resources/dialogue/lesson1.json index 996aec6..9740ced 100644 --- a/resources/dialogue/lesson1.json +++ b/resources/dialogue/lesson1.json @@ -1,10 +1,10 @@ { - "7": { + "0": { "text" : "In sanskrit there are 2 types of vowels - with short crisp prounounciations scripted as a,e,i,o,u and another group with longer and broader pronounciation written as A,E,I,O,U. the consonants also have 2 groups - the lighter group scripted as 'ka','ga','ta','da','ba','pa','ma' etc. and a heavier group with an extra 'h'- 'kha', 'gha', 'pha', 'bha', 'tha' etc. Consonants as usual get pronounced with the help of vowels.", "type": "assertive", "character":"the old man" }, - "8": { + "1": { "text" : "there are 3 genders (lingam) : punglingam(masculine), strIlingam(feminine) and napuMsaklingam(nutre), and 3 vachanam : ekvachanam(one), dwivachanam(two), bahuvachanam(many). In sanskrit there is a root to every noun and verb called 'dhAtu'. The word used in a sentence gets transformed according to gender, number, person and tense" , "type": "assertive", "character" :"the old man", @@ -23,7 +23,7 @@ } } }, - "9" : { + "2" : { "text": "dhanyavādaḥ means thanks and svāgatam means welcome. 'aham asmi' means I am. to ask questions, 'kim' means what? and 'kiyat' means how much ? and 'asti' is used as an auxilliary verb 'is'. so 'kiyat sundaram asti !' means how beautiful it is ! 'idaM kim ?' means what is this?", "type": "assertive", "character":"the old man", diff --git a/resources/script/DialogueLoader.gd b/resources/script/DialogueLoader.gd index 23f6aa9..965a8ff 100644 --- a/resources/script/DialogueLoader.gd +++ b/resources/script/DialogueLoader.gd @@ -1,5 +1,4 @@ extends Node -class_name DialogueLoader export (String, FILE, "*.json") var dialogue_file_path: String setget set_dialogue_file_path @@ -17,6 +16,5 @@ func get_dialogue() -> Dictionary: return dialogue func set_dialogue_file_path(path: String) -> void: - print(path) assert(path.ends_with(".json")) dialogue_file_path = path diff --git a/scenes/DialogueLoader.tscn b/scenes/DialogueLoader.tscn index 3a60402..534b81d 100644 --- a/scenes/DialogueLoader.tscn +++ b/scenes/DialogueLoader.tscn @@ -2,6 +2,5 @@ [ext_resource path="res://resources/script/DialogueLoader.gd" type="Script" id=1] - [node name="DialogueLoader" type="Node"] script = ExtResource( 1 ) diff --git a/scenes/dialog.tscn b/scenes/dialog.tscn index 8f17e82..1d0c972 100644 --- a/scenes/dialog.tscn +++ b/scenes/dialog.tscn @@ -38,10 +38,10 @@ anchor_left = 0.55 anchor_top = 1.05 anchor_right = 0.55 anchor_bottom = 1.05 -margin_left = -235.347 -margin_top = -155.92 -margin_right = 236.653 -margin_bottom = -27.9208 +margin_left = -262.791 +margin_top = -244.969 +margin_right = 354.209 +margin_bottom = -21.969 texture = ExtResource( 4 ) expand = true stretch_mode = 1 @@ -50,10 +50,10 @@ __meta__ = { } [node name="dialogue" type="Label" parent="DialogueSystem/DialogBox/box"] -anchor_left = -1.0572 -anchor_top = -3.36251 -anchor_right = -0.396186 -anchor_bottom = -2.73751 +anchor_left = -0.73406 +anchor_top = -1.83842 +anchor_right = -0.0730455 +anchor_bottom = -1.21342 margin_left = 600.0 margin_top = 446.4 margin_right = 640.0 @@ -67,10 +67,10 @@ __meta__ = { } [node name="speaker" type="Label" parent="DialogueSystem/DialogBox/box"] -anchor_left = -1.22361 -anchor_top = -3.27542 -anchor_right = -1.1537 -anchor_bottom = -3.21292 +anchor_left = -0.925584 +anchor_top = -1.72817 +anchor_right = -0.855674 +anchor_bottom = -1.66567 margin_left = 600.0 margin_top = 446.4 margin_right = 640.0 @@ -84,10 +84,10 @@ __meta__ = { } [node name="Button" type="Button" parent="DialogueSystem/DialogBox/box"] -margin_left = 378.597 -margin_top = 93.2273 -margin_right = 410.597 -margin_bottom = 121.227 +margin_left = 486.034 +margin_top = 165.54 +margin_right = 518.034 +margin_bottom = 193.54 icon = ExtResource( 1 ) flat = true expand_icon = true diff --git a/scenes/dialog_starting.gd b/scenes/dialog_starting.gd new file mode 100644 index 0000000..8fe1892 --- /dev/null +++ b/scenes/dialog_starting.gd @@ -0,0 +1,54 @@ +extends CanvasLayer + +onready var system = $DialogueSystem +onready var dialogue = $DialogueSystem/DialogBox/box/dialogue +onready var speaker = $DialogueSystem/DialogBox/box/speaker +onready var box = $DialogueSystem/DialogBox/box + +signal completed + +var index: int = 0 +var loadedDialogue: Dictionary + +onready var tween: Tween = $DialogueSystem/Tween +export (String, FILE, "*.json") var dialogue_file_path = "res://resources/dialogue/ayan.json" setget set_dialogue_file_path + +var state: Dictionary = {} setget set_state + +func set_dialogue_file_path(path: String) -> void: + dialogue_file_path = path + DialogueLoader.set_dialogue_file_path(dialogue_file_path) + +func set_state(new_state: Dictionary) -> void: + state = new_state + +func process_state(new_state: Dictionary) -> void: + speaker.text = new_state["character"]+ ":" + dialogue.text = new_state["text"] + tween.interpolate_property(dialogue, "visible_characters", 0, dialogue.text.length(), 0.08 * dialogue.text.length()) + tween.start() + +func _ready() -> void: + system.set_visible(false) + DialogueLoader.set_dialogue_file_path(dialogue_file_path) +# set_state(loadedDialogue[String(index)]) +# process_state(state) + +func _on_Button_button_down() -> void: + tween.stop(dialogue) + dialogue.visible_characters = dialogue.text.length() + index += 1 + if index < loadedDialogue.size(): + set_state(loadedDialogue[String(index)]) + process_state(state) + else: + system.set_visible(false) + emit_signal("completed") + +func start() -> void: + loadedDialogue = DialogueLoader.load_dialogue() + system.set_visible(true) + set_state(loadedDialogue[String(index)]) + process_state(state) + + diff --git a/scenes/dialog_starting.tscn b/scenes/dialog_starting.tscn index 3fc4d15..08609a6 100644 --- a/scenes/dialog_starting.tscn +++ b/scenes/dialog_starting.tscn @@ -1,13 +1,11 @@ -[gd_scene load_steps=5 format=2] +[gd_scene load_steps=4 format=2] [ext_resource path="res://assets/dialogue_system/next.png" type="Texture" id=1] -[ext_resource path="res://scenes/DialogueLoader.tscn" type="PackedScene" id=3] +[ext_resource path="res://scenes/dialog_starting.gd" type="Script" id=2] [ext_resource path="res://assets/dialogue_Ui/paper_hor.png" type="Texture" id=4] -[ext_resource path="res://scenes/dialogue_controller.gd" type="Script" id=5] [node name="CanvasLayer" type="CanvasLayer"] -script = ExtResource( 5 ) -dialogue_file_path = "res://resources/dialogue/story.json" +script = ExtResource( 2 ) [node name="DialogueSystem" type="Control" parent="."] anchor_left = 0.499001 @@ -98,6 +96,4 @@ __meta__ = { } [node name="Tween" type="Tween" parent="DialogueSystem"] - -[node name="DialogueLoader" parent="DialogueSystem" instance=ExtResource( 3 )] [connection signal="button_down" from="DialogueSystem/DialogBox/box/Button" to="." method="_on_Button_button_down"] diff --git a/scenes/dialogue_controller.gd b/scenes/dialogue_controller.gd index bfc51e5..44cfadc 100644 --- a/scenes/dialogue_controller.gd +++ b/scenes/dialogue_controller.gd @@ -1,27 +1,23 @@ extends CanvasLayer - -# Declare member variables here. Examples: -# var a: int = 2 -# var b: String = "text" onready var system = $DialogueSystem -export (String, FILE, "*.json") var dialogue_file_path: String = "" setget set_dialogue_file_path -signal completed - -# Called when the node enters the scene tree for the first time. onready var dialogue = $DialogueSystem/DialogBox/box/dialogue onready var speaker = $DialogueSystem/DialogBox/box/speaker onready var box = $DialogueSystem/DialogBox/box +signal completed - -var index = 0 +var index: int = 0 var loadedDialogue: Dictionary -onready var dialogLoader: DialogueLoader = $DialogueSystem/DialogueLoader onready var tween: Tween = $DialogueSystem/Tween +export (String, FILE, "*.json") var dialogue_file_path = "res://resources/dialogue/ayan.json" setget set_dialogue_file_path var state: Dictionary = {} setget set_state +func set_dialogue_file_path(path: String) -> void: + dialogue_file_path = path + DialogueLoader.set_dialogue_file_path(dialogue_file_path) + func set_state(new_state: Dictionary) -> void: state = new_state @@ -32,8 +28,10 @@ func process_state(new_state: Dictionary) -> void: tween.start() func _ready() -> void: - if dialogue_file_path != "": - loadedDialogue = dialogLoader.load_dialogue() + system.set_visible(false) + DialogueLoader.set_dialogue_file_path(dialogue_file_path) +# set_state(loadedDialogue[String(index)]) +# process_state(state) func _on_Button_button_down() -> void: tween.stop(dialogue) @@ -47,13 +45,8 @@ func _on_Button_button_down() -> void: emit_signal("completed") func start() -> void: - loadedDialogue = dialogLoader.load_dialogue() + loadedDialogue = DialogueLoader.load_dialogue() system.set_visible(true) set_state(loadedDialogue[String(index)]) process_state(state) -func set_dialogue_file_path(path: String) -> void: - dialogue_file_path = path - yield($DialogueSystem/DialogueLoader, "ready") - $DialogueSystem/DialogueLoader.set_dialogue_file_path(dialogue_file_path) - diff --git a/scenes/main.gd b/scenes/main.gd index 2fdb508..df01b9e 100644 --- a/scenes/main.gd +++ b/scenes/main.gd @@ -1,6 +1,6 @@ extends Node2D -onready var system = $"initial story" +onready var system = $"initial_story" onready var system_main = $"main_dialogue" # Declare member variables here. Examples: # var a = 2 @@ -10,7 +10,8 @@ onready var system_main = $"main_dialogue" # Called when the node enters the scene tree for the first time. func _ready(): ProgressManager.load_game() - system.start() + $"initial_story".set_dialogue_file_path("res://resources/dialogue/story.json") + $"initial_story".start() # Replace with function body. # Called every frame. 'delta' is the elapsed time since the previous frame. @@ -19,5 +20,5 @@ func _ready(): func _on_initial_story_completed(): - system_main.dialogue_file_path = "res://resources/dialogue/lesson1.json" + system_main.set_dialogue_file_path ("res://resources/dialogue/lesson1.json") system_main.start() diff --git a/scenes/main.tscn b/scenes/main.tscn index 77e39a1..77feac7 100644 --- a/scenes/main.tscn +++ b/scenes/main.tscn @@ -49,7 +49,7 @@ __meta__ = { "_edit_horizontal_guides_": [ ] } -[node name="initial story" parent="." instance=ExtResource( 39 )] +[node name="initial_story" parent="." instance=ExtResource( 39 )] [node name="main_dialogue" parent="." instance=ExtResource( 42 )] @@ -900,5 +900,5 @@ position = Vector2( 3388.58, -6526.62 ) [node name="Area2D" parent="." instance=ExtResource( 41 )] position = Vector2( 6916.3, 5517.02 ) rotation = 1.0472 -[connection signal="completed" from="initial story" to="." method="_on_initial_story_completed"] +[connection signal="completed" from="initial_story" to="." method="_on_initial_story_completed"] [connection signal="body_entered" from="Area2D" to="." method="_on_Area2D_body_entered"]