Added mapping tool, reworked scene structure, and added test data.

This commit is contained in:
2026-09-06 16:50:32 -07:00
parent ab632f455d
commit a7ba813c81
20 changed files with 350 additions and 12 deletions
+25 -1
View File
@@ -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)
+17
View File
@@ -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"])
+1
View File
@@ -0,0 +1 @@
uid://bcx25iulofjjw
+13 -1
View File
@@ -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)
+18
View File
@@ -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
+5 -5
View File
@@ -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