Procházet zdrojové kódy

Use an event dispatcher for trigger_script event

develop
Non0w před 4 roky
rodič
revize
753e8c4059
12 změnil soubory, kde provedl 38 přidání a 31 odebrání
  1. +2
    -9
      jrpg/scenes/TestMain.tscn
  2. +1
    -3
      jrpg/scripts/entities/components/interactions/talk_interaction.gd
  3. +5
    -0
      jrpg/scripts/entities/model/player_infos.gd
  4. +1
    -4
      jrpg/scripts/levels/script_trigger.gd
  5. +1
    -2
      jrpg/scripts/levels/spawner.gd
  6. +2
    -5
      jrpg/scripts/levels/test_coins.gd
  7. +1
    -0
      jrpg/scripts/misc/controller.gd
  8. +3
    -0
      jrpg/scripts/misc/event_dispatcher.gd
  9. +10
    -4
      jrpg/scripts/misc/test_level.gd
  10. +0
    -4
      jrpg/scripts/misc/test_main.gd
  11. +5
    -0
      jrpg/scripts/ui/test_hud.gd
  12. +7
    -0
      project.godot

+ 2
- 9
jrpg/scenes/TestMain.tscn Zobrazit soubor

@@ -17,13 +17,6 @@ scenes = {

[node name="CanvasLayer" type="CanvasLayer" parent="."]

[node name="UI" type="Control" parent="CanvasLayer"]
anchor_right = 1.0
anchor_bottom = 1.0
__meta__ = {
"_edit_use_anchors_": false
}

[node name="HUD" parent="CanvasLayer/UI" instance=ExtResource( 7 )]
[node name="HUD" parent="CanvasLayer" instance=ExtResource( 7 )]

[node name="SpeechPanel" parent="CanvasLayer/UI" instance=ExtResource( 6 )]
[node name="SpeechPanel" parent="CanvasLayer" instance=ExtResource( 6 )]

+ 1
- 3
jrpg/scripts/entities/components/interactions/talk_interaction.gd Zobrazit soubor

@@ -2,9 +2,7 @@ extends BasisInteraction

class_name TalkInteraction

signal trigger_script

var yarn_script : Resource

func on_interact():
emit_signal("trigger_script", yarn_script)
EventDispatcher.emit_signal("trigger_script", yarn_script)

+ 5
- 0
jrpg/scripts/entities/model/player_infos.gd Zobrazit soubor

@@ -46,3 +46,8 @@ func gold_set(value):
func gold_get():
return gold

func reset():
curHp = maxHp
emit_signal("curHp_update", curHp)
gold = 0
emit_signal("gold_update", gold)

+ 1
- 4
jrpg/scripts/levels/script_trigger.gd Zobrazit soubor

@@ -1,12 +1,9 @@
extends Area

signal trigger_script

export var yarnScript : Resource

func enable():
self.connect("body_entered", self, "_on_TriggerArea_body_entered")

func _on_TriggerArea_body_entered(body):
print("triggered")
emit_signal("trigger_script", yarnScript)
EventDispatcher.emit_signal("trigger_script", yarnScript)

+ 1
- 2
jrpg/scripts/levels/spawner.gd Zobrazit soubor

@@ -4,13 +4,12 @@ export var character_data : Resource

var interaction_component : BasisInteraction

func spawn(level):
func spawn():
var inst = character_data.scene.instance()
inst.name = character_data.name
if character_data.yarn != null:
interaction_component = TalkInteraction.new()
interaction_component.name = character_data.yarn.resource_name
interaction_component.yarn_script = character_data.yarn
interaction_component.connect("trigger_script", level, "trigger_script")
inst.add_child(interaction_component)
add_child(inst)

+ 2
- 5
jrpg/scripts/levels/test_coins.gd Zobrazit soubor

@@ -1,14 +1,12 @@
extends Node

signal all_coins_picked_up

export var coin_scene : PackedScene

export var all_coins_picked_up_script : Resource

var coins := -1

func spawn(level):
func spawn():
if coins < 0: # not spawned yet
coins = 0
for spawn in get_children():
@@ -16,9 +14,8 @@ func spawn(level):
coin.connect("picked_up", self, "on_coin_picked_up")
coins += 1
spawn.add_child(coin)
connect("all_coins_picked_up", level, "trigger_script")

func on_coin_picked_up():
coins -= 1
if coins == 0:
emit_signal("all_coins_picked_up", all_coins_picked_up_script)
EventDispatcher.emit_signal("trigger_script", all_coins_picked_up_script)

+ 1
- 0
jrpg/scripts/misc/controller.gd Zobrazit soubor

@@ -1,5 +1,6 @@
extends Node

var hud : HUD
var speech_panel : SpeechPanel

var player_infos := PlayerInfos.new()


+ 3
- 0
jrpg/scripts/misc/event_dispatcher.gd Zobrazit soubor

@@ -0,0 +1,3 @@
extends Node

signal trigger_script

+ 10
- 4
jrpg/scripts/misc/test_level.gd Zobrazit soubor

@@ -9,11 +9,13 @@ func _ready():
yarnRunner.add_command("EnableTrigger", funcref(self, "enable_trigger"))
yarnRunner.add_command("Scene", funcref(self, "scene"))
for trigger in $Triggers.get_children():
trigger.connect("trigger_script", self, "trigger_script")
EventDispatcher.connect("trigger_script", self, "trigger_script")
trigger_script(init_yarn_script)
Controller.hud.show()
Controller.player_infos.reset()
trigger_script(init_yarn_script)

func spawn(args):
yield(get_tree(), "idle_frame")
@@ -23,7 +25,7 @@ func spawn(args):
var spawner = get_node("Spawners/" + args[0])
if spawner != null and spawner.has_method("spawn"):
spawner.spawn(self)
spawner.spawn()
else:
print("spawner " + args[0] + " not found or not compatible")
@@ -65,3 +67,7 @@ func scene(args):
print("Request new scene : " + args[0])
emit_signal("request_new_scene", args[0])

func _exit_tree():
Controller.hud.hide()
Controller.speech_panel.hide()

+ 0
- 4
jrpg/scripts/misc/test_main.gd Zobrazit soubor

@@ -16,10 +16,6 @@ func load_scene(scene_key):
var scene = scenes[scene_key].instance()
scene.connect("request_new_scene", self, "load_scene")
$SceneContainer.add_child(scene)
if scene_key == "TestGameOver":
$CanvasLayer/UI.hide()
else:
$CanvasLayer/UI.show()

func wait_signal(args):
yield(self, "end")


+ 5
- 0
jrpg/scripts/ui/test_hud.gd Zobrazit soubor

@@ -1,5 +1,7 @@
extends Control

class_name HUD

export var healthBar_path : NodePath
onready var healthBar = get_node(healthBar_path)
export var goldText_path : NodePath
@@ -27,3 +29,6 @@ func fetch_components():
healthBar = get_node("HealthBar")
if goldText == null:
goldText = get_node("GoldText")

func _enter_tree():
Controller.hud = self

+ 7
- 0
project.godot Zobrazit soubor

@@ -29,6 +29,11 @@ _global_script_classes=[ {
"language": "GDScript",
"path": "res://jrpg/scripts/ui/choices_box.gd"
}, {
"base": "Control",
"class": "HUD",
"language": "GDScript",
"path": "res://jrpg/scripts/ui/test_hud.gd"
}, {
"base": "KinematicBody",
"class": "Player",
"language": "GDScript",
@@ -84,6 +89,7 @@ _global_script_class_icons={
"BasisInteraction": "",
"CharacterData": "",
"ChoicesBox": "",
"HUD": "",
"Player": "",
"PlayerInfos": "",
"SpeechPanel": "",
@@ -105,6 +111,7 @@ config/icon="res://icon.png"
[autoload]

Controller="*res://jrpg/scripts/misc/controller.gd"
EventDispatcher="*res://jrpg/scripts/misc/event_dispatcher.gd"

[editor_plugins]



Načítá se…
Zrušit
Uložit