feat: validates updated camera position against current camera limits; also some messaging updates
This commit is contained in:
committed by
Julian Murgia
parent
e0155c6097
commit
abb01b7f0b
@@ -24,6 +24,30 @@ func configure() -> ESCCommandArgumentDescriptor:
|
||||
)
|
||||
|
||||
|
||||
# Validate whether the given arguments match the command descriptor
|
||||
func validate(arguments: Array):
|
||||
if not .validate(arguments):
|
||||
return false
|
||||
|
||||
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)
|
||||
|
||||
if not camera_limit.has_point(new_pos):
|
||||
escoria.logger.error(
|
||||
self,
|
||||
"[%s]: invalid camera position. Camera cannot be moved to %s as this is outside the current camera limit %s."
|
||||
% [
|
||||
get_command_name(),
|
||||
new_pos,
|
||||
camera_limit
|
||||
]
|
||||
)
|
||||
return false
|
||||
|
||||
return true
|
||||
|
||||
|
||||
# Run the command
|
||||
func run(command_params: Array) -> int:
|
||||
(escoria.object_manager.get_object(escoria.object_manager.CAMERA).node as ESCCamera)\
|
||||
|
||||
@@ -53,6 +53,7 @@ func run(command_params: Array) -> int:
|
||||
)
|
||||
return ESCExecution.RC_OK
|
||||
|
||||
|
||||
# Validate whether the given arguments match the command descriptor
|
||||
func validate(arguments: Array):
|
||||
if not .validate(arguments):
|
||||
@@ -74,6 +75,24 @@ 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_limit.has_point(new_pos):
|
||||
escoria.logger.error(
|
||||
self,
|
||||
"[%s]: invalid camera position. Camera cannot be moved by %s to %s as this is outside the current camera limit %s."
|
||||
% [
|
||||
get_command_name(),
|
||||
shift_by,
|
||||
new_pos,
|
||||
camera_limit
|
||||
]
|
||||
)
|
||||
return false
|
||||
|
||||
return true
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user