From 4a6f02b7aee156f480a5d28fbcf4bf738f261ffd Mon Sep 17 00:00:00 2001 From: Duncan Brown Date: Fri, 29 Jul 2022 22:27:18 -0400 Subject: [PATCH] fix: has_point() is exclusive of right-/bottom-edge, so we need to account for that --- .../game/core-scripts/esc/commands/camera_push.gd | 6 ++++-- .../game/core-scripts/esc/commands/camera_set_pos.gd | 4 +++- .../game/core-scripts/esc/commands/camera_shift.gd | 4 +++- 3 files changed, 10 insertions(+), 4 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 d3fcf534..4b89b690 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 @@ -55,11 +55,13 @@ func validate(arguments: Array): ) return false - var target_pos = (escoria.object_manager.get_object(arguments[0]).node as ESCItem).global_position + var target_pos = (escoria.object_manager.get_object(arguments[0]).node as ESCItem).global_position + Vector2.ONE var camera: ESCCamera = escoria.object_manager.get_object(escoria.object_manager.CAMERA).node as ESCCamera + # has_point() is exclusive of right-/bottom-edge + var camera_limit_to_test: Rect2 = Rect2(camera.limit_left, camera.limit_top, camera.limit_right - camera.limit_left + 1, camera.limit_bottom - camera.limit_top + 1) 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): + if not camera_limit_to_test.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." 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 731c66b9..0ba5c741 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 @@ -31,9 +31,11 @@ func validate(arguments: Array): var new_pos: Vector2 = Vector2(arguments[1], arguments[2]) var camera: ESCCamera = escoria.object_manager.get_object(escoria.object_manager.CAMERA).node as ESCCamera + # has_point() is exclusive of right-/bottom-edge + var camera_limit_to_test: Rect2 = Rect2(camera.limit_left, camera.limit_top, camera.limit_right - camera.limit_left + 1, camera.limit_bottom - camera.limit_top + 1) 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): + if not camera_limit_to_test.has_point(new_pos): 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 cb48a75d..797d972c 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 @@ -76,11 +76,13 @@ func validate(arguments: Array): return false var camera: ESCCamera = escoria.object_manager.get_object(escoria.object_manager.CAMERA).node as ESCCamera + # has_point() is exclusive of right-/bottom-edge + var camera_limit_to_test: Rect2 = Rect2(camera.limit_left, camera.limit_top, camera.limit_right - camera.limit_left + 1, camera.limit_bottom - camera.limit_top + 1) var camera_limit: Rect2 = Rect2(camera.limit_left, camera.limit_top, camera.limit_right - camera.limit_left, camera.limit_bottom - camera.limit_top) var shift_by: Vector2 = Vector2(arguments[0], arguments[1]) 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): + if not camera_limit_to_test.has_point(new_pos): 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."