fix: camera_push now validates against camera_node like ESCCamera.

This commit is contained in:
Duncan Brown
2022-10-28 12:15:19 -04:00
parent e807044e45
commit 3009fe1242
2 changed files with 29 additions and 13 deletions

View File

@@ -55,12 +55,11 @@ func validate(arguments: Array):
)
return false
var target_pos = (escoria.object_manager.get_object(arguments[0]).node as ESCItem).global_position + Vector2.ONE
var target_pos = _get_target_pos(arguments[0])
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.check_point_is_inside_viewport_limits(target_pos):
_generate_viewport_warning(target_pos - Vector2.ONE, camera)
_generate_viewport_warning(target_pos, camera)
return false
if not arguments[2] in SUPPORTED_TRANSITIONS:
@@ -120,3 +119,8 @@ func _generate_viewport_warning(new_pos: Vector2, camera: ESCCamera) -> void:
camera.get_current_valid_viewport_values_y()
]
)
func _get_target_pos(target_global_id: String) -> Vector2:
var target = escoria.object_manager.get_object(target_global_id).node as ESCItem
return target.get_camera_node().global_position

View File

@@ -81,16 +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.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 viewport with camera limit %s."
% [
get_command_name(),
shift_by,
new_pos,
camera_limit
]
)
_generate_viewport_warning(new_pos, camera)
return false
return true
@@ -102,3 +93,24 @@ 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 = camera.get_camera_limit_rect()
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()
]
)