Sfoglia il codice sorgente

Refacto interaction system, still WIP

develop
Non0w 4 anni fa
parent
commit
7792b2e1f4
19 ha cambiato i file con 181 aggiunte e 152 eliminazioni
  1. +8
    -4
      jrpg/scenes/TestGameOver.tscn
  2. +21
    -20
      jrpg/scenes/TestLVL.tscn
  3. +1
    -7
      jrpg/scenes/TestMain.tscn
  4. +3
    -21
      jrpg/scripts/entities/components/interactions/talk_interaction.gd
  5. +3
    -1
      jrpg/scripts/levels/base_level.gd
  6. +11
    -0
      jrpg/scripts/levels/game_over_scene.gd
  7. +9
    -12
      jrpg/scripts/levels/script_trigger.gd
  8. +7
    -9
      jrpg/scripts/levels/spawner.gd
  9. +5
    -12
      jrpg/scripts/levels/test_coins.gd
  10. +1
    -1
      jrpg/scripts/misc/controller.gd
  11. +63
    -2
      jrpg/scripts/misc/test_level.gd
  12. +13
    -19
      jrpg/scripts/misc/test_main.gd
  13. +11
    -2
      jrpg/scripts/ui/speech_panel.gd
  14. +8
    -0
      jrpg/yarn_scripts/all_coins_picked_up_script.yarn
  15. +1
    -1
      jrpg/yarn_scripts/event1.yarn
  16. +0
    -40
      jrpg/yarn_scripts/main_debug.yarn
  17. +1
    -1
      jrpg/yarn_scripts/npc_debug.yarn
  18. +9
    -0
      jrpg/yarn_scripts/test_start.yarn
  19. +6
    -0
      project.godot

+ 8
- 4
jrpg/scenes/TestGameOver.tscn Vedi File

@@ -1,18 +1,22 @@
[gd_scene load_steps=2 format=2]
[gd_scene load_steps=3 format=2]

[ext_resource path="res://jrpg/fonts/puritan.tres" type="DynamicFont" id=1]
[ext_resource path="res://jrpg/scripts/levels/game_over_scene.gd" type="Script" id=2]

[node name="TestGameOver" type="Control"]
anchor_right = 1.0
anchor_bottom = 1.0
script = ExtResource( 2 )
__meta__ = {
"_edit_use_anchors_": false
}

[node name="Label" type="Label" parent="."]
[node name="Button" type="Button" parent="."]
anchor_right = 1.0
anchor_bottom = 1.0
custom_fonts/font = ExtResource( 1 )
text = "Game Over"
align = 1
valign = 1
__meta__ = {
"_edit_use_anchors_": false
}
[connection signal="pressed" from="Button" to="." method="_on_Button_pressed"]

+ 21
- 20
jrpg/scenes/TestLVL.tscn Vedi File

@@ -1,7 +1,7 @@
[gd_scene load_steps=29 format=2]
[gd_scene load_steps=30 format=2]

[ext_resource path="res://jrpg/scripts/levels/spawner.gd" type="Script" id=1]
[ext_resource path="res://addons/yarn_spinner/yarn_runner_node.gd" type="Script" id=2]
[ext_resource path="res://jrpg/yarn_scripts/test_start.yarn" type="Resource" id=2]
[ext_resource path="res://jrpg/scenes/entities/Pickup.tscn" type="PackedScene" id=3]
[ext_resource path="res://jrpg/yarn_scripts/event1.yarn" type="Resource" id=4]
[ext_resource path="res://jrpg/scripts/levels/test_coins.gd" type="Script" id=5]
@@ -12,6 +12,7 @@
[ext_resource path="res://jrpg/models/nature/_defaultMat.material" type="Material" id=10]
[ext_resource path="res://jrpg/scripts/levels/script_trigger.gd" type="Script" id=11]
[ext_resource path="res://jrpg/characters/basic_enemy.tres" type="Resource" id=12]
[ext_resource path="res://jrpg/yarn_scripts/all_coins_picked_up_script.yarn" type="Resource" id=13]
[ext_resource path="res://jrpg/scripts/misc/test_level.gd" type="Script" id=15]

[sub_resource type="ArrayMesh" id=1]
@@ -241,6 +242,7 @@ radius = 5.11979

[node name="TestLVL" type="Spatial"]
script = ExtResource( 15 )
init_yarn_script = ExtResource( 2 )

[node name="WorldEnvironment" type="WorldEnvironment" parent="."]
environment = ExtResource( 7 )
@@ -372,48 +374,47 @@ material/1 = null
[node name="CollisionShape" type="CollisionShape" parent="ground_grass/Rocks/rock_largeC/tmpParent/rock_largeC/StaticBody"]
shape = SubResource( 14 )

[node name="Coins" type="Spatial" parent="."]
[node name="Spawners" type="Spatial" parent="."]

