WIP: Iterating on warning message. Clamping set_target target in case of target being too close to limits.
This commit is contained in:
@@ -31,18 +31,10 @@ 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
|
||||
var camera_limit: Rect2 = Rect2(camera.limit_left, camera.limit_top, camera.limit_right - camera.limit_left, camera.limit_bottom - camera.limit_top)
|
||||
var camera_limit: Rect2 = _make_camera_limit_rect(camera)
|
||||
|
||||
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 viewport with current camera limit %s."
|
||||
% [
|
||||
get_command_name(),
|
||||
new_pos,
|
||||
camera_limit
|
||||
]
|
||||
)
|
||||
_generate_viewport_warning(new_pos, camera)
|
||||
return false
|
||||
|
||||
return true
|
||||
@@ -64,3 +56,28 @@ func interrupt():
|
||||
self,
|
||||
"[%s] interrupt() function not implemented." % get_command_name()
|
||||
)
|
||||
|
||||
|
||||
func _generate_viewport_warning(new_pos: Vector2, camera: ESCCamera) -> void:
|
||||
var camera_limit: Rect2 = _make_camera_limit_rect(camera)
|
||||
var message: String = \
|
||||
"""
|
||||
[%s]: Invalid camera position. Camera cannot be moved to %s as this is outside the viewport with current camera limit %s.
|
||||
Current valid ranges for positions are: x = %s inclusive; y = %s inclusive.
|
||||
"""
|
||||
|
||||
escoria.logger.warn(
|
||||
self,
|
||||
message
|
||||
% [
|
||||
get_command_name(),
|
||||
new_pos.floor(),
|
||||
camera_limit,
|
||||
camera.get_current_valid_viewport_values_x(),
|
||||
camera.get_current_valid_viewport_values_y()
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
func _make_camera_limit_rect(camera: ESCCamera) -> Rect2:
|
||||
return Rect2(camera.limit_left, camera.limit_top, camera.limit_right - camera.limit_left, camera.limit_bottom - camera.limit_top)
|
||||
|
||||
Reference in New Issue
Block a user