Skip to content

Commit 2c260e0

Browse files
henriiquecamposNathanLovato
authored andcommitted
Refactor RPG Demo
closes #263 - Rename dialog to dialogue - Give meaningful name to generic actors - Move combat screen content to turn_combat folder - Add new icon.png and .svg - Change combat UI to not emit a signal from its parent, instead pass parameters to a function and let the combat work on them there - Remove UI accessing deep layers on the hierarchy (get_parent().get_node("../etc/etc../etc...") - Fix defend() stacking, making the player invulnerable, now evey turn the Health.armor resets to a base_armor value - Remove useless Inventory button (maybe added again in the future when an inventory is added to the demo)
1 parent 5b01dcc commit 2c260e0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1241
-362
lines changed

2d/role_playing_game/Game.gd

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
extends Node
2+
3+
export (NodePath) var combat_screen
4+
export (NodePath) var exploration_screen
5+
6+
const PLAYER_WIN = "res://dialogue/dialogue_data/player_won.json"
7+
const PLAYER_LOSE = "res://dialogue/dialogue_data/player_lose.json"
8+
9+
func _ready():
10+
exploration_screen = get_node(exploration_screen)
11+
combat_screen = get_node(combat_screen)
12+
combat_screen.connect("combat_finished", self, "_on_combat_finished")
13+
for n in $Exploration/Grid.get_children():
14+
if not n.type == n.ACTOR:
15+
continue
16+
if not n.has_node("DialoguePlayer"):
17+
continue
18+
n.get_node("DialoguePlayer").connect("dialogue_finished", self,
19+
"_on_opponent_dialogue_finished", [n])
20+
remove_child(combat_screen)
21+
22+
func _on_opponent_dialogue_finished(opponent):
23+
if opponent.lost:
24+
return
25+
var player = $Exploration/Grid/Player
26+
var combatents = [player.combat_actor, opponent.combat_actor]
27+
start_combat(combatents)
28+
29+
func start_combat(combat_actors):
30+
remove_child($Exploration)
31+
$AnimationPlayer.play("fade")
32+
yield($AnimationPlayer, "animation_finished")
33+
add_child(combat_screen)
34+
combat_screen.show()
35+
combat_screen.initialize(combat_actors)
36+
$AnimationPlayer.play_backwards("fade")
37+
38+
func _on_combat_finished(winner, loser):
39+
remove_child(combat_screen)
40+
$AnimationPlayer.play_backwards("fade")
41+
add_child(exploration_screen)
42+
var dialogue = load("res://dialogue/dialogue_player/DialoguePlayer.tscn").instance()
43+
if winner.name == "Player":
44+
dialogue.dialogue_file = PLAYER_WIN
45+
else:
46+
dialogue.dialogue_file = PLAYER_LOSE
47+
yield($AnimationPlayer, "animation_finished")
48+
var player = $Exploration/Grid/Player
49+
exploration_screen.get_node("DialogueUI").show_dialogue(player, dialogue)
50+
combat_screen.clear_combat()
51+
yield(dialogue, "dialogue_finished")
52+
dialogue.queue_free()

2d/role_playing_game/Game.tscn

Lines changed: 11 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,10 @@
11
[gd_scene load_steps=5 format=2]
22