[node name="Coins" type="Spatial" parent="Spawners"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.43111, 0 )
script = ExtResource( 5 )
coin_scene = ExtResource( 3 )
all_coins_picked_up_script = ExtResource( 13 )

[node name="CoinSpawn1" type="Spatial" parent="Coins"]
[node name="CoinSpawn1" type="Spatial" parent="Spawners/Coins"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 14.3334, 0, 0 )

[node name="CoinSpawn2" type="Spatial" parent="Coins"]
[node name="CoinSpawn2" type="Spatial" parent="Spawners/Coins"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -14.165, 0, 0 )

[node name="CoinSpawn3" type="Spatial" parent="Coins"]
[node name="CoinSpawn3" type="Spatial" parent="Spawners/Coins"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -4.81607, 0, 9.68945 )

[node name="CoinSpawn4" type="Spatial" parent="Coins"]
[node name="CoinSpawn4" type="Spatial" parent="Spawners/Coins"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 19.3149, 0, 6.87337 )

[node name="CoinSpawn5" type="Spatial" parent="Coins"]
[node name="CoinSpawn5" type="Spatial" parent="Spawners/Coins"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -0.330003, 4.60946, -9.86923 )

[node name="CoinSpawn6" type="Spatial" parent="Coins"]
[node name="CoinSpawn6" type="Spatial" parent="Spawners/Coins"]

[node name="Enemy Spawner" type="Spatial" parent="."]
[node name="Kiley" type="Spatial" parent="Spawners"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 3.42834, 0, 8.41565 )
script = ExtResource( 1 )
character_data = ExtResource( 12 )

[node name="Player Spawner" type="Spatial" parent="."]
[node name="Player" type="Spatial" parent="Spawners"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -0.218717, 0, -1.84536 )
script = ExtResource( 1 )
character_data = ExtResource( 6 )
spawn_on_ready = true

[node name="TriggerArea" type="Area" parent="."]
[node name="Triggers" type="Spatial" parent="."]

[node name="Event1" type="Area" parent="Triggers"]
transform = Transform( 0.575895, 0, 0, 0, 0.575895, 0, 0, 0, 0.575895, 10.1852, 5.06822, 17.449 )
script = ExtResource( 11 )
yarnScript = ExtResource( 4 )

[node name="CollisionShape" type="CollisionShape" parent="TriggerArea"]
[node name="CollisionShape" type="CollisionShape" parent="Triggers/Event1"]
shape = SubResource( 15 )

[node name="YarnRunnerNode" type="Node" parent="TriggerArea"]
script = ExtResource( 2 )
yarnScript = ExtResource( 4 )
[connection signal="all_coins_picked_up" from="Coins" to="." method="_on_Coins_all_coins_picked_up"]
[connection signal="body_entered" from="TriggerArea" to="TriggerArea" method="_on_TriggerArea_body_entered"]

+ 1
- 7
jrpg/scenes/TestMain.tscn Vedi File

@@ -1,8 +1,6 @@
[gd_scene load_steps=8 format=2]
[gd_scene load_steps=6 format=2]

[ext_resource path="res://addons/yarn_spinner/yarn_runner_node.gd" type="Script" id=1]
[ext_resource path="res://jrpg/scripts/misc/test_main.gd" type="Script" id=2]
[ext_resource path="res://jrpg/yarn_scripts/main_debug.yarn" type="Resource" id=3]
[ext_resource path="res://jrpg/scenes/TestLVL.tscn" type="PackedScene" id=4]
[ext_resource path="res://jrpg/scenes/TestGameOver.tscn" type="PackedScene" id=5]
[ext_resource path="res://jrpg/scenes/ui/SpeechPanel.tscn" type="PackedScene" id=6]
@@ -15,10 +13,6 @@ scenes = {
"TestLVL": ExtResource( 4 )
}

[node name="YarnRunnerNode" type="Node" parent="."]
script = ExtResource( 1 )
yarnScript = ExtResource( 3 )

[node name="SceneContainer" type="Node" parent="."]

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


+ 3
- 21
jrpg/scripts/entities/components/interactions/talk_interaction.gd Vedi File

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

class_name TalkInteraction

var is_talking = false
signal trigger_script

export var yarnScript : Resource

var yarnRunner := YarnRunner.new()

func _ready():
yarnRunner.add_command("SpawnCoins", funcref($"../../../Coins", "spawn_coins"))
var yarn_script : Resource

func on_interact():
if not is_talking:
yarnRunner.say_func = funcref(Controller.speech_panel.text, "on_new_line")
yarnRunner.choices_func = funcref(Controller.speech_panel.choices, "on_choices")
yarnRunner.yarnScript = self.yarnScript
is_talking = true
Controller.speech_panel.show()
Controller.player_input_enabled = false
yield(yarnRunner.run_all(), "completed")
Controller.player_input_enabled = true
Controller.speech_panel.hide()
is_talking = false
emit_signal("trigger_script", yarn_script)

