From 7dcd1fdd675edaabd17d3d156d8787d73fd2baa9 Mon Sep 17 00:00:00 2001 From: Julian Murgia Date: Tue, 8 Nov 2022 13:02:39 +0100 Subject: [PATCH] Checked whether multiple enabled navpolys upon adding and deleting Impossible to check upon navpoly enabling without creating a new script/custom node. --- .../game/core-scripts/esc_terrain.gd | 36 +++++++++++++++---- 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/addons/escoria-core/game/core-scripts/esc_terrain.gd b/addons/escoria-core/game/core-scripts/esc_terrain.gd index 32f19e08..36c8ddaf 100644 --- a/addons/escoria-core/game/core-scripts/esc_terrain.gd +++ b/addons/escoria-core/game/core-scripts/esc_terrain.gd @@ -64,8 +64,36 @@ onready var logger = Logger.ESCLoggerFile.new() # Set a reference to the active navigation polygon, register to Escoria # and update the texture 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 + if node != null \ + and not is_exiting\ + and node is NavigationPolygonInstance \ + and node.enabled: + navigation_enabled_found = true + for n in get_children(): + if is_exiting and n == node: + continue if n is NavigationPolygonInstance and n.enabled: if navigation_enabled_found: if Engine.is_editor_hint(): @@ -80,15 +108,11 @@ func _ready(): "Multiple NavigationPolygonInstances enabled " + \ "at the same time." ) + return else: navigation_enabled_found = true 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 #