3-
[ext_resource path="res://screens/combat/Combat.tscn" type="PackedScene" id=1]
4-
[ext_resource path="res://screens/exploration/Exploration.tscn" type="PackedScene" id=2]
5-
6-
[sub_resource type="GDScript" id=1]
7-
8-
script/source = "extends Node
9-
10-
export (NodePath) var combat_screen
11-
export (NodePath) var exploration_screen
12-
13-
const PLAYER_WIN = \"res://dialog_system/dialogs/player_won.json\"
14-
const PLAYER_LOSE = \"res://dialog_system/dialogs/player_lose.json\"
15-
16-
func _ready():
17-
exploration_screen = get_node(exploration_screen)
18-
combat_screen = get_node(combat_screen)
19-
combat_screen.connect(\"combat_finished\", self, \"_on_combat_finished\")
20-
for n in $Exploration/Grid.get_children():
21-
if not n.type == n.ACTOR:
22-
continue
23-
if not n.has_node(\"DialogPlayer\"):
24-
continue
25-
n.get_node(\"DialogPlayer\").connect(\"dialog_finished\", self,
26-
\"_on_opponent_dialog_finished\", [n])
27-
remove_child(combat_screen)
28-
29-
func _on_opponent_dialog_finished(opponent):
30-
if opponent.lost:
31-
return
32-
var player = $Exploration/Grid/Player
33-
var combatents = [player.combat_actor, opponent.combat_actor]
34-
start_combat(combatents)
35-
36-
func start_combat(combat_actors):
37-
remove_child($Exploration)
38-
$AnimationPlayer.play(\"fade\")
39-
yield($AnimationPlayer, \"animation_finished\")
40-
add_child(combat_screen)
41-
combat_screen.show()
42-
combat_screen.initialize(combat_actors)
43-
$AnimationPlayer.play_backwards(\"fade\")
44-
45-
func _on_combat_finished(winner, loser):
46-
remove_child(combat_screen)
47-
$AnimationPlayer.play_backwards(\"fade\")
48-
add_child(exploration_screen)
49-
var dialog = load(\"res://dialog_system/dialog_player/DialogPlayer.tscn\").instance()
50-
if winner.name == \"Player\":
51-
dialog.dialog_file = PLAYER_WIN
52-
else:
53-
dialog.dialog_file = PLAYER_LOSE
54-
yield($AnimationPlayer, \"animation_finished\")
55-
var player = $Exploration/Grid/Player
56-
exploration_screen.get_node(\"DialogUI\").show_dialog(player, dialog)
57-
combat_screen.clear_combat()
58-
yield(dialog, \"dialog_finished\")
59-
dialog.queue_free()
60-
"
61-
62-
[sub_resource type="Animation" id=2]
3+
[ext_resource path="res://Game.gd" type="Script" id=1]
4+
[ext_resource path="res://screens/combat/Combat.tscn" type="PackedScene" id=2]
5+
[ext_resource path="res://screens/exploration/Exploration.tscn" type="PackedScene" id=3]
6+
7+
[sub_resource type="Animation" id=1]
638

649
length = 0.5
6510
loop = false
@@ -77,9 +22,10 @@ tracks/0/keys = {
7722
"values": [ Color( 0.0703125, 0.0703125, 0.0703125, 0 ), Color( 0.0703125, 0.0703125, 0.0703125, 1 ) ]
7823
}
7924

80-
[node name="Game" type="Node"]
25+
[node name="Game" type="Node" index="0"]
8126

82-
script = SubResource( 1 )
27+
script = ExtResource( 1 )
28+
_sections_unfolded = [ "Pause" ]
8329
combat_screen = NodePath("Combat")
8430
exploration_screen = NodePath("Exploration")
8531

@@ -90,7 +36,7 @@ autoplay = ""
9036
playback_process_mode = 1
9137
playback_default_blend_time = 0.0
9238
playback_speed = 1.0
93-
anims/fade = SubResource( 2 )
39+
anims/fade = SubResource( 1 )
9440
blend_times = [ ]
9541

9642
[node name="Transition" type="CanvasLayer" parent="." index="1"]
@@ -118,10 +64,10 @@ size_flags_vertical = 1
11864
color = Color( 0.0703125, 0.0703125, 0.0703125, 0 )
11965
_sections_unfolded = [ "Focus", "Mouse", "Visibility" ]
12066

121-
[node name="Combat" parent="." index="2" instance=ExtResource( 1 )]
67+
[node name="Combat" parent="." index="2" instance=ExtResource( 2 )]
12268

12369
visible = false
12470

125-
[node name="Exploration" parent="." index="3" instance=ExtResource( 2 )]
71+
[node name="Exploration" parent="." index="3" instance=ExtResource( 3 )]
12672

12773

2d/role_playing_game/dialog_system/dialog_player/DialogPlayer.gd

Lines changed: 0 additions & 38 deletions
This file was deleted.

2d/role_playing_game/dialog_system/dialog_player/DialogPlayer.tscn

Lines changed: 0 additions & 12 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"dialog_1" : {"name": "Opponent", "text": "Aha! I won, maybe you can try again next time"},
2+
"dialog_1" : {"name": "Opponent", "text": "Aha! I won, maybe you can try again next time"}
33
}
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"dialog_1" : {"name": "Opponent", "text": "Congratulations, you won!"},
2+
"dialog_1" : {"name": "Opponent", "text": "Congratulations, you won!"}
33
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
extends Node
2+
3+
export (String, FILE, "*.json") var dialogue_file
4+
var dialogue_keys = []
5+
var dialogue_name = ""
6+
var current = 0
7+
var dialogue_text = ""
8+
9+
signal dialogue_started
10+
signal dialogue_finished
11+
12+
func start_dialogue():
13+
emit_signal("dialogue_started")
14+
current = 0
15+
index_dialogue()
16+
dialogue_text = dialogue_keys[current].text
17+
dialogue_name = dialogue_keys[current].name
18+
19+
func next_dialogue():
20+
current += 1
21+
if current == dialogue_keys.size():
22+
emit_signal("dialogue_finished")
23+
return
24+
dialogue_text = dialogue_keys[current].text
25+
dialogue_name = dialogue_keys[current].name
26+
27+
func index_dialogue():
28+
var dialogue = load_dialogue(dialogue_file)
29+
dialogue_keys.clear()
30+
for key in dialogue:
31+
dialogue_keys.append(dialogue[key])
32+
33+
func load_dialogue(file_path):
34+
var file = File.new()
35+
if file.file_exists(file_path):
36+
file.open(file_path, file.READ)
37+
var dialogue = parse_json(file.get_as_text())
38+
return dialogue
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[gd_scene load_steps=2 format=2]
2+
3+
[ext_resource path="res://dialogue/dialogue_player/DialoguePlayer.gd" type="Script" id=1]
4+
5+
[node name="DialoguePlayer" type="Node"]
6+
7+
script = ExtResource( 1 )
8+
dialogue_file = null
9+
10+

0 commit comments

Comments
 (0)