+ 3
- 1
jrpg/scripts/levels/base_level.gd Vedi File

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

class_name BaseLevel

signal end
signal request_new_scene

onready var yarnRunner := YarnRunner.new()

func _enter_tree():
Controller.player_input_enabled = true


+ 11
- 0
jrpg/scripts/levels/game_over_scene.gd Vedi File

@@ -0,0 +1,11 @@
extends BaseLevel

func _input(event):
if event.is_action_pressed("ui_accept") or event.is_action_pressed("ui_cancel"):
on_interaction()

func _on_Button_pressed():
on_interaction()

func on_interaction():
emit_signal("request_new_scene", "TestLVL")

+ 9
- 12
jrpg/scripts/levels/script_trigger.gd Vedi File

@@ -1,15 +1,12 @@
extends Node
extends Area

var prout := false
signal trigger_script

func _ready():
$YarnRunnerNode.yarnRunner.add_command("Spawn", funcref(self, "spawn"))
func _on_TriggerArea_body_entered(body):
if not prout:
$YarnRunnerNode.start_script()
prout = true
export var yarnScript : Resource

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

func spawn(entity):
yield(get_tree(), "idle_frame")
$"../Enemy Spawner".spawn($"../Enemy Spawner".character_data)
func _on_TriggerArea_body_entered(body):
print("triggered")
emit_signal("trigger_script", yarnScript)

+ 7
- 9
jrpg/scripts/levels/spawner.gd Vedi File

@@ -1,18 +1,16 @@
extends Node

export var character_data : Resource
export var spawn_on_ready := false

func _ready():
if spawn_on_ready:
spawn(character_data)
var interaction_component : BasisInteraction

func spawn(entity):
func spawn(level):
var inst = character_data.scene.instance()
inst.name = character_data.name
if character_data.yarn != null:
var yarn_runner := TalkInteraction.new()
yarn_runner.name = character_data.yarn.resource_name
yarn_runner.yarnScript = character_data.yarn
inst.add_child(yarn_runner)
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)

+ 5
- 12
jrpg/scripts/levels/test_coins.gd Vedi File

@@ -4,28 +4,21 @@ signal all_coins_picked_up

export var coin_scene : PackedScene

var prout := false

export var spawn_on_ready := false
export var all_coins_picked_up_script : Resource

var coins := -1

func _ready():
if spawn_on_ready:
spawn_coins(null)

func spawn_coins(args):
yield(get_tree(), "idle_frame")
if not prout:
func spawn(level):
if coins < 0: # not spawned yet
coins = 0
for spawn in get_children():
var coin = coin_scene.instance()
coin.connect("picked_up", self, "on_coin_picked_up")
coins += 1
spawn.add_child(coin)
prout = true
connect("all_coins_picked_up", level, "trigger_script")

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

+ 1
- 1
jrpg/scripts/misc/controller.gd Vedi File

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

var speech_panel
var speech_panel : SpeechPanel

var player_infos := PlayerInfos.new()



+ 63
- 2
jrpg/scripts/misc/test_level.gd Vedi File

@@ -2,5 +2,66 @@ extends BaseLevel

class_name TestLevel

func _on_Coins_all_coins_picked_up():
emit_signal("end")
export var init_yarn_script : Resource

func _ready():
yarnRunner.add_command("Spawn", funcref(self, "spawn"))
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")
trigger_script(init_yarn_script)
func spawn(args):
yield(get_tree(), "idle_frame")
if args.size() < 1:
printerr("Spawn command take at least one parameter for target")
return
var spawner = get_node("Spawners/" + args[0])
if spawner != null and spawner.has_method("spawn"):
spawner.spawn(self)
else:
print("spawner " + args[0] + " not found or not compatible")
func enable_trigger(args):
yield(get_tree(), "idle_frame")
if args.size() < 1:
printerr("EnableTrigger command take at least one parameter for target")
return
var trigger = get_node("Triggers/" + args[0])
if trigger != null and trigger.has_method("enable"):
trigger.enable()
print("trigger " + args[0] + " enabled")
else:
print("trigger " + args[0] + " not found or not compatible")

func trigger_script(yarn_script):
print("script triggered")
yarnRunner.say_func = funcref(Controller.speech_panel.text, "on_new_line")
yarnRunner.choices_func = funcref(Controller.speech_panel.choices, "on_choices")
Controller.speech_panel.show()
Controller.player_input_enabled = false
yarnRunner.yarnScript = yarn_script
yield(yarnRunner.run_all(), "completed")
Controller.speech_panel.hide()
Controller.player_input_enabled = true

