Skip to content

Commit

Permalink
fix: uses proper casting and updates validation checks
Browse files Browse the repository at this point in the history
  • Loading branch information
BHSDuncan authored and StraToN committed Jan 19, 2023
1 parent 53c900b commit 327b72f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
11 changes: 10 additions & 1 deletion addons/escoria-core/game/core-scripts/esc/commands/teleport.gd
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ func validate(arguments: Array):
% [get_command_name(), arguments[0]]
)
return false

if not (escoria.object_manager.get_object(arguments[0]).node as ESCItem):
escoria.logger.error(
self,
"[%s]: invalid first object. Object to teleport with global id %s must be of or derived from type ESCItem."
% [get_command_name(), arguments[0]]
)
return false

if not escoria.object_manager.has(arguments[1]):
escoria.logger.error(
self,
Expand All @@ -46,7 +55,7 @@ func validate(arguments: Array):

# Run the command
func run(command_params: Array) -> int:
(escoria.object_manager.get_object(command_params[0]).node as ESCPlayer)\
(escoria.object_manager.get_object(command_params[0]).node as ESCItem) \
.teleport(
escoria.object_manager.get_object(command_params[1]).node
)
Expand Down
15 changes: 13 additions & 2 deletions addons/escoria-core/game/core-scripts/esc/commands/teleport_pos.gd
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,24 @@ func validate(arguments: Array):
% [get_command_name(), arguments[0]]
)
return false

if not (escoria.object_manager.get_object(arguments[0]).node as ESCItem):
escoria.logger.error(
self,
"[%s]: invalid first object. Object to teleport with global id %s must be of or derived from type ESCItem."
% [get_command_name(), arguments[0]]
)
return false

return true


# Run the command
func run(command_params: Array) -> int:
escoria.object_manager.get_object(command_params[0]).node.teleport_to(
Vector2(int(command_params[1]), int(command_params[2]))
(escoria.object_manager.get_object(command_params[0]).node as ESCItem) \
.teleport_to(
Vector2(int(command_params[1]), int(command_params[2])
)
)
return ESCExecution.RC_OK

Expand Down

0 comments on commit 327b72f

Please sign in to comment.