Checked whether multiple enabled navpolys upon adding and deleting

Impossible to check upon navpoly enabling without creating a new script/custom node.
This commit is contained in:
Julian Murgia
2022-11-08 13:02:39 +01:00
committed by Duncan Brown
parent 056db75929
commit 7dcd1fdd67

View File

@@ -64,8 +64,36 @@ onready var logger = Logger.ESCLoggerFile.new()
# Set a reference to the active navigation polygon, register to Escoria # Set a reference to the active navigation polygon, register to Escoria
# and update the texture # and update the texture
func _ready(): func _ready():
connect("child_entered_tree", self, "_check_multiple_enabled_navpolys")
connect("child_exiting_tree", self, "_check_multiple_enabled_navpolys", [true])
_check_multiple_enabled_navpolys()
if !Engine.is_editor_hint():
escoria.room_terrain = self
_update_texture()
# Checks whether multiple navigation polygons are enabled.
# Shows a warning in the terminal if this happens.
# TODO: change this "simple" console log for an editor warning
# by overriding Node._get_configuration_warning() after we get rid of
# deprecated Navigation2D.
#
# #### Parameters
#
# - node: if this method is triggered by child_entered_tree or
# child_exited_tree signals, parameter is the added node.
func _check_multiple_enabled_navpolys(node: Node = null, is_exiting: bool = false) -> void:
var navigation_enabled_found = false var navigation_enabled_found = false
if node != null \
and not is_exiting\
and node is NavigationPolygonInstance \
and node.enabled:
navigation_enabled_found = true
for n in get_children(): for n in get_children():
if is_exiting and n == node:
continue
if n is NavigationPolygonInstance and n.enabled: if n is NavigationPolygonInstance and n.enabled:
if navigation_enabled_found: if navigation_enabled_found:
if Engine.is_editor_hint(): if Engine.is_editor_hint():
@@ -80,15 +108,11 @@ func _ready():
"Multiple NavigationPolygonInstances enabled " + \ "Multiple NavigationPolygonInstances enabled " + \
"at the same time." "at the same time."
) )
return
else: else:
navigation_enabled_found = true navigation_enabled_found = true
current_active_navigation_instance = n current_active_navigation_instance = n
if !Engine.is_editor_hint():
escoria.room_terrain = self
_update_texture()
# Return the Color of the lightmap pixel for the specified position # Return the Color of the lightmap pixel for the specified position
# #