func scene(args):
yield(get_tree(), "idle_frame")
if args.size() < 1:
printerr("Scene command take at least one parameter for target")
return
print("Request new scene : " + args[0])
emit_signal("request_new_scene", args[0])

+ 13
- 19
jrpg/scripts/misc/test_main.gd Vedi File

@@ -5,31 +5,25 @@ export var scenes : Dictionary
signal end

func _ready():
$YarnRunnerNode.yarnRunner.add_command("Scene", funcref(self, "load_scene"))
$YarnRunnerNode.yarnRunner.add_command("WaitSignal", funcref(self, "wait_signal"))
yield($YarnRunnerNode.start_script(), "completed")
load_scene("TestLVL")

func load_scene(args):
func load_scene(scene_key):
yield(get_tree(),"idle_frame")
if args.size() > 0:
var scene_key = args[0]
if scenes.has(scene_key):
for child in $SceneContainer.get_children():
child.queue_free()
var scene = scenes[scene_key].instance()
scene.connect("end", self, "on_scene_end")
$SceneContainer.add_child(scene)
if scene_key == "TestGameOver":
$CanvasLayer/UI.hide()
else:
$CanvasLayer/UI.show()
print(scene_key)
if scenes.has(scene_key):
for child in $SceneContainer.get_children():
child.queue_free()
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")

func on_scene_end():
emit_signal("end")

func _input(event):
if event.is_action_pressed("ui_cancel"):
emit_signal("end")

+ 11
- 2
jrpg/scripts/ui/speech_panel.gd Vedi File

@@ -1,11 +1,20 @@
extends Control

class_name SpeechPanel

export var text_path : NodePath
onready var text := get_node(text_path)
var text : SpeechText

export var choices_path : NodePath
onready var choices := get_node(choices_path)
var choices : ChoicesBox

func _enter_tree():
Controller.speech_panel = self
text = get_node(text_path)
choices = get_node(choices_path)

func _ready():
Controller.speech_panel = self
text = get_node(text_path)
choices = get_node(choices_path)
hide()

+ 8
- 0
jrpg/yarn_scripts/all_coins_picked_up_script.yarn Vedi File

@@ -0,0 +1,8 @@
title: Start
tags:
colorID: 0
position: 693,546
---
All coins picked up!!
<<Scene TestGameOver>>
===

+ 1
- 1
jrpg/yarn_scripts/event1.yarn Vedi File

@@ -4,6 +4,6 @@ colorID: 0
position: 693,546
---
Un personnage apparaît !
<<Spawn enemy_base>>
<<Spawn Kiley>>
Un personnage est apparu !
===

+ 0
- 40
jrpg/yarn_scripts/main_debug.yarn Vedi File

@@ -1,40 +0,0 @@
title: Start
tags:
colorID: 0
position: 571,308
---
Starting
[[TestLVL]]
===
title: TestLVL
tags:
colorID: 0
position: 571,668
---
<<Scene TestLVL>>
Scene loaded
[[TestLVLLoop]]
===
title: GameOver
tags:
colorID: 0
position: 1096,808
---
<<Scene TestGameOver>>
Game Over
<<WaitSignal>>
Restarting
[[TestLVL]]
===
title: TestLVLLoop
tags:
colorID: 0
position: 579,916
---
<<WaitSignal>>
<<if False>>
[[TestLVLLoop]]
<<else>>
[[GameOver]]
<<endif>>
===

+ 1
- 1
jrpg/yarn_scripts/npc_debug.yarn Vedi File

@@ -15,7 +15,7 @@ position: 1032,730
Est-ce que tu aimes la France ?
Est-ce que tu es prêt à donner ta vie pour la France ??
A MOURIIIR POUR TA PATRIE ??
<<SpawnCoins>>
<<Spawn Coins>>
Alors ramasse les piépièces !
===
title: ntm


+ 9
- 0
jrpg/yarn_scripts/test_start.yarn Vedi File

@@ -0,0 +1,9 @@
title: Start
tags:
colorID: 0
position: 693,546
---
<<Spawn Player>>
Let's Start !
<<EnableTrigger Event1>>
===

+ 6
- 0
project.godot Vedi File

@@ -39,6 +39,11 @@ _global_script_classes=[ {
"language": "GDScript",
"path": "res://jrpg/scripts/entities/model/player_infos.gd"
}, {
"base": "Control",
"class": "SpeechPanel",
"language": "GDScript",
"path": "res://jrpg/scripts/ui/speech_panel.gd"
}, {
"base": "Label",
"class": "SpeechText",
"language": "GDScript",
@@ -81,6 +86,7 @@ _global_script_class_icons={
"ChoicesBox": "",
"Player": "",
"PlayerInfos": "",
"SpeechPanel": "",
"SpeechText": "",
"TalkInteraction": "",
"TestLevel": "",


Caricamento…
Annulla
Salva