WIP: Correcting for switched camera limits. Updating validation for camera methods, although this is a WIP.
This commit is contained in:
@@ -62,7 +62,7 @@ func validate(arguments: Array):
|
|||||||
if not camera.check_point_is_inside_viewport_limits(target_pos):
|
if not camera.check_point_is_inside_viewport_limits(target_pos):
|
||||||
escoria.logger.warn(
|
escoria.logger.warn(
|
||||||
self,
|
self,
|
||||||
"[%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."
|
"[%s]: Invalid camera position. Camera cannot be moved to %s at position %s as this is outside the current viewport with camera limit %s."
|
||||||
% [
|
% [
|
||||||
get_command_name(),
|
get_command_name(),
|
||||||
arguments[0],
|
arguments[0],
|
||||||
|
|||||||
@@ -49,7 +49,10 @@ func validate(arguments: Array):
|
|||||||
|
|
||||||
# Run the command
|
# Run the command
|
||||||
func run(command_params: Array) -> int:
|
func run(command_params: Array) -> int:
|
||||||
|
var camera: ESCCamera = escoria.object_manager.get_object(escoria.object_manager.CAMERA).node as ESCCamera
|
||||||
|
camera.clamp_to_viewport_limits()
|
||||||
escoria.main.set_camera_limits(command_params[0])
|
escoria.main.set_camera_limits(command_params[0])
|
||||||
|
|
||||||
return ESCExecution.RC_OK
|
return ESCExecution.RC_OK
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ func validate(arguments: Array):
|
|||||||
if not camera.check_point_is_inside_viewport_limits(new_pos):
|
if not camera.check_point_is_inside_viewport_limits(new_pos):
|
||||||
escoria.logger.warn(
|
escoria.logger.warn(
|
||||||
self,
|
self,
|
||||||
"[%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."
|
"[%s]: Invalid camera position. Camera cannot be moved to %s as this is outside the viewport with current camera limit %s."
|
||||||
% [
|
% [
|
||||||
get_command_name(),
|
get_command_name(),
|
||||||
new_pos,
|
new_pos,
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ func validate(arguments: Array):
|
|||||||
if not camera.check_point_is_inside_viewport_limits(new_pos):
|
if not camera.check_point_is_inside_viewport_limits(new_pos):
|
||||||
escoria.logger.warn(
|
escoria.logger.warn(
|
||||||
self,
|
self,
|
||||||
"[%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."
|
"[%s]: Invalid camera position. Camera cannot be moved by %s to %s as this is outside the current viewport with camera limit %s."
|
||||||
% [
|
% [
|
||||||
get_command_name(),
|
get_command_name(),
|
||||||
shift_by,
|
shift_by,
|
||||||
@@ -91,6 +91,7 @@ func validate(arguments: Array):
|
|||||||
camera_limit
|
camera_limit
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
return false
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
|
||||||
|
|||||||
@@ -342,10 +342,10 @@ func _target_reached():
|
|||||||
# This is something of a hack until we decide on whether we implement an Escoria-specific camera
|
# This is something of a hack until we decide on whether we implement an Escoria-specific camera
|
||||||
# instead of relying on Camera2D.
|
# instead of relying on Camera2D.
|
||||||
func _convert_current_global_pos_for_disabled_drag_margin() -> void:
|
func _convert_current_global_pos_for_disabled_drag_margin() -> void:
|
||||||
var ret_position: Vector2 = self.global_position
|
|
||||||
var viewport_rect: Rect2 = get_viewport_rect()
|
var viewport_rect: Rect2 = get_viewport_rect()
|
||||||
|
|
||||||
var cur_camera_pos: Vector2 = self.get_camera_screen_center()
|
var cur_camera_pos: Vector2 = self.get_camera_screen_center()
|
||||||
|
var ret_position: Vector2 = cur_camera_pos
|
||||||
|
|
||||||
# If the current calculated centre of the camera/viewport is close enough to the set camera
|
# If the current calculated centre of the camera/viewport is close enough to the set camera
|
||||||
# limits (i.e. the centre is upto and including half the viewport's size to the limit being
|
# limits (i.e. the centre is upto and including half the viewport's size to the limit being
|
||||||
@@ -356,21 +356,51 @@ func _convert_current_global_pos_for_disabled_drag_margin() -> void:
|
|||||||
# to the value of the current calculated centre. This compensates for the switch when disabling
|
# to the value of the current calculated centre. This compensates for the switch when disabling
|
||||||
# drag margins.
|
# drag margins.
|
||||||
if cur_camera_pos.x - viewport_rect.size.x * 0.5 * zoom.x <= limit_left:
|
if cur_camera_pos.x - viewport_rect.size.x * 0.5 * zoom.x <= limit_left:
|
||||||
ret_position.x = cur_camera_pos.x
|
#ret_position.x = cur_camera_pos.x
|
||||||
|
ret_position.x = limit_left + viewport_rect.size.x * 0.5 * zoom.x
|
||||||
elif cur_camera_pos.x + viewport_rect.size.x * 0.5 * zoom.x >= limit_right:
|
elif cur_camera_pos.x + viewport_rect.size.x * 0.5 * zoom.x >= limit_right:
|
||||||
ret_position.x = cur_camera_pos.x
|
#ret_position.x = cur_camera_pos.x
|
||||||
elif cur_camera_pos.x < ret_position.x:
|
ret_position.x = limit_right - viewport_rect.size.x * 0.5 * zoom.x
|
||||||
ret_position.x = ret_position.x - (viewport_rect.size.x * 0.5 * zoom.x * drag_margin_right)
|
# elif cur_camera_pos.x < ret_position.x:
|
||||||
elif cur_camera_pos.x > ret_position.x:
|
# ret_position.x = ret_position.x - (viewport_rect.size.x * 0.5 * zoom.x * drag_margin_right)
|
||||||
ret_position.x = ret_position.x + (viewport_rect.size.x * 0.5 * zoom.x * drag_margin_left)
|
# elif cur_camera_pos.x > ret_position.x:
|
||||||
|
# ret_position.x = ret_position.x + (viewport_rect.size.x * 0.5 * zoom.x * drag_margin_left)
|
||||||
|
|
||||||
if cur_camera_pos.y - viewport_rect.size.y * 0.5 * zoom.y <= limit_bottom:
|
if cur_camera_pos.y - viewport_rect.size.y * 0.5 * zoom.y <= limit_top:
|
||||||
ret_position.y = cur_camera_pos.y
|
#ret_position.y = cur_camera_pos.y
|
||||||
elif cur_camera_pos.y + viewport_rect.size.y * 0.5 * zoom.y >= limit_top:
|
ret_position.y = limit_top + viewport_rect.size.y * 0.5 * zoom.y
|
||||||
ret_position.y = cur_camera_pos.y
|
elif cur_camera_pos.y + viewport_rect.size.y * 0.5 * zoom.y >= limit_bottom:
|
||||||
elif cur_camera_pos.y < ret_position.y:
|
#ret_position.y = cur_camera_pos.y
|
||||||
ret_position.y = ret_position.y - (viewport_rect.size.y * 0.5 * zoom.y * drag_margin_bottom)
|
ret_position.y = limit_bottom - viewport_rect.size.y * 0.5 * zoom.y
|
||||||
elif cur_camera_pos.y > ret_position.y:
|
|
||||||
ret_position.y = ret_position.y + (viewport_rect.size.y * 0.5 * zoom.y * drag_margin_top)
|
|
||||||
|
#elif cur_camera_pos.y < ret_position.y:
|
||||||
|
# ret_position.y = ret_position.y - (viewport_rect.size.y * 0.5 * zoom.y * drag_margin_bottom)
|
||||||
|
#elif cur_camera_pos.y > ret_position.y:
|
||||||
|
# ret_position.y = cur_camera_pos.y
|
||||||
|
#ret_position.y = ret_position.y + (viewport_rect.size.y * 0.5 * zoom.y * drag_margin_top)
|
||||||
|
|
||||||
|
self.global_position = ret_position
|
||||||
|
|
||||||
|
|
||||||
|
func clamp_to_viewport_limits() -> void:
|
||||||
|
var viewport_rect: Rect2 = get_viewport_rect()
|
||||||
|
|
||||||
|
var cur_camera_pos: Vector2 = self.get_camera_screen_center()
|
||||||
|
var ret_position: Vector2 = cur_camera_pos
|
||||||
|
|
||||||
|
if cur_camera_pos.x - viewport_rect.size.x * 0.5 * zoom.x <= limit_left:
|
||||||
|
#ret_position.x = limit_left + viewport_rect.size.x * 0.5 * zoom.x
|
||||||
|
ret_position.x = limit_left + viewport_rect.size.x * 0.5 * zoom.x * (1 + drag_margin_left)
|
||||||
|
elif cur_camera_pos.x + viewport_rect.size.x * 0.5 * zoom.x >= limit_right:
|
||||||
|
#ret_position.x = limits.limit_right - viewport_rect.size.x * 0.5 * zoom.x
|
||||||
|
ret_position.x = limit_right - viewport_rect.size.x * 0.5 * zoom.x * (1 + drag_margin_right)
|
||||||
|
|
||||||
|
if cur_camera_pos.y - viewport_rect.size.y * 0.5 * zoom.y <= limit_top:
|
||||||
|
#ret_position.y = limits.limit_top + viewport_rect.size.y * 0.5 * zoom.y
|
||||||
|
ret_position.y = limit_top + viewport_rect.size.y * 0.5 * zoom.y * (1 + drag_margin_top)
|
||||||
|
elif cur_camera_pos.y + viewport_rect.size.y * 0.5 * zoom.y >= limit_bottom:
|
||||||
|
#ret_position.y = limits.limit_bottom - viewport_rect.size.y * 0.5 * zoom.y - viewport_rect.size.y * 0.5 * zoom.y * drag_margin_bottom
|
||||||
|
ret_position.y = limit_bottom - viewport_rect.size.y * 0.5 * zoom.y * (1 + drag_margin_bottom)
|
||||||
|
|
||||||
self.global_position = ret_position
|
self.global_position = ret_position
|
||||||
|
|||||||
Reference in New Issue
Block a user