From cc065a2fb65a93ade7f0f3fceebfb1ecfb29962b Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Thu, 17 Jun 2021 17:58:02 +0200 Subject: [PATCH] Trying to create a retry button --- sources/Runner/ScoreScene.cpp | 15 +++++++-------- sources/System/Lobby/LobbySystem.cpp | 8 ++++---- sources/System/Lobby/LobbySystem.hpp | 3 ++- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/sources/Runner/ScoreScene.cpp b/sources/Runner/ScoreScene.cpp index 43af9488..40b9b041 100644 --- a/sources/Runner/ScoreScene.cpp +++ b/sources/Runner/ScoreScene.cpp @@ -34,24 +34,23 @@ namespace BBM static const std::vector rankName = { "1st", "2nd", "3rd", "4th" }; - Runner::gameState._loadedScenes[GameState::LobbyScene] = Runner::loadLobbyScene(); - auto &lobbyScene = Runner::gameState._loadedScenes[GameState::LobbyScene]; - for (auto &[entity, score, drawable]: gameScene.view()) - players.push_back(entity); + for (WAL::Entity &entity : gameScene.view()) + players.emplace_back(entity); std::sort(players.begin(), players.end(), [](WAL::Entity &entityA, WAL::Entity &entityB) { return entityA.getComponent().aliveTime > entityB.getComponent().aliveTime; }); int playerID = 0; - auto entityGarbage = WAL::Entity(*lobbyScene, ""); for (auto &entity: players) { - RAY3D::Model *model = dynamic_cast(entity.get().getComponent().drawable.get()); + auto *model = dynamic_cast(entity.get().getComponent().drawable.get()); std::string path = model->getTextureByMaterial(MAP_DIFFUSE).getResourcePath(); playersIconPath.push_back(path.replace(path.find("textures"), std::string("textures").size(), "icons")); - auto &newPlayer = lobbyScene->addEntity("add") - .addComponent(playerID++, entityGarbage, entityGarbage); + auto &newPlayer = scene->addEntity("add"); + newPlayer.addComponent(playerID++, newPlayer, newPlayer); newPlayer.getComponent().layout = entity.get().getComponent().layout; + std::string color = path.substr(path.find_last_of('/'), path.find_last_of('.')); + newPlayer.getComponent().color = std::find(LobbySystem::colors.begin(), LobbySystem::colors.end(), color) - LobbySystem::colors.begin(); } addMenuControl(*scene, sounds); diff --git a/sources/System/Lobby/LobbySystem.cpp b/sources/System/Lobby/LobbySystem.cpp index 3867bba6..142dfc92 100644 --- a/sources/System/Lobby/LobbySystem.cpp +++ b/sources/System/Lobby/LobbySystem.cpp @@ -27,7 +27,7 @@ namespace RAY2D = RAY::Drawables::Drawables2D; namespace BBM { - std::array LobbySystem::_colors = { + std::array LobbySystem::colors = { "blue", "red", "green", @@ -60,7 +60,7 @@ namespace BBM lobby.color = 0; } while (this->_colorTaken[lobby.color]); this->_colorTaken[lobby.color] = true; - entity.get().drawable = std::make_shared("assets/player/icons/" + _colors[lobby.color] + ".png"); + entity.get().drawable = std::make_shared("assets/player/icons/" + colors[lobby.color] + ".png"); lobby.coloredTile.getComponent().drawable->setColor(_rayColors[lobby.color]); } @@ -216,8 +216,8 @@ namespace BBM (Runner::hasHeights ? 1.01 : 0), mapHeight * (!(playerCount % 3))); auto *model = dynamic_cast(player.getComponent().drawable.get()); - model->setTextureToMaterial(MAP_DIFFUSE, "assets/player/textures/" + _colors[lobby.color] + ".png"); - std::string texturePath = "assets/player/ui/" + _colors[lobby.color] + ".png"; + model->setTextureToMaterial(MAP_DIFFUSE, "assets/player/textures/" + colors[lobby.color] + ".png"); + std::string texturePath = "assets/player/ui/" + colors[lobby.color] + ".png"; int x = (playerCount % 2 == 0) ? 1920 - 10 - 320 : 10; int y = (playerCount % 3 != 0) ? 1080 - 10 - 248 : 10; scene->addEntity("player color tile") diff --git a/sources/System/Lobby/LobbySystem.hpp b/sources/System/Lobby/LobbySystem.hpp index ad238ea6..b10641aa 100644 --- a/sources/System/Lobby/LobbySystem.hpp +++ b/sources/System/Lobby/LobbySystem.hpp @@ -22,12 +22,13 @@ namespace BBM void _nextColor(WAL::ViewEntity &entity); - static std::array _colors; static std::array _rayColors; std::array _colorTaken = {}; public: + static std::array colors; + //! @inherit void onUpdate(WAL::ViewEntity &entity, std::chrono::nanoseconds dtime) override;