chore: fills in missing docstrings; adds new base class for cameras to avoid duplication of viewport warnings.
This commit is contained in:
@@ -25,7 +25,7 @@
|
||||
# For more details see: https://docs.escoria-framework.org/camera
|
||||
#
|
||||
# @ESC
|
||||
extends ESCBaseCommand
|
||||
extends ESCCameraBaseCommand
|
||||
class_name CameraPushCommand
|
||||
|
||||
# The list of supported transitions as per the link mentioned above
|
||||
@@ -59,7 +59,7 @@ func validate(arguments: Array):
|
||||
var camera: ESCCamera = escoria.object_manager.get_object(escoria.object_manager.CAMERA).node as ESCCamera
|
||||
|
||||
if not camera.check_point_is_inside_viewport_limits(target_pos):
|
||||
_generate_viewport_warning(target_pos, camera)
|
||||
generate_viewport_warning(target_pos, camera)
|
||||
return false
|
||||
|
||||
if not arguments[2] in SUPPORTED_TRANSITIONS:
|
||||
@@ -100,27 +100,13 @@ func interrupt():
|
||||
)
|
||||
|
||||
|
||||
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()
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
# Gets the appropriate target position from the `ESCItem`, as used by the camera.
|
||||
#
|
||||
# #### Parameters
|
||||
#
|
||||
# - target_global_id: The `global_id` of the `ESCItem` to check.
|
||||
#
|
||||
# **Returns** the item's position based on its camera node.
|
||||
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
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
# For more details see: https://docs.escoria-framework.org/camera
|
||||
#
|
||||
# @ESC
|
||||
extends ESCBaseCommand
|
||||
extends ESCCameraBaseCommand
|
||||
class_name CameraSetLimitsCommand
|
||||
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
# For more details see: https://docs.escoria-framework.org/camera
|
||||
#
|
||||
# @ESC
|
||||
extends ESCBaseCommand
|
||||
extends ESCCameraBaseCommand
|
||||
class_name CameraSetPosCommand
|
||||
|
||||
|
||||
@@ -31,10 +31,9 @@ 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 = camera.get_camera_limit_rect()
|
||||
|
||||
if not camera.check_point_is_inside_viewport_limits(new_pos):
|
||||
_generate_viewport_warning(new_pos, camera)
|
||||
generate_viewport_warning(new_pos, camera)
|
||||
return false
|
||||
|
||||
return true
|
||||
@@ -56,24 +55,3 @@ 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()
|
||||
]
|
||||
)
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
# For more details see: https://docs.escoria-framework.org/camera
|
||||
#
|
||||
# @ESC
|
||||
extends ESCBaseCommand
|
||||
extends ESCCameraBaseCommand
|
||||
class_name CameraSetTargetCommand
|
||||
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
# For more details see: https://docs.escoria-framework.org/camera
|
||||
#
|
||||
# @ESC
|
||||
extends ESCBaseCommand
|
||||
extends ESCCameraBaseCommand
|
||||
class_name CameraSetZoomCommand
|
||||
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
# For more details see: https://docs.escoria-framework.org/camera
|
||||
#
|
||||
# @ESC
|
||||
extends ESCBaseCommand
|
||||
extends ESCCameraBaseCommand
|
||||
class_name CameraShiftCommand
|
||||
|
||||
# The list of supported transitions as per the link mentioned above
|
||||
@@ -76,12 +76,11 @@ func validate(arguments: Array):
|
||||
return false
|
||||
|
||||
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 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.check_point_is_inside_viewport_limits(new_pos):
|
||||
_generate_viewport_warning(new_pos, camera)
|
||||
generate_viewport_warning(new_pos, camera)
|
||||
return false
|
||||
|
||||
return true
|
||||
@@ -93,24 +92,3 @@ 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()
|
||||
]
|
||||
)
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
extends ESCBaseCommand
|
||||
class_name ESCCameraBaseCommand
|
||||
|
||||
|
||||
# Generaters a log entry when attempting to move the camera to an invalid position.
|
||||
#
|
||||
# #### Parameters
|
||||
#
|
||||
# - pos: The offending position.
|
||||
# - camera: The camera object that `pos` was checked against.
|
||||
func generate_viewport_warning(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(),
|
||||
pos.floor(),
|
||||
camera_limit,
|
||||
camera.get_current_valid_viewport_values_x(),
|
||||
camera.get_current_valid_viewport_values_y()
|
||||
]
|
||||
)
|
||||
Reference in New Issue
Block a user