aboutsummaryrefslogtreecommitdiff
path: root/src/commands/move_cursor.cpp
blob: 6bd8edaf52fb6254b642f65d9686e30707e6b6e0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include "move_cursor.hpp"

MoveCursorCommand::MoveCursorCommand(
	const Vector2 &direction,
	const std::shared_ptr<ICursorController> &cursor_controller,
	const std::shared_ptr<IScene> &scene) noexcept
	: _direction(direction), _cursor_controller(cursor_controller), _scene(scene)

{
}

void MoveCursorCommand::execute() noexcept
{
	constexpr int32_t amount = 1;

	const auto new_position =
		_cursor_controller->where().to_direction(_direction, amount);

	const auto scene_size = _scene->size();

	if (scene_size.validate_coords(new_position) != CoordsValidation::VALID)
	{
		return;
	}

	_cursor_controller->move_to(new_position);
}