mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-22 00:03:47 +00:00
Updated dialogic
This commit is contained in:
parent
1d11462073
commit
cbb82512ee
483 changed files with 5743 additions and 2177 deletions
|
|
@ -1,17 +1,24 @@
|
|||
@tool
|
||||
extends Resource
|
||||
@icon("uid://j7ym07anlusi")
|
||||
extends "res://addons/dialogic/Resources/dialogic_identifiable_resource.gd"
|
||||
class_name DialogicTimeline
|
||||
|
||||
## Resource that defines a list of events.
|
||||
## It can store them as text and load them from text too.
|
||||
|
||||
|
||||
var events: Array = []
|
||||
var events_processed := false
|
||||
var text_lines_indexed := {}
|
||||
var indent_format := "\t"
|
||||
|
||||
|
||||
## Method used for printing timeline resources identifiably
|
||||
func _to_string() -> String:
|
||||
return "[DialogicTimeline:{file}]".format({"file":resource_path})
|
||||
func _get_extension() -> String:
|
||||
return "dtl"
|
||||
|
||||
|
||||
func _get_resource_name() -> String:
|
||||
return "DialogicTimeline"
|
||||
|
||||
|
||||
## Helper method
|
||||
|
|
@ -27,6 +34,13 @@ func from_text(text:String) -> void:
|
|||
events = text.split('\n', true)
|
||||
events_processed = false
|
||||
|
||||
## Take an initial guess about the indentation format
|
||||
## because the text editor needs it but doesn't call _process()
|
||||
for ev in events:
|
||||
indent_format = ev.substr(0, len(ev) - len(ev.strip_edges(true, false)))
|
||||
if indent_format:
|
||||
break
|
||||
|
||||
|
||||
## Stores all events in their text format and returns them as a string
|
||||
func as_text() -> String:
|
||||
|
|
@ -43,8 +57,8 @@ func as_text() -> String:
|
|||
|
||||
if event != null:
|
||||
for i in event.empty_lines_above:
|
||||
result += "\t".repeat(indent)+"\n"
|
||||
result += "\t".repeat(indent)+event.event_node_as_text.replace('\n', "\n"+"\t".repeat(indent)) + "\n"
|
||||
result += indent_format.repeat(indent)+"\n"
|
||||
result += indent_format.repeat(indent)+event.event_node_as_text.replace('\n', "\n"+indent_format.repeat(indent)) + "\n"
|
||||
if event.can_contain_events:
|
||||
indent += 1
|
||||
if indent < 0:
|
||||
|
|
@ -58,8 +72,18 @@ func as_text() -> String:
|
|||
return result.strip_edges()
|
||||
|
||||
|
||||
## Returns the index of the event that corresponds to a specific line
|
||||
func get_index_from_text_line(text:String, line) -> int:
|
||||
from_text(text)
|
||||
process()
|
||||
return text_lines_indexed[line]
|
||||
|
||||
|
||||
## Method that loads all the event resources from the strings, if it wasn't done before
|
||||
func process() -> void:
|
||||
if len(events) == 0:
|
||||
return
|
||||
|
||||
if typeof(events[0]) == TYPE_STRING:
|
||||
events_processed = false
|
||||
|
||||
|
|
@ -73,7 +97,9 @@ func process() -> void:
|
|||
var end_event := DialogicEndBranchEvent.new()
|
||||
|
||||
var prev_indent := ""
|
||||
indent_format = ""
|
||||
var processed_events := []
|
||||
text_lines_indexed = {}
|
||||
|
||||
# this is needed to add an end branch event even to empty conditions/choices
|
||||
var prev_was_opener := false
|
||||
|
|
@ -83,6 +109,7 @@ func process() -> void:
|
|||
var empty_lines := 0
|
||||
while idx < len(lines)-1:
|
||||
idx += 1
|
||||
text_lines_indexed[idx] = len(processed_events)
|
||||
|
||||
# make sure we are using the string version, in case this was already converted
|
||||
var line := ""
|
||||
|
|
@ -99,8 +126,14 @@ func process() -> void:
|
|||
|
||||
## Add an end event if the indent is smaller then previously
|
||||
var indent: String = line.substr(0,len(line)-len(line_stripped))
|
||||
if indent and ((not indent_format) or not (indent_format in indent)):
|
||||
if not indent_format.is_empty():
|
||||
printerr("Timeline contains varying indentation. Found {0} instead of expected {1}.".format([indent, indent_format]))
|
||||
else:
|
||||
indent_format = indent
|
||||
if len(indent) < len(prev_indent):
|
||||
for i in range(len(prev_indent)-len(indent)):
|
||||
@warning_ignore("integer_division")
|
||||
for i in range(len(prev_indent)/len(indent_format)-len(indent)/len(indent_format)):
|
||||
processed_events.append(end_event.duplicate())
|
||||
## Add an end event if the indent is the same but the previous was an opener
|
||||
## (so for example choice that is empty)
|
||||
|
|
@ -112,16 +145,13 @@ func process() -> void:
|
|||
## Now we process the event into a resource
|
||||
## by checking on each event if it recognizes this string
|
||||
var event_content: String = line_stripped
|
||||
var event: DialogicEvent
|
||||
for i in event_cache:
|
||||
if i._test_event_string(event_content):
|
||||
event = i.duplicate()
|
||||
break
|
||||
var event: DialogicEvent = event_from_string(event_content, event_cache)
|
||||
|
||||
event.empty_lines_above = empty_lines
|
||||
# add the following lines until the event says it's full or there is an empty line
|
||||
while !event.is_string_full_event(event_content):
|
||||
while not event.is_string_full_event(event_content):
|
||||
idx += 1
|
||||
text_lines_indexed[idx] = len(processed_events)
|
||||
if idx == len(lines):
|
||||
break
|
||||
|
||||
|
|
@ -132,20 +162,24 @@ func process() -> void:
|
|||
|
||||
event_content += "\n"+following_line_stripped
|
||||
|
||||
event._load_from_string(event_content)
|
||||
event.event_node_as_text = event_content
|
||||
event._load_from_string(event_content)
|
||||
|
||||
processed_events.append(event)
|
||||
prev_was_opener = event.can_contain_events
|
||||
empty_lines = 0
|
||||
|
||||
if !prev_indent.is_empty():
|
||||
if not prev_indent.is_empty():
|
||||
for i in range(len(prev_indent)):
|
||||
processed_events.append(end_event.duplicate())
|
||||
|
||||
events = processed_events
|
||||
events_processed = true
|
||||
|
||||
if indent_format.is_empty():
|
||||
indent_format = "\t"
|
||||
|
||||
|
||||
|
||||
## This method makes sure that all events in a timeline are correctly reset
|
||||
func clean() -> void:
|
||||
|
|
@ -164,3 +198,10 @@ func clean() -> void:
|
|||
for con_out in event.get_signal_connection_list(sig.name):
|
||||
con_out.signal.disconnect(con_out.callable)
|
||||
unreference()
|
||||
|
||||
|
||||
static func event_from_string(event_content:String, event_cache:Array) -> DialogicEvent:
|
||||
for i in event_cache:
|
||||
if i._test_event_string(event_content):
|
||||
return i.duplicate()
|
||||
return DialogicTextEvent.new()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue