aboutsummaryrefslogtreecommitdiff
path: root/src/bootstrap.cpp
blob: 12f73692be9e5c557a106b01a7999107e52b9224 (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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#include "bootstrap.hpp"

// Interfaces
#include "interfaces/RLE_reader.hpp"
#include "interfaces/cell_helper.hpp"
#include "interfaces/component.hpp"
#include "interfaces/component_renderer.hpp"
#include "interfaces/cursor.hpp"
#include "interfaces/engine.hpp"
#include "interfaces/game.hpp"
#include "interfaces/generation_tracker.hpp"
#include "interfaces/input.hpp"
#include "interfaces/matrix.hpp"
#include "interfaces/scene.hpp"
#include "interfaces/status_manager.hpp"
#include "interfaces/statusline.hpp"

// Implementations
#include "engine/data/bounds.hpp"
#include "engine/data/vector2.hpp"
#include "engine/engine.hpp"
#include "engine/graphics/component_renderer.hpp"
#include "engine/graphics/matrix.hpp"
#include "engine/graphics/scene.hpp"
#include "engine/user/cursor.hpp"
#include "engine/user/input.hpp"
#include "game/RLE_reader.hpp"
#include "game/cell_helper.hpp"
#include "game/components/statusline.hpp"
#include "game/game.hpp"
#include "game/generation_tracker.hpp"
#include "game/status_manager.hpp"

#include <memory>

auto bootstrap() noexcept -> yacppdic::DIContainer
{
	auto di_container = yacppdic::DIContainer();

	di_container.bind<IUserInputObserver>().to<UserInputObserver>();
	di_container.bind<ICursorController>().to<CursorController>();
	di_container.bind<ICLIGameEngine>().to<CLIGameEngine>();
	di_container.bind<IStatusManager>().to<StatusManager>();
	di_container.bind<IScene>().to<Scene>();
	di_container.bind<IRLEReader>().to<RLEReader>();

	di_container.bind<IGameFactory>().to_factory(
		[&di_container](
			const std::shared_ptr<IScene> &scene,
			const std::shared_ptr<ICursorController> &cursor_controller,
			const std::shared_ptr<IUserInputObserver> &user_input_observer)
		{
			const auto statusline_factory = di_container.get<IStatusLineFactory>();

			std::shared_ptr<IStatusManager> status_manager =
				di_container.get<IStatusManager>();

			std::shared_ptr<IGenerationTracker> generation_tracker =
				di_container.get<IGenerationTrackerFactory>()(true);

			const auto cell_helper_factory = di_container.get<ICellHelperFactory<char>>();

			std::shared_ptr<IRLEReader> rle_reader = di_container.get<IRLEReader>();

			return std::make_unique<Game>(
				statusline_factory,
				scene,
				cursor_controller,
				generation_tracker,
				status_manager,
				user_input_observer,
				cell_helper_factory(*(scene->get_matrix())),
				rle_reader);
		});

	di_container.bind<IMatrixFactory<char>>().to_factory(
		[](const Bounds &bounds)
		{
			return std::make_unique<Matrix<char>>(bounds);
		});

	di_container.bind<IMatrixFactory<ComponentElement>>().to_factory(
		[](const Bounds &bounds)
		{
			return std::make_unique<Matrix<ComponentElement>>(bounds);
		});

	di_container.bind<IStatusLineFactory>().to_factory(
		[&di_container](const Bounds &size)
		{
			const auto matrix_factory =
				di_container.get<IMatrixFactory<IComponent::ComponentMatrix::Element>>();

			return std::make_unique<StatusLine>(matrix_factory(size));
		});

	di_container.bind<IGenerationTrackerFactory>().to_factory(
		[](bool is_paused)
		{
			return std::make_unique<GenerationTracker>(is_paused);
		});

	di_container.bind<ICellHelperFactory<char>>().to_factory(
		[](const IMatrix<char> &matrix)
		{
			return std::make_unique<CellHelper<char>>(matrix);
		});

	di_container.bind<IComponentRendererFactory>().to_factory(
		[](const std::shared_ptr<ICursorController> &cursor_controller)
		{
			return std::make_unique<ComponentRenderer>(cursor_controller);
		});

	return di_container;
}