effect_system.cpp 1.46 KB
Newer Older
1
2
#include "effect_system.hpp"

Florian Oetke's avatar
Florian Oetke committed
3
4
#include "../gameplay/combat_system.hpp"
#include "../gameplay/player_comp.hpp"
5
6
#include "../messages.hpp"

Florian Oetke's avatar
Florian Oetke committed
7
8
#include <mirrage/ecs/entity_manager.hpp>

9
10
11

namespace phase_shifter::ui {

Florian Oetke's avatar
Florian Oetke committed
12
13
	using namespace mirrage::util::unit_literals;

14
15
16
17
	Effect_system::Effect_system(mirrage::util::Message_bus& bus, mirrage::ecs::Entity_manager& ecs)
	  : _bus(bus), _mailbox(bus), _ecs(ecs)
	{
		_mailbox.subscribe_to([&](Enemy_killed_msg& e) {
Florian Oetke's avatar
Florian Oetke committed
18
19
			_bus.send<Play_sound_msg>("enemy_hit"_strid);

Florian Oetke's avatar
Florian Oetke committed
20
21
22
23
24
25
26
			auto entity = _ecs.entity_builder("enemy_tombstone")
			                      .rotation(glm::rotation(
			                              glm::vec3{1.f, 0.f, 0.f},
			                              glm::vec3(e.attack_direction.x, 0, -e.attack_direction.z)))
			                      .position(e.position)
			                      .create();

Florian Oetke's avatar
Florian Oetke committed
27
28
29
30
31
32
			_actions.defer(5_s, [&, entity] { _ecs.erase(entity); });
		});

		_mailbox.subscribe_to([&](gameplay::Damaged_msg& e) {
			_ecs.get(e.entity).process([&](auto& entity) {
				entity.process([&](gameplay::Player_comp&) { _bus.send<Play_sound_msg>("damaged"_strid); });
Florian Oetke's avatar
Florian Oetke committed
33
			});
34
35
36
		});

		_mailbox.subscribe_to([&](Win_msg& e) {
Florian Oetke's avatar
Florian Oetke committed
37
			_bus.send<Play_sound_msg>("win"_strid);
38
39
40
41
			// TODO
		});

		_mailbox.subscribe_to([&](Lose_msg& e) {
Florian Oetke's avatar
Florian Oetke committed
42
			_bus.send<Play_sound_msg>("gameover"_strid);
43
44
45
46
			// TODO
		});
	}

Florian Oetke's avatar
Florian Oetke committed
47
48
49
50
51
	void Effect_system::update(mirrage::util::Time dt)
	{
		_mailbox.update_subscriptions();
		_actions.update(dt);
	}
52
53

} // namespace phase_shifter::ui