fix: updates camera limit checking in commands to respect viewport limits (i.e. taking into account camera centre and half-screen limits); also updates warning message and no longer fails on limit violation.
This commit is contained in:
@@ -57,14 +57,12 @@ func validate(arguments: Array):
|
||||
|
||||
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_to_test.has_point(target_pos):
|
||||
if not camera.check_point_is_inside_viewport_limits(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."
|
||||
"[%s]: Invalid camera position. Moving camera by %s to %s will result in viewport being clamped to the current camera limit %s but its actual position not reflecting this."
|
||||
% [
|
||||
get_command_name(),
|
||||
arguments[0],
|
||||
|
||||
@@ -31,14 +31,12 @@ 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_to_test.has_point(new_pos):
|
||||
if not camera.check_point_is_inside_viewport_limits(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."
|
||||
"[%s]: Invalid camera position. Moving camera by %s to %s will result in viewport being clamped to the current camera limit %s but its actual position not reflecting this."
|
||||
% [
|
||||
get_command_name(),
|
||||
new_pos,
|
||||
|
||||
@@ -76,16 +76,14 @@ 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_to_test.has_point(new_pos):
|
||||
if not camera.check_point_is_inside_viewport_limits(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."
|
||||
"[%s]: Invalid camera position. Moving camera by %s to %s will result in viewport being clamped to the current camera limit %s but its actual position not reflecting this."
|
||||
% [
|
||||
get_command_name(),
|
||||
shift_by,
|
||||
@@ -93,7 +91,6 @@ func validate(arguments: Array):
|
||||
camera_limit
|
||||
]
|
||||
)
|
||||
return false
|
||||
|
||||
return true
|
||||
|
||||
|
||||
Reference in New Issue
Block a user