-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0d99e97
commit 3184548
Showing
5 changed files
with
74 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
** EPITECH PROJECT, 2022 | ||
** Bomberman | ||
** File description: | ||
** DrawText | ||
*/ | ||
|
||
#include "InputManager.hpp" | ||
#include "components/Controlable.hpp" | ||
#include "ecs/Storage.hpp" | ||
#include "ecs/World.hpp" | ||
#include "ecs/join.hpp" | ||
#include "ecs/system/SystemData.hpp" | ||
#include "game/Users.hpp" | ||
|
||
#include "logger/Logger.hpp" | ||
|
||
namespace game | ||
{ | ||
void InputManager::run(ecs::SystemData data) | ||
{ | ||
Users &users = data.getResource<Users>(); | ||
Users::ActionEvent event = users.getNextAction(); | ||
|
||
while (event.action != GameAction::NONE) { | ||
Logger::logger.log(Logger::Severity::Debug, [&](std::ostream &writer) { | ||
writer << "Action " << static_cast<size_t>(event.action) << " with value " << event.value | ||
<< " from user " << static_cast<size_t>(event.user); | ||
}); | ||
handleEvent(event, data); | ||
event = users.getNextAction(); | ||
} | ||
} | ||
|
||
void InputManager::handleEvent(const Users::ActionEvent &event, ecs::SystemData data) | ||
{ | ||
for (auto [controlable] : ecs::join(data.getStorage<Controlable>())) | ||
if (controlable.userId == event.user && controlable.callback && controlable.callback(event)) | ||
return; | ||
} | ||
} // namespace game |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
** EPITECH PROJECT, 2022 | ||
** Bomberman | ||
** File description: | ||
** InputManager | ||
*/ | ||
|
||
#ifndef GAME_SYSTEMS_INPUTMANAGER_HPP_ | ||
#define GAME_SYSTEMS_INPUTMANAGER_HPP_ | ||
|
||
#include "ecs/System.hpp" | ||
#include "game/Users.hpp" | ||
|
||
namespace game | ||
{ | ||
struct InputManager : public ecs::System { | ||
void run(ecs::SystemData data) override final; | ||
|
||
private: | ||
void handleEvent(const Users::ActionEvent &event, ecs::SystemData data); | ||
}; | ||
} // namespace game | ||
|
||
#endif /* !GAME_SYSTEMS_INPUTMANAGER_HPP_ */ |