Skip to content

Commit

Permalink
dialogue-issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Andy260700 committed Jan 4, 2021
1 parent 29302d9 commit 9fcdb38
Show file tree
Hide file tree
Showing 10 changed files with 97 additions and 60 deletions.
10 changes: 3 additions & 7 deletions project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -27,6 +22,7 @@ config/icon="res://icon.png"
[autoload]

ProgressManager="*res://scenes/ProgressManager.tscn"
DialogueLoader="*res://scenes/DialogueLoader.tscn"

[rendering]

Expand Down
6 changes: 3 additions & 3 deletions resources/dialogue/lesson1.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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",
Expand Down
2 changes: 0 additions & 2 deletions resources/script/DialogueLoader.gd
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
extends Node
class_name DialogueLoader

export (String, FILE, "*.json") var dialogue_file_path: String setget set_dialogue_file_path

Expand All @@ -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
1 change: 0 additions & 1 deletion scenes/DialogueLoader.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@

[ext_resource path="res://resources/script/DialogueLoader.gd" type="Script" id=1]


[node name="DialogueLoader" type="Node"]
script = ExtResource( 1 )
32 changes: 16 additions & 16 deletions scenes/dialog.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
54 changes: 54 additions & 0 deletions scenes/dialog_starting.gd
Original file line number Diff line number Diff line change
@@ -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)


10 changes: 3 additions & 7 deletions scenes/dialog_starting.tscn
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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"]
31 changes: 12 additions & 19 deletions scenes/dialogue_controller.gd
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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)
Expand All @@ -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)

7 changes: 4 additions & 3 deletions scenes/main.gd
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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.
Expand All @@ -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()
4 changes: 2 additions & 2 deletions scenes/main.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -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 )]

Expand Down Expand Up @@ -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"]

0 comments on commit 9fcdb38

Please sign in to comment.