mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-14 04:25:55 +00:00
Updated dialogic
This commit is contained in:
parent
1d11462073
commit
cbb82512ee
483 changed files with 5743 additions and 2177 deletions
|
|
@ -23,9 +23,10 @@ var shortcode_events := {}
|
|||
var custom_syntax_events := []
|
||||
var text_event: DialogicTextEvent = null
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
# Compile RegEx's
|
||||
completion_word_regex.compile("(?<s>(\\W)|^)(?<word>\\w*)\\x{FFFF}")
|
||||
completion_word_regex.compile(r"(?<s>(\W)|^)(?<word>[\w]*)\x{FFFF}")
|
||||
completion_shortcode_getter_regex.compile("\\[(?<code>\\w*)")
|
||||
completion_shortcode_param_getter_regex.compile("(?<param>\\w*)\\W*=\\s*\"?(\\w|\\s)*"+String.chr(0xFFFF))
|
||||
completion_shortcode_value_regex.compile(r'(\[|\s)[^\[\s=]*="(?<value>[^"$]*)'+String.chr(0xFFFF))
|
||||
|
|
@ -143,25 +144,9 @@ func request_code_completion(force:bool, text:CodeEdit, mode:=Modes.FULL_HIGHLIG
|
|||
|
||||
# suggest values
|
||||
elif symbol == '=' or symbol == '"':
|
||||
var current_parameter_gex := completion_shortcode_param_getter_regex.search(line)
|
||||
if !current_parameter_gex:
|
||||
text.update_code_completion_options(false)
|
||||
return
|
||||
|
||||
var current_parameter := current_parameter_gex.get_string('param')
|
||||
if !shortcode_events[code].get_shortcode_parameters().has(current_parameter):
|
||||
text.update_code_completion_options(false)
|
||||
return
|
||||
if !shortcode_events[code].get_shortcode_parameters()[current_parameter].has('suggestions'):
|
||||
if typeof(shortcode_events[code].get_shortcode_parameters()[current_parameter].default) == TYPE_BOOL:
|
||||
suggest_bool(text, shortcode_events[code].event_color.lerp(syntax_highlighter.normal_color, 0.3))
|
||||
elif len(word) > 0:
|
||||
text.add_code_completion_option(CodeEdit.KIND_VARIABLE, word, word, shortcode_events[code].event_color.lerp(syntax_highlighter.normal_color, 0.3), text.get_theme_icon("GuiScrollArrowRight", "EditorIcons"), '" ')
|
||||
text.update_code_completion_options(true)
|
||||
return
|
||||
|
||||
var suggestions: Dictionary = shortcode_events[code].get_shortcode_parameters()[current_parameter]['suggestions'].call()
|
||||
suggest_custom_suggestions(suggestions, text, shortcode_events[code].event_color.lerp(syntax_highlighter.normal_color, 0.3))
|
||||
suggest_shortcode_values(text, shortcode_events[code], line, word)
|
||||
text.update_code_completion_options(true)
|
||||
return
|
||||
|
||||
# Force update and showing of the popup
|
||||
text.update_code_completion_options(true)
|
||||
|
|
@ -172,7 +157,7 @@ func request_code_completion(force:bool, text:CodeEdit, mode:=Modes.FULL_HIGHLIG
|
|||
if mode == Modes.TEXT_EVENT_ONLY and !event is DialogicTextEvent:
|
||||
continue
|
||||
|
||||
if ! ' ' in line_part:
|
||||
if not ' ' in line_part:
|
||||
event._get_start_code_completion(self, text)
|
||||
|
||||
if event.is_valid_event(line):
|
||||
|
|
@ -182,19 +167,23 @@ func request_code_completion(force:bool, text:CodeEdit, mode:=Modes.FULL_HIGHLIG
|
|||
# Force update and showing of the popup
|
||||
text.update_code_completion_options(true)
|
||||
|
||||
# USEFUL FOR DEBUGGING
|
||||
#print(text.get_code_completion_options().map(func(x):return "{display_text}".format(x)))
|
||||
|
||||
|
||||
|
||||
# Helper that adds all characters as options
|
||||
func suggest_characters(text:CodeEdit, type := CodeEdit.KIND_MEMBER, text_event_start:=false) -> void:
|
||||
func suggest_characters(text:CodeEdit, type := CodeEdit.KIND_MEMBER, event:DialogicEvent=null) -> void:
|
||||
for character in DialogicResourceUtil.get_character_directory():
|
||||
var result: String = character
|
||||
if " " in character:
|
||||
result = '"'+character+'"'
|
||||
if text_event_start and load(DialogicResourceUtil.get_character_directory()[character]).portraits.is_empty():
|
||||
result += ':'
|
||||
if event and event is DialogicTextEvent and load(DialogicResourceUtil.get_character_directory()[character]).portraits.is_empty():
|
||||
result += ': '
|
||||
elif event and event is DialogicCharacterEvent:
|
||||
result += " "
|
||||
text.add_code_completion_option(type, character, result, syntax_highlighter.character_name_color, load("res://addons/dialogic/Editor/Images/Resources/character.svg"))
|
||||
|
||||
|
||||
# Helper that adds all timelines as options
|
||||
func suggest_timelines(text:CodeEdit, type := CodeEdit.KIND_MEMBER, color:=Color()) -> void:
|
||||
for timeline in DialogicResourceUtil.get_timeline_directory():
|
||||
|
|
@ -209,7 +198,7 @@ func suggest_labels(text:CodeEdit, timeline:String='', end:='', color:=Color())
|
|||
|
||||
# Helper that adds all portraits of a given character as options
|
||||
func suggest_portraits(text:CodeEdit, character_name:String, end_check:=')') -> void:
|
||||
if !character_name in DialogicResourceUtil.get_character_directory():
|
||||
if not character_name in DialogicResourceUtil.get_character_directory():
|
||||
return
|
||||
var character_resource: DialogicCharacter = load(DialogicResourceUtil.get_character_directory()[character_name])
|
||||
for portrait in character_resource.portraits:
|
||||
|
|
@ -238,10 +227,30 @@ func suggest_custom_suggestions(suggestions:Dictionary, text:CodeEdit, color:Col
|
|||
text.add_code_completion_option(CodeEdit.KIND_VARIABLE, key, str(suggestions[key].value), color, suggestions[key].get('icon', null), '" ')
|
||||
|
||||
|
||||
# Filters the list of all possible options, depending on what was typed
|
||||
# Purpose of the different Kinds is explained in [_request_code_completion]
|
||||
func suggest_shortcode_values(text:CodeEdit, event:DialogicEvent, line:String, word:String) -> void:
|
||||
var current_parameter_gex := completion_shortcode_param_getter_regex.search(line)
|
||||
if !current_parameter_gex:
|
||||
return
|
||||
|
||||
var current_parameter := current_parameter_gex.get_string('param')
|
||||
if !event.get_shortcode_parameters().has(current_parameter):
|
||||
return
|
||||
if !event.get_shortcode_parameters()[current_parameter].has('suggestions'):
|
||||
if typeof(event.get_shortcode_parameters()[current_parameter].default) == TYPE_BOOL:
|
||||
suggest_bool(text, event.event_color.lerp(syntax_highlighter.normal_color, 0.3))
|
||||
elif len(word) > 0:
|
||||
text.add_code_completion_option(CodeEdit.KIND_VARIABLE, word, word, event.event_color.lerp(syntax_highlighter.normal_color, 0.3), text.get_theme_icon("GuiScrollArrowRight", "EditorIcons"), '" ')
|
||||
return
|
||||
|
||||
var suggestions: Dictionary = event.get_shortcode_parameters()[current_parameter]['suggestions'].call()
|
||||
suggest_custom_suggestions(suggestions, text, event.event_color.lerp(syntax_highlighter.normal_color, 0.3))
|
||||
|
||||
|
||||
## Filters the list of all possible options, depending on what was typed
|
||||
## Purpose of the different Kinds is explained in [_request_code_completion]
|
||||
func filter_code_completion_candidates(candidates:Array, text:CodeEdit) -> Array:
|
||||
var valid_candidates := []
|
||||
|
||||
var current_word := get_code_completion_word(text)
|
||||
for candidate in candidates:
|
||||
if candidate.kind == text.KIND_PLAIN_TEXT:
|
||||
|
|
@ -289,7 +298,7 @@ func confirm_code_completion(replace:bool, text:CodeEdit) -> void:
|
|||
|
||||
if code_completion.has('default_value') and typeof(code_completion['default_value']) == TYPE_STRING:
|
||||
var next_letter := text.get_line(text.get_caret_line()).substr(text.get_caret_column(), len(code_completion['default_value']))
|
||||
if next_letter == code_completion['default_value'] or next_letter[0] == code_completion['default_value'][0]:
|
||||
if next_letter and (next_letter == code_completion['default_value'] or next_letter[0] == code_completion['default_value'][0]):
|
||||
text.set_caret_column(text.get_caret_column()+1)
|
||||
else:
|
||||
text.insert_text_at_caret(code_completion['default_value'])
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue