Skip to content

Commit

Permalink
ECS: Add current progres
Browse files Browse the repository at this point in the history
  • Loading branch information
guillaumeAbel committed Nov 3, 2023
1 parent 4f2e897 commit ed15d90
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 39 deletions.
14 changes: 7 additions & 7 deletions src/Client/Systems/Events/EventsSystems.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,11 +205,11 @@ namespace Systems {
{
std::lock_guard<std::mutex> lock(Registry::getInstance().mutex);
Registry &registry = Registry::getInstance();
Registry::components<Raylib::Music> arrMusics = registry.getComponents<Raylib::Music>();
auto &arrMusics = registry.getComponents<Raylib::MusicShared>();

for (auto &music : arrMusics) {
if (music.getPath() == musicPath && Raylib::KeyboardInput::isKeyPressed(Raylib::KeyboardKey::KB_M)) {
music.setNeedToPlay(true);
if (music->getPath() == musicPath && Raylib::KeyboardInput::isKeyPressed(Raylib::KeyboardKey::KB_M)) {
music->setNeedToPlay(true);
}
}
}
Expand All @@ -226,13 +226,13 @@ namespace Systems {
auto soundEffectShoot3 = Raylib::Sound::fromFile(soundPathShoot3, soundVolume);

Registry::getInstance().addEntity();
Registry::getInstance().getComponents<Raylib::Music>().insertBack(*music);
Registry::getInstance().getComponents<Raylib::MusicShared>().insertBack(music);
Registry::getInstance().addEntity();
Registry::getInstance().getComponents<Raylib::Sound>().insertBack(*soundEffectShoot);
Registry::getInstance().getComponents<Raylib::SoundShared>().insertBack(soundEffectShoot);
Registry::getInstance().addEntity();
Registry::getInstance().getComponents<Raylib::Sound>().insertBack(*soundEffectShoot2);
Registry::getInstance().getComponents<Raylib::SoundShared>().insertBack(soundEffectShoot2);
Registry::getInstance().addEntity();
Registry::getInstance().getComponents<Raylib::Sound>().insertBack(*soundEffectShoot3);
Registry::getInstance().getComponents<Raylib::SoundShared>().insertBack(soundEffectShoot3);
SystemManagersDirector::getInstance().getSystemManager(managerId).removeSystem(systemId);
}

Expand Down
1 change: 1 addition & 0 deletions src/Client/Systems/Menu/ButtonCallbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "B-luga-physics/ECSCustomTypes.hpp"
#include "B-luga/Logger.hpp"
#include "B-luga/SceneManager.hpp"
#include "B-luga-graphics/GraphicsCustomTypes.hpp"
#include "ButtonCallbacks.hpp"
#include "NitworkClient.hpp"

Expand Down
10 changes: 5 additions & 5 deletions src/Client/Systems/Menu/Menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ namespace Menu {
std::string name = Json::isDataExist(elem, "name")
? Json::getInstance().getDataFromJson<std::string>(elem, "name")
: "";
Raylib::Text textComp(text);
auto textComp = Raylib::Text::fromText(text);
std::size_t maxChar(Json::getInstance().getDataFromJson<std::size_t>(elem, "maxChar"));
Types::InputBox inputBox(text, name, maxChar);
auto search =
Expand All @@ -73,7 +73,7 @@ namespace Menu {
initFromSprite(elem);
}
Registry::getInstance().getComponents<Types::FontSize>().insertBack(fsz);
Registry::getInstance().getComponents<Raylib::Text>().insertBack(textComp);
Registry::getInstance().getComponents<Raylib::TextShared>().insertBack(textComp);
Registry::getInstance().getComponents<Types::InputBox>().insertBack(inputBox);
Registry::getInstance().getComponents<Types::Position>().insertBack(position);
Registry::getInstance().getComponents<Types::CollisionRect>().insertBack(collisionRect);
Expand Down Expand Up @@ -174,10 +174,10 @@ namespace Menu {
Maths::intToFloatConservingDecimals(arrPosition[id].y),
Maths::intToFloatConservingDecimals(arrCollisionRect[id].width),
Maths::intToFloatConservingDecimals(arrCollisionRect[id].height));
Raylib::Vector2 mousePos(Raylib::getMousePosition().x, Raylib::getMousePosition().y);
Raylib::Vector2 mousePos(Raylib::MouseInput::getMousePosition().x, Raylib::MouseInput::getMousePosition().y);

mousePos.x = (mousePos.x * maxPercent) / Raylib::getScreenWidth();
mousePos.y = (mousePos.y * maxPercent) / Raylib::getScreenHeight();
mousePos.x = (mousePos.x * maxPercent) / Raylib::Window::getScreenWidth();
mousePos.y = (mousePos.y * maxPercent) / Raylib::Window::getScreenHeight();

return Raylib::checkCollisionPointRec(mousePos, rect);
}
Expand Down
38 changes: 20 additions & 18 deletions src/Client/Systems/Menu/MenuSystems.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@
#include "B-luga-physics/ECSCustomTypes.hpp"
#include "B-luga/Maths/Maths.hpp"
#include "B-luga/SceneManager.hpp"
#include "B-luga-graphics/AnimRect.hpp"
#include "B-luga-graphics/GraphicsCustomTypes.hpp"
#include "MenuSystems.hpp"
#include "ResourcesManager.hpp"
#include "init.hpp"
#include "Menu.hpp"

namespace Systems {
Expand Down Expand Up @@ -43,13 +47,13 @@ namespace Systems {

static void insertText(std::size_t id, Registry::components<Types::InputBox> &arrInputBox)
{
Registry::components<Raylib::Text> arrText =
Registry::getInstance().getComponents<Raylib::Text>();
int key = Raylib::getCharPressed();
Registry::components<Raylib::TextShared> arrText =
Registry::getInstance().getComponents<Raylib::TextShared>();
int key = Raylib::KeyboardInput::getCharPressed();

if ((key >= ' ') && (key <= '}') && (arrInputBox[id].text.size() < arrInputBox[id].maxChar)) {
arrInputBox[id].text += static_cast<char>(key);
arrText[id].setCurrentText(arrInputBox[id].text);
arrText[id]->setCurrentText(arrInputBox[id].text);
}
}

Expand All @@ -58,7 +62,7 @@ namespace Systems {
Registry::components<Types::InputBox> arrInputBox =
Registry::getInstance().getComponents<Types::InputBox>();
std::vector<std::size_t> ids = Registry::getInstance().getEntitiesByComponents(
{typeid(Types::InputBox), typeid(Raylib::Text)});
{typeid(Types::InputBox), typeid(Raylib::TextShared)});

for (auto id : ids) {
if (arrInputBox[id].selected == true) {
Expand All @@ -71,7 +75,7 @@ namespace Systems {
{
std::size_t idEntity = 0;

if (Raylib::isMouseButtonPressed(Raylib::MouseButton::MOUSE_BTN_LEFT)) {
if (Raylib::MouseInput::isMouseButtonPressed(Raylib::MouseButton::MOUSE_BTN_LEFT)) {
if (!::Menu::checkClick(idEntity)) {
setAllInputBoxFalse();
return;
Expand All @@ -82,12 +86,12 @@ namespace Systems {

static void deleteInputBoxChar(std::size_t id, Registry::components<Types::InputBox> &arrInputBox)
{
Registry::components<Raylib::Text> arrText =
Registry::getInstance().getComponents<Raylib::Text>();
auto &arrText =
Registry::getInstance().getComponents<Raylib::TextShared>();

if (arrInputBox[id].text.size() > 0) {
arrInputBox[id].text.pop_back();
arrText[id].setCurrentText(arrInputBox[id].text);
arrText[id]->setCurrentText(arrInputBox[id].text);
}
}

Expand All @@ -96,10 +100,10 @@ namespace Systems {
Registry::components<Types::InputBox> arrInputBox =
Registry::getInstance().getComponents<Types::InputBox>();
std::vector<std::size_t> ids = Registry::getInstance().getEntitiesByComponents(
{typeid(Types::InputBox), typeid(Raylib::Text)});
{typeid(Types::InputBox), typeid(Raylib::TextShared)});

for (auto id : ids) {
if (arrInputBox[id].selected && Raylib::isKeyPressed(Raylib::KeyboardKey::KB_BACKSPACE)) {
if (arrInputBox[id].selected && Raylib::KeyboardInput::isKeyPressed(Raylib::KeyboardKey::KB_BACKSPACE)) {
deleteInputBoxChar(id, arrInputBox);
}
}
Expand Down Expand Up @@ -142,28 +146,26 @@ namespace Systems {
for (auto id : ids) {
if (::Menu::checkIsInsideRect(id)) {
arrAnimRect[id].changeRectList(Types::RectListType::HOVER);
Raylib::setMouseCursor(MOUSE_CURSOR_ARROW);
if (Raylib::isMouseButtonPressed(Raylib::MouseButton::MOUSE_BTN_LEFT)) {
if (Raylib::MouseInput::isMouseButtonPressed(Raylib::MouseButton::MOUSE_BTN_LEFT)) {
arrButton[id].callback();
}
return;
}
arrAnimRect[id].changeRectList(Types::RectListType::UNDEFINED);
}
Raylib::setMouseCursor(MOUSE_CURSOR_DEFAULT);
}

void initMenu(std::size_t managerId, std::size_t systemId)
{
if (Scene::SceneManager::getInstance().getCurrentScene() != Scene::Scene::MENU) {
if (Scene::SceneManager::getInstance().getCurrentScene() != Scenes::MENU) {
SystemManagersDirector::getInstance().getSystemManager(managerId).removeSystem(systemId);
return;
}
nlohmann::json connectButton =
Json::getInstance().getDataByVector({"menu", "connect"}, JsonType::MENU_DATA);
nlohmann::json inputBoxIp = Json::getInstance().getDataByVector({"menu", "ip"}, JsonType::MENU_DATA);
Json::getInstance().getDataByVector(ResourcesManager::getPathByJsonType(JsonType::MENU_DATA), {"menu", "connect"});
nlohmann::json inputBoxIp = Json::getInstance().getDataByVector(ResourcesManager::getPathByJsonType(JsonType::MENU_DATA), {"menu", "ip"});
nlohmann::json inputBoxHost =
Json::getInstance().getDataByVector({"menu", "host"}, JsonType::MENU_DATA);
Json::getInstance().getDataByVector(ResourcesManager::getPathByJsonType(JsonType::MENU_DATA), {"menu", "host"});

try {
::Menu::MenuBuilder::getInstance().initMenuEntity(
Expand Down
10 changes: 5 additions & 5 deletions src/Client/Systems/Menus/SelectLobby/SelectLobbySystems.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ namespace Systems::SelectLobbySystems {
Registry::getInstance().getClock().decreaseSeconds(clockId, 1);
// already created lobby
auto idsLobbyStatus =
Registry::getInstance().getEntitiesByComponents({typeid(LobbyStatus), typeid(Raylib::Text)});
Registry::getInstance().getEntitiesByComponents({typeid(LobbyStatus), typeid(Raylib::TextShared)});
auto &arrLobbyStatus = Registry::getInstance().getComponents<LobbyStatus>();
auto &arrLobbyText = Registry::getInstance().getComponents<Raylib::Text>();
auto &arrLobbyText = Registry::getInstance().getComponents<Raylib::TextShared>();
// list of all lobby
auto ids = Registry::getInstance().getEntitiesByComponents({typeid(struct lobby_s)});
auto &arrLobby = Registry::getInstance().getComponents<struct lobby_s>();
Expand All @@ -129,8 +129,8 @@ namespace Systems::SelectLobbySystems {
for (auto idLobbyStatus : idsLobbyStatus) {
if (arrLobby[id].lobbyInfos.port == arrLobbyStatus[idLobbyStatus].port
&& std::string(arrLobby[id].lobbyInfos.ip) == arrLobbyStatus[idLobbyStatus].ip) {
x = arrLobbyText[idLobbyStatus].x();
y = arrLobbyText[idLobbyStatus].y();
x = arrLobbyText[idLobbyStatus]->x();
y = arrLobbyText[idLobbyStatus]->y();
found = true;
}
}
Expand All @@ -143,7 +143,7 @@ namespace Systems::SelectLobbySystems {
+ gameTypeToString(arrLobby[id].gameType);
y += 5;
auto text = Raylib::Text::fromText(text_t, Raylib::Vector2(x, y), 2, Raylib::Red);
arrLobbyText.insertBack(*text);
arrLobbyText.insertBack(text);
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/Game/CreateMissiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,16 @@ namespace Systems {
static void playBulletSound(Types::Missiles &typeOfMissile)
{
Json &json = Json::getInstance();
Registry::components<Raylib::Sound> arrSounds =
Registry::getInstance().getComponents<Raylib::Sound>();
Registry::components<Raylib::SoundShared> arrSounds =
Registry::getInstance().getComponents<Raylib::SoundShared>();
nlohmann::json bulletData =
json.getJsonObjectById(ResourcesManager::getPathByJsonType(JsonType::BULLETS), getMissileId(typeOfMissile.type), "bullets");

const std::string soundPathShoot = json.getDataFromJson<std::string>(bulletData, "soundPath");

for (auto &sound : arrSounds) {
if (sound.getPath() == soundPathShoot) {
sound.setNeedToPlay(true);
if (sound->getPath() == soundPathShoot) {
sound->setNeedToPlay(true);
break;
}
}
Expand Down

0 comments on commit ed15d90

Please sign in to comment.