forked from harper/spooktober-vnj
Added mapping tool, reworked scene structure, and added test data.
This commit is contained in:
@@ -3,20 +3,34 @@
|
||||
[ext_resource type="Script" uid="uid://dw5jr50hsls5n" path="res://dialogue/scripts/dialogue.gd" id="1_tbx8t"]
|
||||
[ext_resource type="Script" uid="uid://d2d5w1vmd71js" path="res://dialogue/scripts/choice.gd" id="2_7gud4"]
|
||||
[ext_resource type="Script" uid="uid://cu54e7uh65lq0" path="res://dialogue/scripts/scene.gd" id="3_2c6wc"]
|
||||
[ext_resource type="Script" uid="uid://bcx25iulofjjw" path="res://dialogue/scripts/choice_target.gd" id="3_7gud4"]
|
||||
|
||||
[sub_resource type="Resource" id="Resource_w5su3"]
|
||||
script = ExtResource("3_7gud4")
|
||||
metadata/_custom_type_script = "uid://bcx25iulofjjw"
|
||||
|
||||
[sub_resource type="Resource" id="Resource_6lvw1"]
|
||||
script = ExtResource("2_7gud4")
|
||||
response = "test1"
|
||||
targets = Array[ExtResource("3_7gud4")]([SubResource("Resource_w5su3")])
|
||||
metadata/_custom_type_script = "uid://d2d5w1vmd71js"
|
||||
|
||||
[sub_resource type="Resource" id="Resource_k33ik"]
|
||||
script = ExtResource("2_7gud4")
|
||||
response = "test2"
|
||||
metadata/_custom_type_script = "uid://d2d5w1vmd71js"
|
||||
|
||||
[sub_resource type="Resource" id="Resource_qdk4l"]
|
||||
script = ExtResource("1_tbx8t")
|
||||
dialogue = "this is a test of the dialoge sysytem"
|
||||
choices = Array[ExtResource("2_7gud4")]([SubResource("Resource_6lvw1"), SubResource("Resource_k33ik")])
|
||||
metadata/_custom_type_script = "uid://dw5jr50hsls5n"
|
||||
|
||||
[sub_resource type="Resource" id="Resource_psx0q"]
|
||||
script = ExtResource("1_tbx8t")
|
||||
dialogue = "this should be the second message"
|
||||
metadata/_custom_type_script = "uid://dw5jr50hsls5n"
|
||||
|
||||
[sub_resource type="Resource" id="Resource_elg5j"]
|
||||
script = ExtResource("1_tbx8t")
|
||||
dialogue = "i hope you enjoyed"
|
||||
metadata/_custom_type_script = "uid://dw5jr50hsls5n"
|
||||
|
||||
[resource]
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
{
|
||||
"d":[
|
||||
{
|
||||
"chr": "test_character1",
|
||||
"d": "Hi, I'm test1!\nNice to meet you, what's your name?",
|
||||
"chs": []
|
||||
},
|
||||
{
|
||||
"chr": "test_character2",
|
||||
"d": "I'm test2!",
|
||||
"chs": []
|
||||
},
|
||||
{
|
||||
"chr": "test_character1",
|
||||
"d": "Where are you from?",
|
||||
"chs": [
|
||||
{
|
||||
"r": "Atlanta",
|
||||
"t": [
|
||||
{
|
||||
"t": "test_scene3.json",
|
||||
"c": [],
|
||||
"e": "ATL1"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"r": "San Francisco",
|
||||
"t": [
|
||||
{
|
||||
"t": "test_scene4.json",
|
||||
"c": [],
|
||||
"e": "SFO1"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"d":[
|
||||
{
|
||||
"chr": "test_character1",
|
||||
"d": "Goodbye!",
|
||||
"chs": []
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"d":[
|
||||
{
|
||||
"chr": "test_character1",
|
||||
"d": "You are from Atlanta!",
|
||||
"chs": [
|
||||
{
|
||||
"r": "",
|
||||
"t": [
|
||||
{
|
||||
"t": "test_scene2.json",
|
||||
"c": [],
|
||||
"e": ""
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"d":[
|
||||
{
|
||||
"chr": "test_character1",
|
||||
"d": "You are from San Francisco!",
|
||||
"chs": [
|
||||
{
|
||||
"r": "",
|
||||
"t": [
|
||||
{
|
||||
"t": "test_scene2.json",
|
||||
"c": [],
|
||||
"e": ""
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -2,4 +2,28 @@ extends Resource
|
||||
class_name Choice
|
||||
|
||||
@export var response: String
|
||||
@export var scene: DialogueScene
|
||||
@export var targets: Array[ChoiceTarget]
|
||||
|
||||
func get_target()->DialogueScene:
|
||||
for target : ChoiceTarget in targets:
|
||||
if target.condition_events.is_empty():
|
||||
if !target.target_event.is_empty():
|
||||
Game.log_event_data(target.target_event)
|
||||
return target.target_scene
|
||||
if Game.has_all_events_data(target.condition_events):
|
||||
if !target.target_event.is_empty():
|
||||
Game.log_event_data(target.target_event)
|
||||
return target.target_scene
|
||||
print(error_string(ERR_INVALID_PARAMETER) +
|
||||
" in Choice.get_target(), check that there is a target with an empty condition_events in targets")
|
||||
return null
|
||||
|
||||
func _init(str1 : String, targs : Array[ChoiceTarget]):
|
||||
response = str1
|
||||
targets = targs
|
||||
|
||||
static func load_dict(dict : Dictionary) -> Choice:
|
||||
var ts : Array[ChoiceTarget] = []
|
||||
for tar : Dictionary in dict["t"]:
|
||||
ts.append(ChoiceTarget.load_dict(tar))
|
||||
return new(dict["r"], ts)
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
extends Resource
|
||||
class_name ChoiceTarget
|
||||
## Target scene to go to if condition is in game events.
|
||||
@export var target_scene_loc: String
|
||||
## An array of event names-- empty array means that this target is default.
|
||||
@export var condition_events: Array[String]
|
||||
## Name of event to log to events data.
|
||||
## Can be empty string, in which case no event is logged.
|
||||
@export var target_event: String
|
||||
|
||||
func _init(t_sc_loc : String, conditions: Array, event : String):
|
||||
target_scene_loc = t_sc_loc
|
||||
condition_events.assign(conditions)
|
||||
target_event = event
|
||||
|
||||
static func load_dict(dict : Dictionary) -> ChoiceTarget:
|
||||
return ChoiceTarget.new(dict["t"], dict["c"], dict["e"])
|
||||
@@ -0,0 +1 @@
|
||||
uid://bcx25iulofjjw
|
||||
@@ -2,5 +2,17 @@ extends Resource
|
||||
class_name Dialogue
|
||||
|
||||
@export var character: Character
|
||||
@export_multiline() var dialogue: String
|
||||
@export_multiline() var dialogue_str: String
|
||||
@export var choices: Array[Choice]
|
||||
|
||||
func _init(chr : String, str1:String, choices1:Array[Choice]):
|
||||
# there's probably a better way to do this but idk yet
|
||||
character = load("res://characters/"+chr+".tres")
|
||||
dialogue_str = str1
|
||||
choices = choices1
|
||||
|
||||
static func load_dict(dict: Dictionary) -> Dialogue:
|
||||
var chs : Array[Choice] = []
|
||||
for ch : Dictionary in dict["chs"]:
|
||||
chs.append(Choice.load_dict(ch))
|
||||
return new(dict["chr"], dict["d"], chs)
|
||||
|
||||
@@ -1,7 +1,25 @@
|
||||
extends Resource
|
||||
class_name DialogueScene
|
||||
|
||||
static var baseLoc : String= "res://dialogue/resources/"
|
||||
@export var dialogue: Array[Dialogue]
|
||||
|
||||
func get_scene() -> Array[Dialogue]:
|
||||
return self.dialogue
|
||||
|
||||
func _init(dia : Array[Dialogue]) -> void:
|
||||
dialogue = dia
|
||||
|
||||
static func load_dict(dict : Dictionary) -> DialogueScene:
|
||||
var dia : Array[Dialogue]= []
|
||||
for d :Dictionary in dict["d"]:
|
||||
dia.append(Dialogue.load_dict(d))
|
||||
return new(dia)
|
||||
|
||||
static func load_scene(loc: String) -> DialogueScene:
|
||||
var f = FileAccess.open(baseLoc + loc, FileAccess.READ)
|
||||
if f != null:
|
||||
var ret = DialogueScene.load_dict(JSON.parse_string(f.get_as_text()))
|
||||
f.close()
|
||||
return ret
|
||||
return null
|
||||
|
||||
@@ -17,12 +17,12 @@ func Start():
|
||||
|
||||
func walk_scene(next_scene: DialogueScene):
|
||||
print("walking scene")
|
||||
for scene in next_scene.get_scene():
|
||||
print(scene.dialogue)
|
||||
if scene.choices.size() > 0:
|
||||
for choice in scene.choices:
|
||||
for dia : Dialogue in next_scene.get_scene():
|
||||
print(dia.dialogue_str)
|
||||
if dia.choices.size() > 0:
|
||||
for choice: Choice in dia.choices:
|
||||
print(choice.response)
|
||||
if Input.is_key_pressed(KEY_1):
|
||||
await walk_scene(scene.choices[0].scene)
|
||||
await walk_scene(dia.choices[0].get_target())
|
||||
step.emit()
|
||||
await step
|
||||
|
||||
Reference in New Issue
Block a user