Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More tricks for current scene detection #172

Merged
merged 2 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 46 additions & 6 deletions addons/panku_console/modules/variable_tracker/module.gd
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ const CURRENT_REGISTERED_TIP := "[tip] Node '%s' registered as current scene, yo
const CURRENT_REMOVED_TIP := "[tip] No current scene found, [b]%s[/b] keyword is no longer available."
const USER_AUTOLOADS_TIP := "[tip] Accessible user singleton modules: [b]%s[/b]"

var _raw_exceptions_string: String = ""
var _nodes_exception_regexp: RegEx

var _reverse_root_nodes_order: bool
var _current_scene_root:Node
var _user_singleton_files := []
var _tween_loop:Tween
Expand All @@ -23,13 +27,29 @@ var _loop_call_back:CallbackTweener

func init_module():
get_module_opt().tracking_delay = load_module_data("tracking_delay", DEFAULT_TRACKING_DELAY)
_reverse_root_nodes_order = load_module_data("use_last_as_current", true)
_raw_exceptions_string = load_module_data("root_node_exceptions", _raw_exceptions_string)

await core.get_tree().process_frame # not sure if it is necessary

update_exceptions_regexp()
_update_project_singleton_files()
_setup_scene_root_tracker()
_check_autoloads()


# Build root node exceptions regular expression
func update_exceptions_regexp() -> void:
if _raw_exceptions_string.is_empty():
_nodes_exception_regexp = RegEx.new() # not valid expression
return

_nodes_exception_regexp = RegEx.create_from_string(_raw_exceptions_string)

if not _nodes_exception_regexp.is_valid():
push_error("Can't parse '%s' expression for variable tracker" % _raw_exceptions_string)


# Parse project setting and collect and autoload files.
func _update_project_singleton_files() -> void:
_user_singleton_files.clear()
Expand Down Expand Up @@ -88,25 +108,45 @@ func _check_current_scene() -> void:

_current_scene_root = scene_root_found


## Find the root node of current active scene.
func get_scene_root() -> Node:
# Assuming current scene is the first node in tree that is not autoload singleton.
for node in core.get_tree().root.get_children():
for node in _get_valid_root_nodes():
if not _is_singleton(node):
return node

return null


# Get list of tree root nodes filtered and sorted according module settings
func _get_valid_root_nodes() -> Array:
var nodes: Array = core.get_tree().root.get_children().filter(_root_nodes_filter)

if _reverse_root_nodes_order:
nodes.reverse()

return nodes


# Filter function for tree root nodes
func _root_nodes_filter(node: Node) -> bool:
# skip panku plugin itself
if node.name == core.SingletonName:
return false

# skip user defined exceptions
if _nodes_exception_regexp.is_valid() and _nodes_exception_regexp.search(node.name):
return false

return true


# Find all autoload singletons and bind its to environment vars.
func _check_autoloads() -> void:
var _user_singleton_names := []

for node in core.get_tree().root.get_children():
if node.name == core.SingletonName:
# skip panku plugin itself
continue

for node in _get_valid_root_nodes():
if _is_singleton(node):
# register user singleton
_user_singleton_names.append(node.name)
Expand Down
24 changes: 23 additions & 1 deletion addons/panku_console/modules/variable_tracker/opt.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,31 @@ extends ModuleOptions

@export_group("variable_tracker")

@export var export_comment_use_last_as_current = (
"Use last non singleton node as current scene. "
+ "First node will be used if this option disabled."
)
@export var use_last_as_current: bool:
get:
return _module._reverse_root_nodes_order
set(value):
use_last_as_current = value
_module._reverse_root_nodes_order = value

@export var export_comment_root_node_exceptions = (
"Top level nodes which will be ignored by variable tracker. "
+ "Regular expressions can be used e.g. '(SignalBus|Game*)'."
)
@export var root_node_exceptions: String:
get:
return _module._raw_exceptions_string
set(value):
root_node_exceptions = value
_module._raw_exceptions_string = value
_module.update_exceptions_regexp()

@export var export_comment_tracking_delay = "Current scene checking interval."
@export_range(0.1, 2.0, 0.1) var tracking_delay := 0.5:
set(v):
tracking_delay = v
_module.change_tracking_delay(tracking_delay)
_module.change_tracking_delay(tracking_delay)