From e4bb111cb9e49c2c184840f4c661b9c1f6345dca Mon Sep 17 00:00:00 2001 From: Duncan Brown Date: Fri, 29 Jul 2022 20:48:54 -0400 Subject: [PATCH] fix: changes camera target vs limit errors to warnings and makes sure they're in the right places --- .../core-scripts/esc/commands/camera_push.gd | 18 ++++++++++++++++++ .../esc/commands/camera_set_pos.gd | 2 +- .../core-scripts/esc/commands/camera_shift.gd | 2 +- addons/escoria-core/game/main.gd | 2 +- 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/addons/escoria-core/game/core-scripts/esc/commands/camera_push.gd b/addons/escoria-core/game/core-scripts/esc/commands/camera_push.gd index 30b0995e6..d3fcf5348 100644 --- a/addons/escoria-core/game/core-scripts/esc/commands/camera_push.gd +++ b/addons/escoria-core/game/core-scripts/esc/commands/camera_push.gd @@ -54,6 +54,24 @@ func validate(arguments: Array): % [get_command_name(), arguments[0]] ) return false + + var target_pos = (escoria.object_manager.get_object(arguments[0]).node as ESCItem).global_position + var camera: ESCCamera = escoria.object_manager.get_object(escoria.object_manager.CAMERA).node as ESCCamera + var camera_limit: Rect2 = Rect2(camera.limit_left, camera.limit_top, camera.limit_right - camera.limit_left, camera.limit_bottom - camera.limit_top) + + if not camera_limit.has_point(target_pos): + escoria.logger.warn( + self, + "[%s]: invalid camera position. Camera cannot be moved to %s at position %s as this is outside the current camera limit %s." + % [ + get_command_name(), + arguments[0], + target_pos, + camera_limit + ] + ) + return false + if not arguments[2] in SUPPORTED_TRANSITIONS: escoria.logger.error( self, diff --git a/addons/escoria-core/game/core-scripts/esc/commands/camera_set_pos.gd b/addons/escoria-core/game/core-scripts/esc/commands/camera_set_pos.gd index da9dd29b9..731c66b96 100644 --- a/addons/escoria-core/game/core-scripts/esc/commands/camera_set_pos.gd +++ b/addons/escoria-core/game/core-scripts/esc/commands/camera_set_pos.gd @@ -34,7 +34,7 @@ func validate(arguments: Array): var camera_limit: Rect2 = Rect2(camera.limit_left, camera.limit_top, camera.limit_right - camera.limit_left, camera.limit_bottom - camera.limit_top) if not camera_limit.has_point(new_pos): - escoria.logger.error( + escoria.logger.warn( self, "[%s]: invalid camera position. Camera cannot be moved to %s as this is outside the current camera limit %s." % [ diff --git a/addons/escoria-core/game/core-scripts/esc/commands/camera_shift.gd b/addons/escoria-core/game/core-scripts/esc/commands/camera_shift.gd index 6c121dee3..cb48a75df 100644 --- a/addons/escoria-core/game/core-scripts/esc/commands/camera_shift.gd +++ b/addons/escoria-core/game/core-scripts/esc/commands/camera_shift.gd @@ -81,7 +81,7 @@ func validate(arguments: Array): var new_pos: Vector2 = Vector2(camera.position.x + shift_by.x, camera.position.y + shift_by.y) if not camera_limit.has_point(new_pos): - escoria.logger.error( + escoria.logger.warn( self, "[%s]: invalid camera position. Camera cannot be moved by %s to %s as this is outside the current camera limit %s." % [ diff --git a/addons/escoria-core/game/main.gd b/addons/escoria-core/game/main.gd index 990e90ca4..0a72542df 100644 --- a/addons/escoria-core/game/main.gd +++ b/addons/escoria-core/game/main.gd @@ -164,7 +164,7 @@ func set_camera_limits(camera_limit_id: int = 0, scene: Node = current_scene) -> escoria.logger.info( self, - "Setting camera limits from scene " + area + "Setting camera limits from scene " + str(area) ) limits = ESCCameraLimits.new( area.position.x,