Format files using GDScript Toolkit

This commit is contained in:
Leroy Hopson 2023-01-21 11:34:39 +13:00
parent 9f269aec8c
commit e563a15ce2
No known key found for this signature in database
GPG key ID: D2747312A6DB51AA
52 changed files with 3459 additions and 2454 deletions

View file

@ -9,51 +9,59 @@ extends Window
panel_button = $Layout/CPanelButton/ShortcutButton,
}
func _ready():
for key in _ctrls:
var sc_button = _ctrls[key]
sc_button.connect('start_edit', _on_edit_start.bind(sc_button))
sc_button.connect('end_edit', _on_edit_end)
sc_button.connect("start_edit", _on_edit_start.bind(sc_button))
sc_button.connect("end_edit", _on_edit_end)
# show dialog when running scene from editor.
if(get_parent() == get_tree().root):
if get_parent() == get_tree().root:
popup_centered()
# ------------
# Events
# ------------
func _on_Hide_pressed():
hide()
func _on_edit_start(which):
for key in _ctrls:
var sc_button = _ctrls[key]
if(sc_button != which):
if sc_button != which:
sc_button.disable_set(true)
sc_button.disable_clear(true)
func _on_edit_end():
for key in _ctrls:
var sc_button = _ctrls[key]
sc_button.disable_set(false)
sc_button.disable_clear(false)
# ------------
# Public
# ------------
func get_run_all():
return _ctrls.run_all.get_shortcut()
func get_run_current_script():
return _ctrls.run_current_script.get_shortcut()
func get_run_current_inner():
return _ctrls.run_current_inner.get_shortcut()
func get_run_current_test():
return _ctrls.run_current_test.get_shortcut()
func get_panel_button():
return _ctrls.panel_button.get_shortcut()
@ -61,11 +69,11 @@ func get_panel_button():
func save_shortcuts(path):
var f = ConfigFile.new()
f.set_value('main', 'run_all', _ctrls.run_all.get_shortcut())
f.set_value('main', 'run_current_script', _ctrls.run_current_script.get_shortcut())
f.set_value('main', 'run_current_inner', _ctrls.run_current_inner.get_shortcut())
f.set_value('main', 'run_current_test', _ctrls.run_current_test.get_shortcut())
f.set_value('main', 'panel_button', _ctrls.panel_button.get_shortcut())
f.set_value("main", "run_all", _ctrls.run_all.get_shortcut())
f.set_value("main", "run_current_script", _ctrls.run_current_script.get_shortcut())
f.set_value("main", "run_current_inner", _ctrls.run_current_inner.get_shortcut())
f.set_value("main", "run_current_test", _ctrls.run_current_test.get_shortcut())
f.set_value("main", "panel_button", _ctrls.panel_button.get_shortcut())
f.save(path)
@ -75,8 +83,8 @@ func load_shortcuts(path):
var f = ConfigFile.new()
f.load(path)
_ctrls.run_all.set_shortcut(f.get_value('main', 'run_all', emptyShortcut))
_ctrls.run_current_script.set_shortcut(f.get_value('main', 'run_current_script', emptyShortcut))
_ctrls.run_current_inner.set_shortcut(f.get_value('main', 'run_current_inner', emptyShortcut))
_ctrls.run_current_test.set_shortcut(f.get_value('main', 'run_current_test', emptyShortcut))
_ctrls.panel_button.set_shortcut(f.get_value('main', 'panel_button', emptyShortcut))
_ctrls.run_all.set_shortcut(f.get_value("main", "run_all", emptyShortcut))
_ctrls.run_current_script.set_shortcut(f.get_value("main", "run_current_script", emptyShortcut))
_ctrls.run_current_inner.set_shortcut(f.get_value("main", "run_current_inner", emptyShortcut))
_ctrls.run_current_test.set_shortcut(f.get_value("main", "run_current_test", emptyShortcut))
_ctrls.panel_button.set_shortcut(f.get_value("main", "panel_button", emptyShortcut))

View file

@ -1,39 +1,37 @@
@tool
extends Control
const RUNNER_JSON_PATH = 'res://.gut_editor_config.json'
const RESULT_FILE = 'user://.gut_editor.bbcode'
const RESULT_JSON = 'user://.gut_editor.json'
const SHORTCUTS_PATH = 'res://.gut_editor_shortcuts.cfg'
const RUNNER_JSON_PATH = "res://.gut_editor_config.json"
const RESULT_FILE = "user://.gut_editor.bbcode"
const RESULT_JSON = "user://.gut_editor.json"
const SHORTCUTS_PATH = "res://.gut_editor_shortcuts.cfg"
var TestScript = load('res://addons/gut/test.gd')
var GutConfigGui = load('res://addons/gut/gui/gut_config_gui.gd')
var ScriptTextEditors = load('res://addons/gut/gui/script_text_editor_controls.gd')
var TestScript = load("res://addons/gut/test.gd")
var GutConfigGui = load("res://addons/gut/gui/gut_config_gui.gd")
var ScriptTextEditors = load("res://addons/gut/gui/script_text_editor_controls.gd")
var _interface = null;
var _is_running = false;
var _gut_config = load('res://addons/gut/gut_config.gd').new()
var _interface = null
var _is_running = false
var _gut_config = load("res://addons/gut/gut_config.gd").new()
var _gut_config_gui = null
var _gut_plugin = null
var _light_color = Color(0, 0, 0, .5)
var _panel_button = null
var _last_selected_path = null
@onready var _ctrls = {
output = $layout/RSplit/CResults/TabBar/OutputText.get_rich_text_edit(),
output_ctrl = $layout/RSplit/CResults/TabBar/OutputText,
run_button = $layout/ControlBar/RunAll,
shortcuts_button = $layout/ControlBar/Shortcuts,
settings_button = $layout/ControlBar/Settings,
run_results_button = $layout/ControlBar/RunResultsBtn,
output_button = $layout/ControlBar/OutputBtn,
settings = $layout/RSplit/sc/Settings,
shortcut_dialog = $BottomPanelShortcuts,
light = $layout/RSplit/CResults/ControlBar/Light3D,
results = {
results =
{
bar = $layout/RSplit/CResults/ControlBar,
passing = $layout/RSplit/CResults/ControlBar/Passing/value,
failing = $layout/RSplit/CResults/ControlBar/Failing/value,
@ -52,27 +50,37 @@ func _init():
func _ready():
_ctrls.results.bar.connect('draw', _on_results_bar_draw.bind(_ctrls.results.bar))
_ctrls.results.bar.connect("draw", _on_results_bar_draw.bind(_ctrls.results.bar))
hide_settings(!_ctrls.settings_button.button_pressed)
_gut_config_gui = GutConfigGui.new(_ctrls.settings)
_gut_config_gui.set_options(_gut_config.options)
_apply_options_to_controls()
_ctrls.shortcuts_button.icon = get_theme_icon('Shortcut', 'EditorIcons')
_ctrls.settings_button.icon = get_theme_icon('Tools', 'EditorIcons')
_ctrls.run_results_button.icon = get_theme_icon('AnimationTrackGroup', 'EditorIcons') # Tree
_ctrls.output_button.icon = get_theme_icon('Font', 'EditorIcons')
_ctrls.shortcuts_button.icon = get_theme_icon("Shortcut", "EditorIcons")
_ctrls.settings_button.icon = get_theme_icon("Tools", "EditorIcons")
_ctrls.run_results_button.icon = get_theme_icon("AnimationTrackGroup", "EditorIcons") # Tree
_ctrls.output_button.icon = get_theme_icon("Font", "EditorIcons")
_ctrls.run_results.set_output_control(_ctrls.output_ctrl)
_ctrls.run_results.set_font(
_gut_config.options.panel_options.font_name,
_gut_config.options.panel_options.font_size)
(
_ctrls
. run_results
. set_font(
_gut_config.options.panel_options.font_name, _gut_config.options.panel_options.font_size
)
)
var check_import = load('res://addons/gut/images/red.png')
if(check_import == null):
_ctrls.run_results.add_centered_text("GUT got some new images that are not imported yet. Please restart Godot.")
print('GUT got some new images that are not imported yet. Please restart Godot.')
var check_import = load("res://addons/gut/images/red.png")
if check_import == null:
(
_ctrls
. run_results
. add_centered_text(
"GUT got some new images that are not imported yet. Please restart Godot."
)
)
print("GUT got some new images that are not imported yet. Please restart Godot.")
else:
_ctrls.run_results.add_centered_text("Let's run some tests!")
@ -86,24 +94,30 @@ func _apply_options_to_controls():
_ctrls.output_ctrl.set_all_fonts(_gut_config.options.panel_options.font_name)
_ctrls.output_ctrl.set_font_size(_gut_config.options.panel_options.font_size)
_ctrls.run_results.set_font(
_gut_config.options.panel_options.font_name,
_gut_config.options.panel_options.font_size)
(
_ctrls
. run_results
. set_font(
_gut_config.options.panel_options.font_name, _gut_config.options.panel_options.font_size
)
)
_ctrls.run_results.set_show_orphans(!_gut_config.options.hide_orphans)
func _process(delta):
if(_is_running):
if(!_interface.is_playing_scene()):
if _is_running:
if !_interface.is_playing_scene():
_is_running = false
_ctrls.output_ctrl.add_text("\ndone")
load_result_output()
_gut_plugin.make_bottom_panel_item_visible(self)
# ---------------
# Private
# ---------------
func load_shortcuts():
_ctrls.shortcut_dialog.load_shortcuts(SHORTCUTS_PATH)
_apply_shortcuts()
@ -111,7 +125,7 @@ func load_shortcuts():
func _is_test_script(script):
var from = script.get_base_script()
while(from and from.resource_path != 'res://addons/gut/test.gd'):
while from and from.resource_path != "res://addons/gut/test.gd":
from = from.get_base_script()
return from != null
@ -121,7 +135,7 @@ func _show_errors(errs):
_ctrls.output_ctrl.clear()
var text = "Cannot run tests, you have a configuration error:\n"
for e in errs:
text += str('* ', e, "\n")
text += str("* ", e, "\n")
text += "Check your settings ----->"
_ctrls.output_ctrl.add_text(text)
hide_output_text(false)
@ -136,39 +150,40 @@ func _save_config():
_gut_config.options.panel_options.use_colors = _ctrls.output_ctrl.get_use_colors()
var w_result = _gut_config.write_options(RUNNER_JSON_PATH)
if(w_result != OK):
push_error(str('Could not write options to ', RUNNER_JSON_PATH, ': ', w_result))
return;
if w_result != OK:
push_error(str("Could not write options to ", RUNNER_JSON_PATH, ": ", w_result))
return
func _run_tests():
var issues = _gut_config_gui.get_config_issues()
if(issues.size() > 0):
if issues.size() > 0:
_show_errors(issues)
return
write_file(RESULT_FILE, 'Run in progress')
write_file(RESULT_FILE, "Run in progress")
_save_config()
_apply_options_to_controls()
_ctrls.output_ctrl.clear()
_ctrls.run_results.clear()
_ctrls.run_results.add_centered_text('Running...')
_ctrls.run_results.add_centered_text("Running...")
_interface.play_custom_scene('res://addons/gut/gui/GutRunner.tscn')
_interface.play_custom_scene("res://addons/gut/gui/GutRunner.tscn")
_is_running = true
_ctrls.output_ctrl.add_text('Running...')
_ctrls.output_ctrl.add_text("Running...")
func _apply_shortcuts():
_ctrls.run_button.shortcut = _ctrls.shortcut_dialog.get_run_all()
_ctrls.run_at_cursor.get_script_button().shortcut = \
_ctrls.shortcut_dialog.get_run_current_script()
_ctrls.run_at_cursor.get_inner_button().shortcut = \
_ctrls.shortcut_dialog.get_run_current_inner()
_ctrls.run_at_cursor.get_test_button().shortcut = \
_ctrls.shortcut_dialog.get_run_current_test()
_ctrls.run_at_cursor.get_script_button().shortcut = (
_ctrls . shortcut_dialog . get_run_current_script()
)
_ctrls.run_at_cursor.get_inner_button().shortcut = (
_ctrls . shortcut_dialog . get_run_current_inner()
)
_ctrls.run_at_cursor.get_test_button().shortcut = _ctrls.shortcut_dialog.get_run_current_test()
_panel_button.shortcut = _ctrls.shortcut_dialog.get_panel_button()
@ -194,7 +209,7 @@ func _on_Light_draw():
func _on_editor_script_changed(script):
if(script):
if script:
set_current_script(script)
@ -205,10 +220,12 @@ func _on_RunAll_pressed():
func _on_Shortcuts_pressed():
_ctrls.shortcut_dialog.popup_centered()
func _on_bottom_panel_shortcuts_visibility_changed():
_apply_shortcuts()
_ctrls.shortcut_dialog.save_shortcuts(SHORTCUTS_PATH)
func _on_RunAtCursor_run_tests(what):
_gut_config.options.selected = what.script
_gut_config.options.inner_class = what.inner_class
@ -228,7 +245,7 @@ func _on_OutputBtn_pressed():
func _on_RunResultsBtn_pressed():
hide_result_tree(! _ctrls.run_results_button.button_pressed)
hide_result_tree(!_ctrls.run_results_button.button_pressed)
_save_config()
@ -237,6 +254,7 @@ func _on_RunResultsBtn_pressed():
func _on_UseColors_pressed():
pass
# ---------------
# Public
# ---------------
@ -251,7 +269,7 @@ func hide_settings(should):
# collapse only collapses the first control, so we move
# settings around to be the collapsed one
if(should):
if should:
s_scroll.get_parent().move_child(s_scroll, 0)
else:
s_scroll.get_parent().move_child(s_scroll, 1)
@ -270,13 +288,13 @@ func load_result_output():
var summary = get_file_as_text(RESULT_JSON)
var test_json_conv = JSON.new()
if (test_json_conv.parse(summary) != OK):
if test_json_conv.parse(summary) != OK:
return
var results = test_json_conv.get_data()
_ctrls.run_results.load_json_results(results)
var summary_json = results['test_scripts']['props']
var summary_json = results["test_scripts"]["props"]
_ctrls.results.passing.text = str(summary_json.passing)
_ctrls.results.passing.get_parent().visible = true
@ -284,22 +302,24 @@ func load_result_output():
_ctrls.results.failing.get_parent().visible = true
_ctrls.results.pending.text = str(summary_json.pending)
_ctrls.results.pending.get_parent().visible = _ctrls.results.pending.text != '0'
_ctrls.results.pending.get_parent().visible = _ctrls.results.pending.text != "0"
_ctrls.results.errors.text = str(summary_json.errors)
_ctrls.results.errors.get_parent().visible = _ctrls.results.errors.text != '0'
_ctrls.results.errors.get_parent().visible = _ctrls.results.errors.text != "0"
_ctrls.results.warnings.text = str(summary_json.warnings)
_ctrls.results.warnings.get_parent().visible = _ctrls.results.warnings.text != '0'
_ctrls.results.warnings.get_parent().visible = _ctrls.results.warnings.text != "0"
_ctrls.results.orphans.text = str(summary_json.orphans)
_ctrls.results.orphans.get_parent().visible = _ctrls.results.orphans.text != '0' and !_gut_config.options.hide_orphans
_ctrls.results.orphans.get_parent().visible = (
_ctrls.results.orphans.text != "0" and !_gut_config.options.hide_orphans
)
if(summary_json.tests == 0):
if summary_json.tests == 0:
_light_color = Color(1, 0, 0, .75)
elif(summary_json.failures != 0):
elif summary_json.failures != 0:
_light_color = Color(1, 0, 0, .75)
elif(summary_json.pending != 0):
elif summary_json.pending != 0:
_light_color = Color(1, 1, 0, .75)
else:
_light_color = Color(0, 1, 0, .75)
@ -308,8 +328,8 @@ func load_result_output():
func set_current_script(script):
if(script):
if(_is_test_script(script)):
if script:
if _is_test_script(script):
var file = script.resource_path.get_file()
_last_selected_path = script.resource_path.get_file()
_ctrls.run_at_cursor.activate_for_script(script.resource_path)
@ -317,7 +337,11 @@ func set_current_script(script):
func set_interface(value):
_interface = value
_interface.get_script_editor().connect("editor_script_changed",Callable(self,'_on_editor_script_changed'))
(
_interface
. get_script_editor()
. connect("editor_script_changed", Callable(self, "_on_editor_script_changed"))
)
var ste = ScriptTextEditors.new(_interface.get_script_editor())
_ctrls.run_results.set_interface(_interface)
@ -333,14 +357,15 @@ func set_plugin(value):
func set_panel_button(value):
_panel_button = value
# ------------------------------------------------------------------------------
# Write a file.
# ------------------------------------------------------------------------------
func write_file(path, content):
var f = FileAccess.open(path, FileAccess.WRITE)
if(f != null):
if f != null:
f.store_string(content)
f = null;
f = null
return FileAccess.get_open_error()
@ -349,9 +374,9 @@ func write_file(path, content):
# Returns the text of a file or an empty string if the file could not be opened.
# ------------------------------------------------------------------------------
func get_file_as_text(path):
var to_return = ''
var to_return = ""
var f = FileAccess.open(path, FileAccess.READ)
if(f != null):
if f != null:
to_return = f.get_as_text()
f = null
return to_return
@ -361,7 +386,7 @@ func get_file_as_text(path):
# return if_null if value is null otherwise return value
# ------------------------------------------------------------------------------
func nvl(value, if_null):
if(value == null):
if value == null:
return if_null
else:
return value

View file

@ -1,15 +1,15 @@
extends Node2D
var Gut = load('res://addons/gut/gut.gd')
var ResultExporter = load('res://addons/gut/result_exporter.gd')
var GutConfig = load('res://addons/gut/gut_config.gd')
var Gut = load("res://addons/gut/gut.gd")
var ResultExporter = load("res://addons/gut/result_exporter.gd")
var GutConfig = load("res://addons/gut/gut_config.gd")
const RUNNER_JSON_PATH = 'res://.gut_editor_config.json'
const RESULT_FILE = 'user://.gut_editor.bbcode'
const RESULT_JSON = 'user://.gut_editor.json'
const RUNNER_JSON_PATH = "res://.gut_editor_config.json"
const RESULT_FILE = "user://.gut_editor.bbcode"
const RESULT_JSON = "user://.gut_editor.json"
var _gut_config = null
var _gut = null;
var _gut = null
var _wrote_results = false
# Flag for when this is being used at the command line. Otherwise it is
# assumed this is being used by the panel and being launched with
@ -21,55 +21,63 @@ var _cmdln_mode = false
var auto_run_tests = true
func _ready():
if(_gut_config == null):
if _gut_config == null:
_gut_config = GutConfig.new()
_gut_config.load_panel_options(RUNNER_JSON_PATH)
# The command line will call run_tests on its own. When used from the panel
# we have to kick off the tests ourselves b/c there's no way I know of to
# interact with the scene that was run via play_custom_scene.
if(!_cmdln_mode and auto_run_tests):
call_deferred('run_tests')
if !_cmdln_mode and auto_run_tests:
call_deferred("run_tests")
func run_tests(show_gui=true):
if(_gut == null):
func run_tests(show_gui = true):
if _gut == null:
get_gut()
_setup_gui(show_gui)
_gut.add_children_to = self
if(_gut_config.options.gut_on_top):
if _gut_config.options.gut_on_top:
_gut_layer.add_child(_gut)
else:
add_child(_gut)
if(!_cmdln_mode):
_gut.end_run.connect(_on_tests_finished.bind(_gut_config.options.should_exit, _gut_config.options.should_exit_on_success))
if !_cmdln_mode:
(
_gut
. end_run
. connect(
_on_tests_finished.bind(
_gut_config.options.should_exit, _gut_config.options.should_exit_on_success
)
)
)
_gut_config.config_gut(_gut)
var run_rest_of_scripts = _gut_config.options.unit_test_name == ''
var run_rest_of_scripts = _gut_config.options.unit_test_name == ""
_gut.test_scripts(run_rest_of_scripts)
func _setup_gui(show_gui):
if(show_gui):
if show_gui:
_gui.gut = _gut
var printer = _gut.logger.get_printer('gui')
var printer = _gut.logger.get_printer("gui")
printer.set_textbox(_gui.get_textbox())
else:
_gut.logger.disable_printer('gui', true)
_gut.logger.disable_printer("gui", true)
_gui.visible = false
var opts = _gut_config.options
_gui.set_font_size(opts.font_size)
_gui.set_font(opts.font_name)
if(opts.font_color != null and opts.font_color.is_valid_html_color()):
if opts.font_color != null and opts.font_color.is_valid_html_color():
_gui.set_default_font_color(Color(opts.font_color))
if(opts.background_color != null and opts.background_color.is_valid_html_color()):
if opts.background_color != null and opts.background_color.is_valid_html_color():
_gui.set_background_color(Color(opts.background_color))
#_tester.set_modulate(Color(1.0, 1.0, 1.0, min(1.0, float(opts.opacity) / 100)))
@ -79,16 +87,15 @@ func _setup_gui(show_gui):
# _tester.get_gui().compact_mode(true)
func _write_results():
var content = _gui.get_textbox().text #_gut.logger.get_gui_bbcode()
var content = _gui.get_textbox().text #_gut.logger.get_gui_bbcode()
var f = FileAccess.open(RESULT_FILE, FileAccess.WRITE)
if(f != null):
if f != null:
f.store_string(content)
f.close()
else:
push_error('Could not save bbcode, result = ', FileAccess.get_open_error())
push_error("Could not save bbcode, result = ", FileAccess.get_open_error())
var exporter = ResultExporter.new()
var f_result = exporter.write_json_file(_gut, RESULT_JSON)
@ -96,21 +103,21 @@ func _write_results():
func _exit_tree():
if(!_wrote_results and !_cmdln_mode):
if !_wrote_results and !_cmdln_mode:
_write_results()
func _on_tests_finished(should_exit, should_exit_on_success):
_write_results()
if(should_exit):
if should_exit:
get_tree().quit()
elif(should_exit_on_success and _gut.get_fail_count() == 0):
elif should_exit_on_success and _gut.get_fail_count() == 0:
get_tree().quit()
func get_gut():
if(_gut == null):
if _gut == null:
_gut = Gut.new()
return _gut

View file

@ -1,32 +1,37 @@
extends VBoxContainer
@tool
class SearchResults:
var L = 0
var C = 0
var positions = []
var te = null
var _last_term = ''
var _last_term = ""
func _search_te(text, start_position, flags=0):
func _search_te(text, start_position, flags = 0):
var start_pos = start_position
if(start_pos[L] < 0 or start_pos[L] > te.get_line_count()):
if start_pos[L] < 0 or start_pos[L] > te.get_line_count():
start_pos[L] = 0
if(start_pos[C] < 0):
if start_pos[C] < 0:
start_pos[L] = 0
var result = te.search(text, flags, start_pos[L], start_pos[C])
if(result.size() == 2 and result[L] == start_position[L] and
result[C] == start_position[C] and text == _last_term):
if(flags == TextEdit.SEARCH_BACKWARDS):
if (
result.size() == 2
and result[L] == start_position[L]
and result[C] == start_position[C]
and text == _last_term
):
if flags == TextEdit.SEARCH_BACKWARDS:
result[C] -= 1
else:
result[C] += 1
result = _search_te(text, result, flags)
L = result.y
C = result.x
elif(result.size() == 2):
elif result.size() == 2:
te.scroll_vertical = result[L]
te.select(result[L], result[C], result[L], result[C] + text.length())
te.set_caret_column(result[C])
@ -67,12 +72,13 @@ class SearchResults:
var last_pos = [0, 0]
positions.clear()
while(found):
while found:
c_pos = te.search(text, 0, c_pos[L], c_pos[C])
if(c_pos.size() > 0 and
(c_pos[L] > last_pos[L] or
(c_pos[L] == last_pos[L] and c_pos[C] > last_pos[C]))):
if (
c_pos.size() > 0
and (c_pos[L] > last_pos[L] or (c_pos[L] == last_pos[L] and c_pos[C] > last_pos[C]))
):
positions.append([c_pos[L], c_pos[C]])
c_pos[C] += 1
last_pos = c_pos
@ -80,42 +86,41 @@ class SearchResults:
found = false
@onready var _ctrls = {
output = $Output,
copy_button = $Toolbar/CopyButton,
use_colors = $Toolbar/UseColors,
clear_button = $Toolbar/ClearButton,
word_wrap = $Toolbar/WordWrap,
show_search = $Toolbar/ShowSearch,
search_bar = {
search_bar =
{
bar = $Search,
search_term = $Search/SearchTerm,
}
}
var _sr = SearchResults.new()
func _test_running_setup():
_ctrls.use_colors.text = 'use colors'
_ctrls.show_search.text = 'search'
_ctrls.word_wrap.text = 'ww'
_ctrls.use_colors.text = "use colors"
_ctrls.show_search.text = "search"
_ctrls.word_wrap.text = "ww"
set_all_fonts("CourierPrime")
set_font_size(20)
load_file('user://.gut_editor.bbcode')
load_file("user://.gut_editor.bbcode")
func _ready():
_sr.te = _ctrls.output
_ctrls.use_colors.icon = get_theme_icon('RichTextEffect', 'EditorIcons')
_ctrls.show_search.icon = get_theme_icon('Search', 'EditorIcons')
_ctrls.word_wrap.icon = get_theme_icon('Loop', 'EditorIcons')
_ctrls.use_colors.icon = get_theme_icon("RichTextEffect", "EditorIcons")
_ctrls.show_search.icon = get_theme_icon("Search", "EditorIcons")
_ctrls.word_wrap.icon = get_theme_icon("Loop", "EditorIcons")
_setup_colors()
if(get_parent() == get_tree().root):
if get_parent() == get_tree().root:
_test_running_setup()
@ -125,23 +130,23 @@ func _ready():
func _setup_colors():
_ctrls.output.clear()
var keywords = [
['Failed', Color.RED],
['Passed', Color.GREEN],
['Pending', Color.YELLOW],
['Orphans', Color.YELLOW],
['WARNING', Color.YELLOW],
['ERROR', Color.RED]
["Failed", Color.RED],
["Passed", Color.GREEN],
["Pending", Color.YELLOW],
["Orphans", Color.YELLOW],
["WARNING", Color.YELLOW],
["ERROR", Color.RED]
]
for keyword in keywords:
if (_ctrls.output.syntax_highlighter == null) :
if _ctrls.output.syntax_highlighter == null:
_ctrls.output.syntax_highlighter = CodeHighlighter.new()
_ctrls.output.syntax_highlighter.add_keyword_color(keyword[0], keyword[1])
var f_color = null
if (_ctrls.output.theme == null) :
if _ctrls.output.theme == null:
f_color = get_theme_color("font_color")
else :
else:
f_color = _ctrls.output.theme.font_color
_ctrls.output.add_theme_color_override("font_color_readonly", f_color)
_ctrls.output.add_theme_color_override("function_color", f_color)
@ -151,8 +156,8 @@ func _setup_colors():
func _set_font(font_name, custom_name):
var rtl = _ctrls.output
if(font_name == null):
rtl.set('custom_fonts/' + custom_name, null)
if font_name == null:
rtl.set("custom_fonts/" + custom_name, null)
else:
pass
# cuasing issues in 4.0
@ -184,7 +189,8 @@ func _on_ShowSearch_pressed():
func _on_SearchTerm_focus_entered():
_ctrls.search_bar.search_term.call_deferred('select_all')
_ctrls.search_bar.search_term.call_deferred("select_all")
func _on_SearchNext_pressed():
_sr.find_next(_ctrls.search_bar.search_term.text)
@ -195,63 +201,67 @@ func _on_SearchPrev_pressed():
func _on_SearchTerm_text_changed(new_text):
if(new_text == ''):
if new_text == "":
_ctrls.output.deselect()
else:
_sr.find_next(new_text)
func _on_SearchTerm_text_entered(new_text):
if(Input.is_physical_key_pressed(KEY_SHIFT)):
if Input.is_physical_key_pressed(KEY_SHIFT):
_sr.find_prev(new_text)
else:
_sr.find_next(new_text)
func _on_SearchTerm_gui_input(event):
if(event is InputEventKey and !event.pressed and event.scancode == KEY_ESCAPE):
if event is InputEventKey and !event.pressed and event.scancode == KEY_ESCAPE:
show_search(false)
func _on_WordWrap_pressed():
_ctrls.output.wrap_enabled = _ctrls.word_wrap.pressed
_ctrls.output.queue_redraw()
# ------------------
# Public
# ------------------
func show_search(should):
_ctrls.search_bar.bar.visible = should
if(should):
if should:
_ctrls.search_bar.search_term.grab_focus()
_ctrls.search_bar.search_term.select_all()
_ctrls.show_search.button_pressed = should
func search(text, start_pos, highlight=true):
func search(text, start_pos, highlight = true):
return _sr.find_next(text)
func copy_to_clipboard():
var selected = _ctrls.output.get_selection_text()
if(selected != ''):
if selected != "":
OS.clipboard = selected
else:
OS.clipboard = _ctrls.output.text
func clear():
_ctrls.output.text = ''
_ctrls.output.text = ""
func set_all_fonts(base_name):
if(base_name == 'Default'):
_set_font(null, 'font')
if base_name == "Default":
_set_font(null, "font")
# _set_font(null, 'normal_font')
# _set_font(null, 'bold_font')
# _set_font(null, 'italics_font')
# _set_font(null, 'bold_italics_font')
else:
_set_font(base_name + '-Regular', 'font')
_set_font(base_name + "-Regular", "font")
# _set_font(base_name + '-Regular', 'normal_font')
# _set_font(base_name + '-Bold', 'bold_font')
# _set_font(base_name + '-Italic', 'italics_font')
@ -260,8 +270,10 @@ func set_all_fonts(base_name):
func set_font_size(new_size):
var rtl = _ctrls.output
if(rtl.get('custom_fonts/font') != null):
rtl.get('custom_fonts/font').size = new_size
if rtl.get("custom_fonts/font") != null:
rtl.get("custom_fonts/font").size = new_size
# rtl.get('custom_fonts/bold_italics_font').size = new_size
# rtl.get('custom_fonts/bold_font').size = new_size
# rtl.get('custom_fonts/italics_font').size = new_size
@ -273,7 +285,7 @@ func set_use_colors(value):
func get_use_colors():
return false;
return false
func get_rich_text_edit():
@ -281,20 +293,19 @@ func get_rich_text_edit():
func load_file(path):
var f = FileAccess.open(path, FileAccess.READ)
if(f == null):
if f == null:
return
var t = f.get_as_text()
f.close()
_ctrls.output.text = t
_ctrls.output.scroll_vertical = _ctrls.output.get_line_count()
_ctrls.output.set_deferred('scroll_vertical', _ctrls.output.get_line_count())
_ctrls.output.set_deferred("scroll_vertical", _ctrls.output.get_line_count())
func add_text(text):
if(is_inside_tree()):
if is_inside_tree():
_ctrls.output.text += text

View file

@ -1,8 +1,7 @@
@tool
extends Control
var ScriptTextEditors = load('res://addons/gut/gui/script_text_editor_controls.gd')
var ScriptTextEditors = load("res://addons/gut/gui/script_text_editor_controls.gd")
@onready var _ctrls = {
btn_script = $HBox/BtnRunScript,
@ -28,17 +27,18 @@ func _ready():
_ctrls.btn_inner.visible = false
_ctrls.btn_method.visible = false
# ----------------
# Private
# ----------------
func _set_editor(which):
_last_line = -1
if(_cur_editor != null and _cur_editor.get_ref()):
_cur_editor.get_ref().disconnect('cursor_changed',Callable(self,'_on_cursor_changed'))
if _cur_editor != null and _cur_editor.get_ref():
_cur_editor.get_ref().disconnect("cursor_changed", Callable(self, "_on_cursor_changed"))
if(which != null):
if which != null:
_cur_editor = weakref(which)
which.connect('cursor_changed',Callable(self,'_on_cursor_changed'),[which])
which.connect("cursor_changed", Callable(self, "_on_cursor_changed"), [which])
_last_line = which.get_caret_line()
_last_info = _editors.get_line_info()
@ -58,20 +58,22 @@ func _update_buttons(info):
_ctrls.arrow_2.visible = info.test_method != null
_ctrls.btn_method.text = str(info.test_method)
_ctrls.btn_method.hint_tooltip = str("Run test ", info.test_method)
# The button's new size won't take effect until the next frame.
# This appears to be what was causing the button to not be clickable the
# first time.
call_deferred("_update_size")
func _update_size():
custom_minimum_size.x = _ctrls.btn_method.size.x + _ctrls.btn_method.rect_position.x
# ----------------
# Events
# ----------------
func _on_cursor_changed(which):
if(which.get_caret_line() != _last_line):
if which.get_caret_line() != _last_line:
_last_line = which.get_caret_line()
_last_info = _editors.get_line_info()
_update_buttons(_last_info)
@ -147,6 +149,3 @@ func search_current_editor_for_text(txt):
to_return = result[TextEdit.SEARCH_RESULT_LINE]
return to_return

View file

@ -2,22 +2,22 @@ extends Control
@tool
var _interface = null
var _utils = load('res://addons/gut/utils.gd').new()
var _utils = load("res://addons/gut/utils.gd").new()
var _hide_passing = true
var _font = null
var _font_size = null
var _root = null
var _max_icon_width = 10
var _editors = null # script_text_editor_controls.gd
var _editors = null # script_text_editor_controls.gd
var _show_orphans = true
var _output_control = null
const _col_1_bg_color = Color(0, 0, 0, .1)
var _icons = {
red = load('res://addons/gut/images/red.png'),
green = load('res://addons/gut/images/green.png'),
yellow = load('res://addons/gut/images/yellow.png'),
var _icons = {
red = load("res://addons/gut/images/red.png"),
green = load("res://addons/gut/images/green.png"),
yellow = load("res://addons/gut/images/yellow.png"),
}
signal search_for_text(text)
@ -26,7 +26,8 @@ signal search_for_text(text)
tree = $VBox/Output/Scroll/Tree,
lbl_overlay = $VBox/Output/OverlayMessage,
chk_hide_passing = $VBox/Toolbar/HidePassing,
toolbar = {
toolbar =
{
toolbar = $VBox/Toolbar,
collapse = $VBox/Toolbar/Collapse,
collapse_all = $VBox/Toolbar/CollapseAll,
@ -38,31 +39,32 @@ signal search_for_text(text)
}
}
func _test_running_setup():
_hide_passing = true
_show_orphans = true
var _gut_config = load('res://addons/gut/gut_config.gd').new()
_gut_config.load_panel_options('res://.gut_editor_config.json')
var _gut_config = load("res://addons/gut/gut_config.gd").new()
_gut_config.load_panel_options("res://.gut_editor_config.json")
set_font(
_gut_config.options.panel_options.font_name,
_gut_config.options.panel_options.font_size)
_gut_config.options.panel_options.font_name, _gut_config.options.panel_options.font_size
)
_ctrls.toolbar.hide_passing.text = '[hp]'
load_json_file('user://.gut_editor.json')
_ctrls.toolbar.hide_passing.text = "[hp]"
load_json_file("user://.gut_editor.json")
func _set_toolbutton_icon(btn, icon_name, text):
if(Engine.is_editor_hint()):
btn.icon = get_theme_icon(icon_name, 'EditorIcons')
if Engine.is_editor_hint():
btn.icon = get_theme_icon(icon_name, "EditorIcons")
else:
btn.text = str('[', text, ']')
btn.text = str("[", text, "]")
func _ready():
var f = null
if ($FontSampler.get_label_settings() == null) :
if $FontSampler.get_label_settings() == null:
f = get_theme_default_font()
else :
else:
f = $FontSampler.get_label_settings().font
var s_size = f.get_string_size("000 of 000 passed")
_root = _ctrls.tree.create_item()
@ -72,37 +74,49 @@ func _ready():
_ctrls.tree.set_column_expand(1, false)
_ctrls.tree.set_column_custom_minimum_width(1, s_size.x)
_set_toolbutton_icon(_ctrls.toolbar.collapse, 'CollapseTree', 'c')
_set_toolbutton_icon(_ctrls.toolbar.collapse_all, 'CollapseTree', 'c')
_set_toolbutton_icon(_ctrls.toolbar.expand, 'ExpandTree', 'e')
_set_toolbutton_icon(_ctrls.toolbar.expand_all, 'ExpandTree', 'e')
_set_toolbutton_icon(_ctrls.toolbar.show_script, 'Script', 'ss')
_set_toolbutton_icon(_ctrls.toolbar.scroll_output, 'Font', 'so')
_set_toolbutton_icon(_ctrls.toolbar.collapse, "CollapseTree", "c")
_set_toolbutton_icon(_ctrls.toolbar.collapse_all, "CollapseTree", "c")
_set_toolbutton_icon(_ctrls.toolbar.expand, "ExpandTree", "e")
_set_toolbutton_icon(_ctrls.toolbar.expand_all, "ExpandTree", "e")
_set_toolbutton_icon(_ctrls.toolbar.show_script, "Script", "ss")
_set_toolbutton_icon(_ctrls.toolbar.scroll_output, "Font", "so")
_ctrls.toolbar.hide_passing.set('custom_icons/checked', get_theme_icon('GuiVisibilityHidden', 'EditorIcons'))
_ctrls.toolbar.hide_passing.set('custom_icons/unchecked', get_theme_icon('GuiVisibilityVisible', 'EditorIcons'))
(
_ctrls
. toolbar
. hide_passing
. set("custom_icons/checked", get_theme_icon("GuiVisibilityHidden", "EditorIcons"))
)
(
_ctrls
. toolbar
. hide_passing
. set("custom_icons/unchecked", get_theme_icon("GuiVisibilityVisible", "EditorIcons"))
)
if(get_parent() == get_tree().root):
if get_parent() == get_tree().root:
_test_running_setup()
call_deferred('_update_min_width')
call_deferred("_update_min_width")
func _update_min_width():
custom_minimum_size.x = _ctrls.toolbar.toolbar.size.x
func _open_file(path, line_number):
if(_interface == null):
print('Too soon, wait a bit and try again.')
if _interface == null:
print("Too soon, wait a bit and try again.")
return
var r = load(path)
if(line_number != -1):
if line_number != -1:
_interface.edit_script(r, line_number)
else:
_interface.edit_script(r)
if(_ctrls.toolbar.show_script.pressed):
_interface.set_main_screen_editor('Script')
if _ctrls.toolbar.show_script.pressed:
_interface.set_main_screen_editor("Script")
func _add_script_tree_item(script_path, script_json):
@ -111,19 +125,20 @@ func _add_script_tree_item(script_path, script_json):
var item_text = script_path
var parent = _root
if(path_info.inner_class != ''):
if path_info.inner_class != "":
parent = _find_script_item_with_path(path_info.path)
item_text = path_info.inner_class
if(parent == null):
if parent == null:
parent = _add_script_tree_item(path_info.path, {})
var item = _ctrls.tree.create_item(parent)
item.set_text(0, item_text)
var meta = {
"type":"script",
"path":path_info.path,
"inner_class":path_info.inner_class,
"json":script_json}
"type": "script",
"path": path_info.path,
"inner_class": path_info.inner_class,
"json": script_json
}
item.set_metadata(0, meta)
item.set_custom_bg_color(1, _col_1_bg_color)
@ -135,7 +150,7 @@ func _add_assert_item(text, icon, parent_item):
var assert_item = _ctrls.tree.create_item(parent_item)
assert_item.set_icon_max_width(0, _max_icon_width)
assert_item.set_text(0, text)
assert_item.set_metadata(0, {"type":"assert"})
assert_item.set_metadata(0, {"type": "assert"})
assert_item.set_icon(0, icon)
assert_item.set_custom_bg_color(1, _col_1_bg_color)
@ -145,12 +160,12 @@ func _add_assert_item(text, icon, parent_item):
func _add_test_tree_item(test_name, test_json, script_item):
# print(' * adding test ', test_name)
var no_orphans_to_show = !_show_orphans or (_show_orphans and test_json.orphans == 0)
if(_hide_passing and test_json['status'] == 'pass' and no_orphans_to_show):
if _hide_passing and test_json["status"] == "pass" and no_orphans_to_show:
return
var item = _ctrls.tree.create_item(script_item)
var status = test_json['status']
var meta = {"type":"test", "json":test_json}
var status = test_json["status"]
var meta = {"type": "test", "json": test_json}
item.set_text(0, test_name)
item.set_text(1, status)
@ -160,40 +175,39 @@ func _add_test_tree_item(test_name, test_json, script_item):
item.set_metadata(0, meta)
item.set_icon_max_width(0, _max_icon_width)
var orphan_text = 'orphans'
if(test_json.orphans == 1):
orphan_text = 'orphan'
orphan_text = str(test_json.orphans, ' ', orphan_text)
var orphan_text = "orphans"
if test_json.orphans == 1:
orphan_text = "orphan"
orphan_text = str(test_json.orphans, " ", orphan_text)
if(status == 'pass' and no_orphans_to_show):
if status == "pass" and no_orphans_to_show:
item.set_icon(0, _icons.green)
elif(status == 'pass' and !no_orphans_to_show):
elif status == "pass" and !no_orphans_to_show:
item.set_icon(0, _icons.yellow)
item.set_text(1, orphan_text)
elif(status == 'fail'):
elif status == "fail":
item.set_icon(0, _icons.red)
else:
item.set_icon(0, _icons.yellow)
if(!_hide_passing):
if !_hide_passing:
for passing in test_json.passing:
_add_assert_item('pass: ' + passing, _icons.green, item)
_add_assert_item("pass: " + passing, _icons.green, item)
for failure in test_json.failing:
_add_assert_item("fail: " + failure.replace("\n", ''), _icons.red, item)
_add_assert_item("fail: " + failure.replace("\n", ""), _icons.red, item)
for pending in test_json.pending:
_add_assert_item("pending: " + pending.replace("\n", ''), _icons.yellow, item)
_add_assert_item("pending: " + pending.replace("\n", ""), _icons.yellow, item)
if(status != 'pass' and !no_orphans_to_show):
if status != "pass" and !no_orphans_to_show:
_add_assert_item(orphan_text, _icons.yellow, item)
return item
func _load_result_tree(j):
var scripts = j['test_scripts']['scripts']
var scripts = j["test_scripts"]["scripts"]
var script_keys = scripts.keys()
# if we made it here, the json is valid and we did something, otherwise the
# 'nothing to see here' should be visible.
@ -201,30 +215,30 @@ func _load_result_tree(j):
var _last_script_item = null
for key in script_keys:
var tests = scripts[key]['tests']
var tests = scripts[key]["tests"]
var test_keys = tests.keys()
var s_item = _add_script_tree_item(key, scripts[key])
var bad_count = 0
for test_key in test_keys:
var t_item = _add_test_tree_item(test_key, tests[test_key], s_item)
if(tests[test_key].status != 'pass'):
if tests[test_key].status != "pass":
bad_count += 1
elif(t_item != null):
elif t_item != null:
t_item.collapsed = true
# get_children returns the first child or null. its a dumb name.
if(s_item.get_children() == null):
if s_item.get_children() == null:
# var m = s_item.get_metadata(0)
# print('!! Deleting ', m.path, ' ', m.inner_class)
s_item.free()
else:
var total_text = str(test_keys.size(), ' passed')
var total_text = str(test_keys.size(), " passed")
# s_item.set_text_alignment(1, s_item.ALIGN_LEFT)
if(bad_count == 0):
if bad_count == 0:
s_item.collapsed = true
else:
total_text = str(test_keys.size() - bad_count, ' of ', test_keys.size(), ' passed')
total_text = str(test_keys.size() - bad_count, " of ", test_keys.size(), " passed")
s_item.set_text(1, total_text)
_free_childless_scripts()
@ -235,7 +249,7 @@ func _free_childless_scripts():
var items = _root.get_children()
for item in items:
var next_item = item.get_next()
if(item.get_children() == null):
if item.get_children() == null:
item.free()
item = next_item
@ -245,9 +259,9 @@ func _find_script_item_with_path(path):
var to_return = null
var idx = 0
while(idx < items.size() and to_return == null):
while idx < items.size() and to_return == null:
var item = items[idx]
if(item.get_metadata(0).path == path):
if item.get_metadata(0).path == path:
to_return = item
else:
idx += 1
@ -257,21 +271,18 @@ func _find_script_item_with_path(path):
func _get_line_number_from_assert_msg(msg):
var line = -1
if(msg.find('at line') > 0):
if msg.find("at line") > 0:
line = msg.split("at line")[-1].split(" ")[-1].to_int()
return line
func _get_path_and_inner_class_name_from_test_path(path):
var to_return = {
path = '',
inner_class = ''
}
var to_return = {path = "", inner_class = ""}
to_return.path = path
if !path.ends_with('.gd'):
var loc = path.find('.gd')
to_return.inner_class = path.split('.')[-1]
if !path.ends_with(".gd"):
var loc = path.find(".gd")
to_return.inner_class = path.split(".")[-1]
to_return.path = path.substr(0, loc + 3)
return to_return
@ -279,37 +290,37 @@ func _get_path_and_inner_class_name_from_test_path(path):
func _handle_tree_item_select(item, force_scroll):
var item_type = item.get_metadata(0).type
var path = '';
var line = -1;
var method_name = ''
var inner_class = ''
var path = ""
var line = -1
var method_name = ""
var inner_class = ""
if(item_type == 'test'):
if item_type == "test":
var s_item = item.get_parent()
path = s_item.get_metadata(0)['path']
inner_class = s_item.get_metadata(0)['inner_class']
path = s_item.get_metadata(0)["path"]
inner_class = s_item.get_metadata(0)["inner_class"]
line = -1
method_name = item.get_text(0)
elif(item_type == 'assert'):
elif item_type == "assert":
var s_item = item.get_parent().get_parent()
path = s_item.get_metadata(0)['path']
inner_class = s_item.get_metadata(0)['inner_class']
path = s_item.get_metadata(0)["path"]
inner_class = s_item.get_metadata(0)["inner_class"]
line = _get_line_number_from_assert_msg(item.get_text(0))
method_name = item.get_parent().get_text(0)
elif(item_type == 'script'):
path = item.get_metadata(0)['path']
if(item.get_parent() != _root):
elif item_type == "script":
path = item.get_metadata(0)["path"]
if item.get_parent() != _root:
inner_class = item.get_text(0)
line = -1
method_name = ''
method_name = ""
else:
return
var path_info = _get_path_and_inner_class_name_from_test_path(path)
if(force_scroll or _ctrls.toolbar.show_script.pressed):
if force_scroll or _ctrls.toolbar.show_script.pressed:
_goto_code(path, line, method_name, inner_class)
if(force_scroll or _ctrls.toolbar.scroll_output.pressed):
if force_scroll or _ctrls.toolbar.scroll_output.pressed:
_goto_output(path, method_name, inner_class)
@ -327,9 +338,9 @@ func _get_line_number_for_seq_search(search_strings, te):
var i = 0
var string_found = true
while(i < search_strings.size() and string_found):
while i < search_strings.size() and string_found:
result = te.search(search_strings[i], s_flags, line.y, line.x)
if(result.x != -1):
if result.x != -1:
line = result
else:
string_found = false
@ -338,55 +349,56 @@ func _get_line_number_for_seq_search(search_strings, te):
return line.y
func _goto_code(path, line, method_name='', inner_class =''):
if(_interface == null):
print('going to ', [path, line, method_name, inner_class])
func _goto_code(path, line, method_name = "", inner_class = ""):
if _interface == null:
print("going to ", [path, line, method_name, inner_class])
return
_open_file(path, line)
if(line == -1):
if line == -1:
var search_strings = []
if(inner_class != ''):
if inner_class != "":
search_strings.append(inner_class)
if(method_name != ''):
if method_name != "":
search_strings.append(method_name)
line = _get_line_number_for_seq_search(search_strings, _editors.get_current_text_edit())
if(line != -1):
if line != -1:
_interface.get_script_editor().goto_line(line)
func _goto_output(path, method_name, inner_class):
if(_output_control == null):
if _output_control == null:
return
var search_strings = [path]
if(inner_class != ''):
if inner_class != "":
search_strings.append(inner_class)
if(method_name != ''):
if method_name != "":
search_strings.append(method_name)
var line = _get_line_number_for_seq_search(search_strings, _output_control.get_rich_text_edit())
if(line != -1):
if line != -1:
_output_control.scroll_to_line(line)
func _show_all_passed():
if(_root.get_children() == null):
add_centered_text('Everything passed!')
if _root.get_children() == null:
add_centered_text("Everything passed!")
func _set_collapsed_on_all(item, value):
if(item == _root):
if item == _root:
var node = _root.get_children()
while(node != null):
node.call_recursive('set_collapsed', value)
while node != null:
node.call_recursive("set_collapsed", value)
node = node.get_next()
else:
item.call_recursive('set_collapsed', value)
item.call_recursive("set_collapsed", value)
# --------------
# Events
@ -396,16 +408,17 @@ func _on_Tree_item_selected():
var item = _ctrls.tree.get_selected()
_handle_tree_item_select(item, false)
# it just looks better if the left is always selected.
if(item.is_selected(1)):
if item.is_selected(1):
item.deselect(1)
item.select(0)
func _on_Tree_item_activated():
# force scroll
print('double clicked')
print("double clicked")
_handle_tree_item_select(_ctrls.tree.get_selected(), true)
func _on_Collapse_pressed():
collapse_selected()
@ -425,29 +438,39 @@ func _on_ExpandAll_pressed():
func _on_Hide_Passing_pressed():
_hide_passing = _ctrls.toolbar.hide_passing.button_pressed
# --------------
# Public
# --------------
func load_json_file(path):
var text = _utils.get_file_as_text(path)
if(text != ''):
if text != "":
var test_json_conv = JSON.new()
test_json_conv.parse(text)
var result = test_json_conv.get_data()
if(result.error != OK):
add_centered_text(str(path, " has invalid json in it \n",
'Error ', result.error, "@", result.error_line, "\n",
result.error_string))
if result.error != OK:
add_centered_text(
str(
path,
" has invalid json in it \n",
"Error ",
result.error,
"@",
result.error_line,
"\n",
result.error_string
)
)
return
load_json_results(result.result)
else:
add_centered_text(str(path, ' was empty or does not exist.'))
add_centered_text(str(path, " was empty or does not exist."))
func load_json_results(j):
clear()
add_centered_text('Nothing Here')
add_centered_text("Nothing Here")
_load_result_tree(j)
@ -456,7 +479,7 @@ func add_centered_text(t):
func clear_centered_text():
_ctrls.lbl_overlay.text = ''
_ctrls.lbl_overlay.text = ""
func clear():
@ -483,12 +506,13 @@ func expand_all():
func collapse_selected():
var item = _ctrls.tree.get_selected()
if(item != null):
if item != null:
_set_collapsed_on_all(item, true)
func expand_selected():
var item = _ctrls.tree.get_selected()
if(item != null):
if item != null:
_set_collapsed_on_all(item, false)
@ -498,6 +522,8 @@ func set_show_orphans(should):
func set_font(font_name, size):
pass
# var dyn_font = FontFile.new()
# var font_data = FontFile.new()
# font_data.font_path = 'res://addons/gut/fonts/' + font_name + '-Regular.ttf'

View file

@ -1,7 +1,6 @@
@tool
extends Control
@onready var _ctrls = {
shortcut_label = $Layout/lblShortcut,
set_button = $Layout/SetButton,
@ -14,7 +13,7 @@ signal changed
signal start_edit
signal end_edit
const NO_SHORTCUT = '<None>'
const NO_SHORTCUT = "<None>"
var _source_event = InputEventKey.new()
var _pre_edit_event = null
@ -22,28 +21,39 @@ var _key_disp = NO_SHORTCUT
var _modifier_keys = [KEY_ALT, KEY_CTRL, KEY_META, KEY_SHIFT]
# Called when the node enters the scene tree for the first time.
func _ready():
set_process_unhandled_key_input(false)
func _display_shortcut():
if(_key_disp == ''):
if _key_disp == "":
_key_disp = NO_SHORTCUT
_ctrls.shortcut_label.text = _key_disp
func _is_shift_only_modifier():
return _source_event.shift_pressed and \
!(_source_event.alt_pressed or _source_event.command_pressed or \
_source_event.ctrl_pressed or _source_event.meta_pressed) and \
!_is_modifier(_source_event.keycode)
return (
_source_event.shift_pressed
and !(
_source_event.alt_pressed
or _source_event.command_pressed
or _source_event.ctrl_pressed
or _source_event.meta_pressed
)
and !_is_modifier(_source_event.keycode)
)
func _has_modifier(event):
return event.alt_pressed or event.command_pressed or \
event.ctrl_pressed or event.meta_pressed or \
event.shift_pressed
return (
event.alt_pressed
or event.command_pressed
or event.ctrl_pressed
or event.meta_pressed
or event.shift_pressed
)
func _is_modifier(keycode):
@ -58,23 +68,24 @@ func _edit_mode(should):
_ctrls.cancel_button.visible = should
_ctrls.clear_button.visible = !should
if(should and to_s() == ''):
_ctrls.shortcut_label.text = 'press buttons'
if should and to_s() == "":
_ctrls.shortcut_label.text = "press buttons"
else:
_ctrls.shortcut_label.text = to_s()
if(should):
if should:
emit_signal("start_edit")
else:
emit_signal("end_edit")
# ---------------
# Events
# ---------------
func _unhandled_key_input(event):
if(event is InputEventKey):
if(event.pressed):
if(_has_modifier(event) and !_is_modifier(event.get_keycode_with_modifiers())):
if event is InputEventKey:
if event.pressed:
if _has_modifier(event) and !_is_modifier(event.get_keycode_with_modifiers()):
_source_event = event
_key_disp = OS.get_keycode_string(event.get_keycode_with_modifiers())
else:
@ -92,7 +103,7 @@ func _on_SetButton_pressed():
func _on_SaveButton_pressed():
_edit_mode(false)
_pre_edit_event = null
emit_signal('changed')
emit_signal("changed")
func _on_CancelButton_pressed():
@ -105,6 +116,7 @@ func _on_CancelButton_pressed():
func _on_ClearButton_pressed():
clear_shortcut()
# ---------------
# Public
# ---------------
@ -123,7 +135,7 @@ func get_shortcut():
func set_shortcut(sc):
if(sc == null or sc.events == null || sc.events.size() <= 0):
if sc == null or sc.events == null || sc.events.size() <= 0:
clear_shortcut()
else:
_source_event = sc.events[0]
@ -140,5 +152,6 @@ func clear_shortcut():
func disable_set(should):
_ctrls.set_button.disabled = should
func disable_clear(should):
_ctrls.clear_button.disabled = should

View file

@ -3,7 +3,7 @@
class DirectoryCtrl:
extends HBoxContainer
var text = '':
var text = "":
get:
return _txt_path.text
set(val):
@ -14,35 +14,33 @@ class DirectoryCtrl:
var _dialog = FileDialog.new()
func _init():
_btn_dir.text = '...'
_btn_dir.connect('pressed',Callable(self,'_on_dir_button_pressed'))
_btn_dir.text = "..."
_btn_dir.connect("pressed", Callable(self, "_on_dir_button_pressed"))
_txt_path.size_flags_horizontal = _txt_path.SIZE_EXPAND_FILL
_dialog.mode = _dialog.FILE_MODE_OPEN_DIR
_dialog.unresizable = false
_dialog.connect("dir_selected",Callable(self,'_on_selected'))
_dialog.connect("file_selected",Callable(self,'_on_selected'))
_dialog.connect("dir_selected", Callable(self, "_on_selected"))
_dialog.connect("file_selected", Callable(self, "_on_selected"))
_dialog.size = Vector2(1000, 700)
func _on_selected(path):
text = path
func _on_dir_button_pressed():
_dialog.current_dir = _txt_path.text
_dialog.popup_centered()
func _ready():
add_child(_txt_path)
add_child(_btn_dir)
add_child(_dialog)
func get_line_edit():
return _txt_path
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
class FileCtrl:
@ -51,17 +49,18 @@ class FileCtrl:
func _init():
_dialog.mode = _dialog.FILE_MODE_OPEN_FILE
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
class Vector2Ctrl:
extends VBoxContainer
var value = Vector2(-1, -1) :
var value = Vector2(-1, -1):
get:
return get_value()
set(val):
set_value(val)
var disabled = false :
var disabled = false:
get:
return get_disabled()
set(val):
@ -70,8 +69,8 @@ class Vector2Ctrl:
var y_spin = SpinBox.new()
func _init():
add_child(_make_one('x: ', x_spin))
add_child(_make_one('y: ', y_spin))
add_child(_make_one("x: ", x_spin))
add_child(_make_one("y: ", y_spin))
func _make_one(txt, spinner):
var hbox = HBoxContainer.new()
@ -85,7 +84,7 @@ class Vector2Ctrl:
return hbox
func set_value(v):
if(v != null):
if v != null:
x_spin.value = v[0]
y_spin.value = v[1]
@ -103,14 +102,13 @@ class Vector2Ctrl:
pass
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
var _base_container = null
var _base_control = null
const DIRS_TO_LIST = 6
var _cfg_ctrls = {}
var _avail_fonts = ['AnonymousPro', 'CourierPrime', 'LobsterTwo', 'Default']
var _avail_fonts = ["AnonymousPro", "CourierPrime", "LobsterTwo", "Default"]
func _init(cont):
@ -158,10 +156,10 @@ func _add_title(text):
# lbl.align = Label.ALIGNMENT_CENTER
_base_container.add_child(row)
row.connect('draw', _on_title_cell_draw.bind(row))
row.connect("draw", _on_title_cell_draw.bind(row))
func _add_number(key, value, disp_text, v_min, v_max, hint=''):
func _add_number(key, value, disp_text, v_min, v_max, hint = ""):
var value_ctrl = SpinBox.new()
value_ctrl.value = value
value_ctrl.size_flags_horizontal = value_ctrl.SIZE_EXPAND_FILL
@ -172,12 +170,12 @@ func _add_number(key, value, disp_text, v_min, v_max, hint=''):
_new_row(key, disp_text, value_ctrl, hint)
func _add_select(key, value, values, disp_text, hint=''):
func _add_select(key, value, values, disp_text, hint = ""):
var value_ctrl = OptionButton.new()
var select_idx = 0
for i in range(values.size()):
value_ctrl.add_item(values[i])
if(value == values[i]):
if value == values[i]:
select_idx = i
value_ctrl.selected = select_idx
value_ctrl.size_flags_horizontal = value_ctrl.SIZE_EXPAND_FILL
@ -185,7 +183,7 @@ func _add_select(key, value, values, disp_text, hint=''):
_new_row(key, disp_text, value_ctrl, hint)
func _add_value(key, value, disp_text, hint=''):
func _add_value(key, value, disp_text, hint = ""):
var value_ctrl = LineEdit.new()
value_ctrl.size_flags_horizontal = value_ctrl.SIZE_EXPAND_FILL
value_ctrl.text = value
@ -194,14 +192,14 @@ func _add_value(key, value, disp_text, hint=''):
_new_row(key, disp_text, value_ctrl, hint)
func _add_boolean(key, value, disp_text, hint=''):
func _add_boolean(key, value, disp_text, hint = ""):
var value_ctrl = CheckBox.new()
value_ctrl.button_pressed = value
_new_row(key, disp_text, value_ctrl, hint)
func _add_directory(key, value, disp_text, hint=''):
func _add_directory(key, value, disp_text, hint = ""):
var value_ctrl = DirectoryCtrl.new()
value_ctrl.size_flags_horizontal = value_ctrl.SIZE_EXPAND_FILL
value_ctrl.text = value
@ -210,7 +208,7 @@ func _add_directory(key, value, disp_text, hint=''):
_new_row(key, disp_text, value_ctrl, hint)
func _add_file(key, value, disp_text, hint=''):
func _add_file(key, value, disp_text, hint = ""):
var value_ctrl = FileCtrl.new()
value_ctrl.size_flags_horizontal = value_ctrl.SIZE_EXPAND_FILL
value_ctrl.text = value
@ -219,7 +217,7 @@ func _add_file(key, value, disp_text, hint=''):
_new_row(key, disp_text, value_ctrl, hint)
func _add_color(key, value, disp_text, hint=''):
func _add_color(key, value, disp_text, hint = ""):
var value_ctrl = ColorPickerButton.new()
value_ctrl.size_flags_horizontal = value_ctrl.SIZE_EXPAND_FILL
value_ctrl.color = value
@ -227,7 +225,7 @@ func _add_color(key, value, disp_text, hint=''):
_new_row(key, disp_text, value_ctrl, hint)
func _add_vector2(key, value, disp_text, hint=''):
func _add_vector2(key, value, disp_text, hint = ""):
var value_ctrl = Vector2Ctrl.new()
value_ctrl.size_flags_horizontal = value_ctrl.SIZE_EXPAND_FILL
value_ctrl.value = value
@ -235,6 +233,8 @@ func _add_vector2(key, value, disp_text, hint=''):
_wire_select_on_focus(value_ctrl.y_spin.get_line_edit())
_new_row(key, disp_text, value_ctrl, hint)
# -----------------------------
@ -243,17 +243,17 @@ func _add_vector2(key, value, disp_text, hint=''):
# ------------------
func _wire_select_on_focus(which):
pass
which.connect('focus_entered', _on_ctrl_focus_highlight.bind(which))
which.connect('focus_exited', _on_ctrl_focus_unhighlight.bind(which))
which.connect("focus_entered", _on_ctrl_focus_highlight.bind(which))
which.connect("focus_exited", _on_ctrl_focus_unhighlight.bind(which))
func _on_ctrl_focus_highlight(which):
if(which.has_method('select_all')):
which.call_deferred('select_all')
if which.has_method("select_all"):
which.call_deferred("select_all")
func _on_ctrl_focus_unhighlight(which):
if(which.has_method('select')):
if which.has_method("select"):
which.select(0, 0)
@ -269,17 +269,17 @@ func get_config_issues():
var has_directory = false
for i in range(DIRS_TO_LIST):
var key = str('directory_', i)
var key = str("directory_", i)
var path = _cfg_ctrls[key].text
if(path != null and path != ''):
if path != null and path != "":
has_directory = true
if(!DirAccess.dir_exists(path)):
to_return.append(str('Test directory ', path, ' does not exist.'))
if !DirAccess.dir_exists(path):
to_return.append(str("Test directory ", path, " does not exist."))
if(!has_directory):
to_return.append('You do not have any directories set.')
if !has_directory:
to_return.append("You do not have any directories set.")
if(!_cfg_ctrls['suffix'].text.ends_with('.gd')):
if !_cfg_ctrls["suffix"].text.ends_with(".gd"):
to_return.append("Script suffix must end in '.gd'")
return to_return
@ -287,90 +287,186 @@ func get_config_issues():
func set_options(options):
_add_title("Settings")
_add_number("log_level", options.log_level, "Log Level", 0, 3,
"Detail level for log messages.\n" + \
"\t0: Errors and failures only.\n" + \
"\t1: Adds all test names + warnings + info\n" + \
"\t2: Shows all asserts\n" + \
"\t3: Adds more stuff probably, maybe not.")
_add_boolean('ignore_pause', options.ignore_pause, 'Ignore Pause',
"Ignore calls to pause_before_teardown")
_add_boolean('hide_orphans', options.hide_orphans, 'Hide Orphans',
'Do not display orphan counts in output.')
_add_boolean('should_exit', options.should_exit, 'Exit on Finish',
"Exit when tests finished.")
_add_boolean('should_exit_on_success', options.should_exit_on_success, 'Exit on Success',
"Exit if there are no failures. Does nothing if 'Exit on Finish' is enabled.")
_add_number(
"log_level",
options.log_level,
"Log Level",
0,
3,
(
"Detail level for log messages.\n"
+ "\t0: Errors and failures only.\n"
+ "\t1: Adds all test names + warnings + info\n"
+ "\t2: Shows all asserts\n"
+ "\t3: Adds more stuff probably, maybe not."
)
)
_add_boolean(
"ignore_pause",
options.ignore_pause,
"Ignore Pause",
"Ignore calls to pause_before_teardown"
)
_add_boolean(
"hide_orphans",
options.hide_orphans,
"Hide Orphans",
"Do not display orphan counts in output."
)
_add_boolean("should_exit", options.should_exit, "Exit on Finish", "Exit when tests finished.")
_add_boolean(
"should_exit_on_success",
options.should_exit_on_success,
"Exit on Success",
"Exit if there are no failures. Does nothing if 'Exit on Finish' is enabled."
)
_add_title("Panel Output")
_add_select('output_font_name', options.panel_options.font_name, _avail_fonts, 'Font',
"The name of the font to use when running tests and in the output panel to the left.")
_add_number('output_font_size', options.panel_options.font_size, 'Font Size', 5, 100,
"The font size to use when running tests and in the output panel to the left.")
_add_select(
"output_font_name",
options.panel_options.font_name,
_avail_fonts,
"Font",
"The name of the font to use when running tests and in the output panel to the left."
)
_add_number(
"output_font_size",
options.panel_options.font_size,
"Font Size",
5,
100,
"The font size to use when running tests and in the output panel to the left."
)
_add_title("Runner Window")
_add_boolean(
"gut_on_top",
options.gut_on_top,
"On Top",
"The GUT Runner appears above children added during tests."
)
_add_number(
"opacity", options.opacity, "Opacity", 0, 100, "The opacity of GUT when tests are running."
)
_add_boolean(
"should_maximize",
options.should_maximize,
"Maximize",
"Maximize GUT when tests are being run."
)
_add_boolean(
"compact_mode",
options.compact_mode,
"Compact Mode",
"The runner will be in compact mode. This overrides Maximize."
)
_add_title('Runner Window')
_add_boolean("gut_on_top", options.gut_on_top, "On Top",
"The GUT Runner appears above children added during tests.")
_add_number('opacity', options.opacity, 'Opacity', 0, 100,
"The opacity of GUT when tests are running.")
_add_boolean('should_maximize', options.should_maximize, 'Maximize',
"Maximize GUT when tests are being run.")
_add_boolean('compact_mode', options.compact_mode, 'Compact Mode',
'The runner will be in compact mode. This overrides Maximize.')
_add_title("Runner Appearance")
_add_select(
"font_name",
options.font_name,
_avail_fonts,
"Font",
"The font to use for text output in the Gut Runner."
)
_add_number(
"font_size",
options.font_size,
"Font Size",
5,
100,
"The font size for text output in the Gut Runner."
)
_add_color(
"font_color",
options.font_color,
"Font Color",
"The font color for text output in the Gut Runner."
)
_add_color(
"background_color",
options.background_color,
"Background Color",
"The background color for text output in the Gut Runner."
)
_add_boolean(
"disable_colors",
options.disable_colors,
"Disable Formatting",
"Disable formatting and colors used in the Runner. Does not affect panel output."
)
_add_title('Runner Appearance')
_add_select('font_name', options.font_name, _avail_fonts, 'Font',
"The font to use for text output in the Gut Runner.")
_add_number('font_size', options.font_size, 'Font Size', 5, 100,
"The font size for text output in the Gut Runner.")
_add_color('font_color', options.font_color, 'Font Color',
"The font color for text output in the Gut Runner.")
_add_color('background_color', options.background_color, 'Background Color',
"The background color for text output in the Gut Runner.")
_add_boolean('disable_colors', options.disable_colors, 'Disable Formatting',
'Disable formatting and colors used in the Runner. Does not affect panel output.')
_add_title('Test Directories')
_add_boolean('include_subdirs', options.include_subdirs, 'Include Subdirs',
"Include subdirectories of the directories configured below.")
_add_title("Test Directories")
_add_boolean(
"include_subdirs",
options.include_subdirs,
"Include Subdirs",
"Include subdirectories of the directories configured below."
)
for i in range(DIRS_TO_LIST):
var value = ''
if(options.dirs.size() > i):
var value = ""
if options.dirs.size() > i:
value = options.dirs[i]
_add_directory(str('directory_', i), value, str('Directory ', i))
_add_directory(str("directory_", i), value, str("Directory ", i))
_add_title("XML Output")
_add_value("junit_xml_file", options.junit_xml_file, "Output Path3D",
"Path3D and filename where GUT should create a JUnit compliant XML file. " +
"This file will contain the results of the last test run. To avoid " +
"overriding the file use Include Timestamp.")
_add_boolean("junit_xml_timestamp", options.junit_xml_timestamp, "Include Timestamp",
"Include a timestamp in the filename so that each run gets its own xml file.")
_add_value(
"junit_xml_file",
options.junit_xml_file,
"Output Path3D",
(
"Path3D and filename where GUT should create a JUnit compliant XML file. "
+ "This file will contain the results of the last test run. To avoid "
+ "overriding the file use Include Timestamp."
)
)
_add_boolean(
"junit_xml_timestamp",
options.junit_xml_timestamp,
"Include Timestamp",
"Include a timestamp in the filename so that each run gets its own xml file."
)
_add_title("Hooks")
_add_file(
"pre_run_script",
options.pre_run_script,
"Pre-Run Hook",
"This script will be run by GUT before any tests are run."
)
_add_file(
"post_run_script",
options.post_run_script,
"Post-Run Hook",
"This script will be run by GUT after all tests are run."
)
_add_title('Hooks')
_add_file('pre_run_script', options.pre_run_script, 'Pre-Run Hook',
'This script will be run by GUT before any tests are run.')
_add_file('post_run_script', options.post_run_script, 'Post-Run Hook',
'This script will be run by GUT after all tests are run.')
_add_title('Misc')
_add_value('prefix', options.prefix, 'Script Prefix',
"The filename prefix for all test scripts.")
_add_value('suffix', options.suffix, 'Script Suffix',
"Script suffix, including .gd extension. For example '_foo.gd'.")
_add_number('paint_after', options.paint_after, 'Paint After', 0.0, 1.0,
"How long GUT will wait before pausing for 1 frame to paint the screen. 0 is never.")
_add_title("Misc")
_add_value(
"prefix", options.prefix, "Script Prefix", "The filename prefix for all test scripts."
)
_add_value(
"suffix",
options.suffix,
"Script Suffix",
"Script suffix, including .gd extension. For example '_foo.gd'."
)
_add_number(
"paint_after",
options.paint_after,
"Paint After",
0.0,
1.0,
"How long GUT will wait before pausing for 1 frame to paint the screen. 0 is never."
)
# since _add_number doesn't set step property, it will default to a step of
# 1 and cast values to int. Give it a .5 step and re-set the value.
_cfg_ctrls.paint_after.step = .05
_cfg_ctrls.paint_after.value = options.paint_after
print('paint after = ', options.paint_after)
print("paint after = ", options.paint_after)
func get_options(base_opts):
var to_return = base_opts.duplicate()
@ -383,13 +479,13 @@ func get_options(base_opts):
to_return.should_exit_on_success = _cfg_ctrls.should_exit_on_success.button_pressed
#Output
to_return.panel_options.font_name = _cfg_ctrls.output_font_name.get_item_text(
_cfg_ctrls.output_font_name.selected)
to_return.panel_options.font_name = (
_cfg_ctrls . output_font_name . get_item_text(_cfg_ctrls.output_font_name.selected)
)
to_return.panel_options.font_size = _cfg_ctrls.output_font_size.value
# Runner Appearance
to_return.font_name = _cfg_ctrls.font_name.get_item_text(
_cfg_ctrls.font_name.selected)
to_return.font_name = _cfg_ctrls.font_name.get_item_text(_cfg_ctrls.font_name.selected)
to_return.font_size = _cfg_ctrls.font_size.value
to_return.should_maximize = _cfg_ctrls.should_maximize.button_pressed
to_return.compact_mode = _cfg_ctrls.compact_mode.button_pressed
@ -400,14 +496,13 @@ func get_options(base_opts):
to_return.gut_on_top = _cfg_ctrls.gut_on_top.button_pressed
to_return.paint_after = _cfg_ctrls.paint_after.value
# Directories
to_return.include_subdirs = _cfg_ctrls.include_subdirs.button_pressed
var dirs = []
for i in range(DIRS_TO_LIST):
var key = str('directory_', i)
var key = str("directory_", i)
var val = _cfg_ctrls[key].text
if(val != '' and val != null):
if val != "" and val != null:
dirs.append(val)
to_return.dirs = dirs

View file

@ -11,57 +11,52 @@ class ScriptEditorControlRef:
_script_editor = weakref(script_edit)
_populate_controls()
func _populate_controls():
# who knows if the tree will change so get the first instance of each
# type of control we care about. Chances are there won't be more than
# one of these in the future, but their position in the tree may change.
_code_editor = weakref(_get_first_child_named('CodeTextEditor', _script_editor.get_ref()))
_code_editor = weakref(_get_first_child_named("CodeTextEditor", _script_editor.get_ref()))
_text_edit = weakref(_get_first_child_named("CodeEdit", _code_editor.get_ref()))
func _get_first_child_named(obj_name, parent_obj):
if(parent_obj == null):
if parent_obj == null:
return null
var kids = parent_obj.get_children()
var index = 0
var to_return = null
while(index < kids.size() and to_return == null):
if(str(kids[index]).find(str("[", obj_name)) != -1):
while index < kids.size() and to_return == null:
if str(kids[index]).find(str("[", obj_name)) != -1:
to_return = kids[index]
else:
to_return = _get_first_child_named(obj_name, kids[index])
if(to_return == null):
if to_return == null:
index += 1
return to_return
func get_script_text_edit():
return _script_editor.get_ref()
func get_text_edit():
# ScriptTextEditors that are loaded when the project is opened
# do not have their children populated yet. So if we may have to
# _populate_controls again if we don't have one.
if(_text_edit == null):
if _text_edit == null:
_populate_controls()
return _text_edit.get_ref()
func get_script_editor():
return _script_editor
func is_visible():
var to_return = false
if(_script_editor.get_ref()):
if _script_editor.get_ref():
to_return = _script_editor.get_ref().visible
return to_return
# ##############################################################################
#
# ##############################################################################
@ -74,8 +69,9 @@ var _script_editor = null
# and related controls at the time of the last refresh.
var _script_editor_controls = []
var _method_prefix = 'test_'
var _inner_class_prefix = 'Test'
var _method_prefix = "test_"
var _inner_class_prefix = "Test"
func _init(script_edit):
_script_editor = script_edit
@ -83,7 +79,7 @@ func _init(script_edit):
func _is_script_editor(obj):
return str(obj).find('[ScriptTextEditor') != -1
return str(obj).find("[ScriptTextEditor") != -1
# Find the first ScriptTextEditor and then get its parent. Done this way
@ -91,36 +87,37 @@ func _is_script_editor(obj):
# future proofed.
func _find_script_editors_parent():
var _first_editor = _get_first_child_of_type_name("ScriptTextEditor", _script_editor)
if(_first_editor != null):
if _first_editor != null:
_script_editors_parent = _first_editor.get_parent()
func _populate_editors():
if(_script_editors_parent == null):
if _script_editors_parent == null:
return
_script_editor_controls.clear()
for child in _script_editors_parent.get_children():
if(_is_script_editor(child)):
if _is_script_editor(child):
var ref = ScriptEditorControlRef.new(child)
_script_editor_controls.append(ref)
# Yes, this is the same as the one above but with a different name. This was
# easier than trying to find a place where it could be used by both.
func _get_first_child_of_type_name(obj_name, parent_obj):
if(parent_obj == null):
if parent_obj == null:
return null
var kids = parent_obj.get_children()
var index = 0
var to_return = null
while(index < kids.size() and to_return == null):
if(str(kids[index]).find(str("[", obj_name)) != -1):
while index < kids.size() and to_return == null:
if str(kids[index]).find(str("[", obj_name)) != -1:
to_return = kids[index]
else:
to_return = _get_first_child_of_type_name(obj_name, kids[index])
if(to_return == null):
if to_return == null:
index += 1
return to_return
@ -139,11 +136,12 @@ func _get_class_name_from_line(text):
var the_name = right.rstrip(":")
return the_name
func refresh():
if(_script_editors_parent == null):
if _script_editors_parent == null:
_find_script_editors_parent()
if(_script_editors_parent != null):
if _script_editors_parent != null:
_populate_editors()
@ -151,14 +149,14 @@ func get_current_text_edit():
var cur_script_editor = null
var idx = 0
while(idx < _script_editor_controls.size() and cur_script_editor == null):
if(_script_editor_controls[idx].is_visible()):
while idx < _script_editor_controls.size() and cur_script_editor == null:
if _script_editor_controls[idx].is_visible():
cur_script_editor = _script_editor_controls[idx]
else:
idx += 1
var to_return = null
if(cur_script_editor != null):
if cur_script_editor != null:
to_return = cur_script_editor.get_text_edit()
return to_return
@ -174,36 +172,32 @@ func get_script_editor_controls():
func get_line_info():
var editor = get_current_text_edit()
if(editor == null):
if editor == null:
return
var info = {
script = null,
inner_class = null,
test_method = null
}
var info = {script = null, inner_class = null, test_method = null}
var line = editor.get_caret_line()
var done_func = false
var done_inner = false
while(line > 0 and (!done_func or !done_inner)):
if(editor.can_fold_line(line)):
while line > 0 and (!done_func or !done_inner):
if editor.can_fold_line(line):
var text = editor.get_line(line)
var strip_text = text.strip_edges(true, false) # only left
var strip_text = text.strip_edges(true, false) # only left
if(!done_func and strip_text.begins_with("func ")):
if !done_func and strip_text.begins_with("func "):
var func_name = _get_func_name_from_line(text)
if(func_name.begins_with(_method_prefix)):
if func_name.begins_with(_method_prefix):
info.test_method = func_name
done_func = true
# If the func line is left justified then there won't be any
# inner classes above it.
if(strip_text == text):
if strip_text == text:
done_inner = true
if(!done_inner and strip_text.begins_with("class")):
if !done_inner and strip_text.begins_with("class"):
var inner_name = _get_class_name_from_line(text)
if(inner_name.begins_with(_inner_class_prefix)):
if inner_name.begins_with(_inner_class_prefix):
info.inner_class = inner_name
done_inner = true
# if we found an inner class then we are already past