diff --git a/CMakeLists.txt b/CMakeLists.txt index 875f0325..4c56475c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -190,7 +190,9 @@ set(SOURCES sources/Component/Color/ColorComponent.cpp sources/Component/Stat/StatComponent.cpp sources/Component/Stat/StatComponent.hpp - sources/Component/Speed/SpeedComponent.cpp sources/Component/Speed/SpeedComponent.hpp) + sources/Component/Speed/SpeedComponent.cpp + sources/Component/Speed/SpeedComponent.hpp + ) add_executable(bomberman sources/main.cpp diff --git a/sources/Component/Lobby/ResumeLobbyComponent.cpp b/sources/Component/Lobby/ResumeLobbyComponent.cpp index 5a1bbf24..6cc0440b 100644 --- a/sources/Component/Lobby/ResumeLobbyComponent.cpp +++ b/sources/Component/Lobby/ResumeLobbyComponent.cpp @@ -9,9 +9,9 @@ namespace BBM ResumeLobbyComponent::ResumeLobbyComponent(WAL::Entity &entity, int playerNumber, WAL::Entity &button, WAL::Entity &tile, int pColor) : WAL::Component(entity), playerID(playerNumber), + playerColor(pColor), readyButton(button), - coloredTile(tile), - playerColor(pColor) + coloredTile(tile) {} WAL::Component *ResumeLobbyComponent::clone(WAL::Entity &entity) const diff --git a/sources/Component/Tag/TagComponent.hpp b/sources/Component/Tag/TagComponent.hpp index 9775c06d..328ca860 100644 --- a/sources/Component/Tag/TagComponent.hpp +++ b/sources/Component/Tag/TagComponent.hpp @@ -60,4 +60,5 @@ namespace BBM constexpr const char Bumper[] = "Bumper"; // interact with bombs (getting damage etc) but doesn't stop explosion constexpr const char BlowablePass[] = "BlowablePass"; + constexpr const char Timer[] = "Timer"; } diff --git a/sources/Parser/Node.cpp b/sources/Parser/Node.cpp index 3ad73b1c..f4d23eab 100644 --- a/sources/Parser/Node.cpp +++ b/sources/Parser/Node.cpp @@ -46,12 +46,7 @@ namespace BBM std::vector Node::getChildNodes(void) { - std::vector childs; - - for (const auto &child : this->_childNodes) { - childs.emplace_back(child); - } - return childs; + return this->_childNodes; } void Node::setName(const std::string &name) diff --git a/sources/Parser/ParserYaml.cpp b/sources/Parser/ParserYaml.cpp index 7122a053..020e7190 100644 --- a/sources/Parser/ParserYaml.cpp +++ b/sources/Parser/ParserYaml.cpp @@ -177,7 +177,7 @@ namespace BBM { if ((tmpAssets.find("red.png") == std::string::npos && tmpAssets.find("blue.png") == std::string::npos && tmpAssets.find("green.png") == std::string::npos && tmpAssets.find("yellow.png") == std::string::npos && tmpAssets.find("ai.png") == std::string::npos) || !std::filesystem::exists(tmpAssets)) { - throw (ParserError("Error with saved map: One asset is invalid.\n Loading default maps...")); + throw (ParserError("One asset is invalid.")); } auto start = tmpAssets.find_last_of('/') + 1; auto colorStr = tmpAssets.substr(start, tmpAssets.length() - start - 4); @@ -281,15 +281,19 @@ namespace BBM { std::string subStr; try { - auto start = line.find('[', 0) + 1; - subStr = line.substr(start, line.find(']', 0) - 1 - start); + auto start = line.find('[') + 1; + auto end = line.find(']'); + if (start == std::string::npos || end == std::string::npos || line.back() != ']') { + throw ParserError("Error parsing position."); + } + subStr = line.substr(start, end - start); auto pos = Utils::splitStr(subStr, ','); if (pos.size() != 3) - throw (ParserError("Error with saved map: Error parsing position.\n Loading default maps...")); + throw (ParserError("Error parsing position.")); if (!Utils::tryParseFloat(pos[0], x) || !Utils::tryParseFloat(pos[1], y) || !Utils::tryParseFloat(pos[2], z)) - throw (ParserError("Error with saved map: Error parsing position.\n Loading default maps...")); + throw (ParserError("Error parsing position.")); } catch (const std::out_of_range &err) { - throw (ParserError("Error with saved map: Error parsing position.\n Loading default maps...")); + throw (ParserError("Error parsing position.")); } return Vector3f(x, y, z); } @@ -299,9 +303,9 @@ namespace BBM { int maxBomb = 0; if (str.find('-') != std::string::npos) - throw (ParserError("Error with saved map: Couldn't parse max bomb.\n Loading default maps...")); + throw (ParserError("Couldn't parse max bomb.")); if (!Utils::tryParseInteger(str, maxBomb)) - throw (ParserError("Error with saved map: Couldn't parse max bomb.\n Loading default maps...")); + throw (ParserError("Couldn't parse max bomb.")); return (maxBomb); } @@ -310,9 +314,9 @@ namespace BBM { int explosionRadius = 0; if (line.find('-') != std::string::npos) - throw (ParserError("Error with saved map: Couldn't parse explosion radius.\n Loading default maps...")); + throw (ParserError("Couldn't parse explosion radius.")); if (!Utils::tryParseInteger(line, explosionRadius)) - throw (ParserError("Error with saved map: Couldn't parse explosion radius.\n Loading default maps...")); + throw (ParserError("Couldn't parse explosion radius.")); return (explosionRadius); } @@ -321,29 +325,29 @@ namespace BBM { float speed = 0; if (line.find('-') != std::string::npos) - throw (ParserError("Error with saved map: Couldn't parse speed.\n Loading default maps...")); + throw (ParserError("Couldn't parse speed.")); if (!Utils::tryParseFloat(line, speed)) - throw (ParserError("Error with saved map: Couldn't parse speed.\n Loading default maps...")); + throw (ParserError("Couldn't parse speed.")); return (speed); } MapGenerator::BlockType ParserYAML::_parseBlockType(const std::string& blockType) { if (blockType.find('-') != std::string::npos) - throw (ParserError("Error with saved map: Couldn't parse block type.\n Loading default maps...")); + throw (ParserError("Couldn't parse block type.")); int block = 0; if (!Utils::tryParseInteger(blockType, block)) - throw (ParserError("Error with saved map: Couldn't parse block type.\n Loading default maps...")); + throw (ParserError("Couldn't parse block type.")); return (static_cast(block)); } Bonus::BonusType ParserYAML::_parseBonusType(const std::string& bonusType) { if (bonusType.find('-') != std::string::npos) - throw (ParserError("Error with saved map: Couldn't parse bonus type.\n Loading default maps...")); + throw (ParserError("Couldn't parse bonus type.")); int bonus = 0; if (!Utils::tryParseInteger(bonusType, bonus)) - throw (ParserError("Error with saved map: Couldn't parse bonus type.\n Loading default maps...")); + throw (ParserError("Couldn't parse bonus type.")); return (static_cast(bonus)); } @@ -357,10 +361,10 @@ namespace BBM { if (!garbage.empty()) { - throw ParserError("ill formed header, line: " + Utils::trimCopy(line)); + throw ParserError("Ill formed header,\nline: " + Utils::trimCopy(line)); } if (headerName.back() != ':') { - throw ParserError("header not ended with ':' , line: " + Utils::trimCopy(line)); + throw ParserError("Header not ended with ':',\nline: " + Utils::trimCopy(line)); } headerName.pop_back(); return headerName; @@ -376,10 +380,10 @@ namespace BBM { ss >> propertyName >> propertyValue >> garbage; if (!garbage.empty()) { - throw ParserError("ill formed property, line: " + Utils::trimCopy(line)); + throw ParserError("ill formed property, \nline: " + Utils::trimCopy(line)); } if (propertyName.back() != ':') { - throw ParserError("property name not ended with ':' , line: " + Utils::trimCopy(line)); + throw ParserError("property name not ended with ':', \nline: " + Utils::trimCopy(line)); } propertyName.pop_back(); return std::make_pair(propertyName, propertyValue); @@ -395,7 +399,7 @@ namespace BBM { std::ifstream file(path); if (!file.good()) - throw ParserError("can't read file"); + throw ParserError("Can't read file"); return parseNode(file, "root"); } @@ -412,7 +416,7 @@ namespace BBM { throw ParserError("Yaml only support 2 spaces as indent"); } if (lineIndentLevel > static_cast(indentLevel)) { - throw ParserError("indent issue"); + throw ParserError("Indent issue"); } if (lineIndentLevel < static_cast(indentLevel)) { file.seekg(static_cast(file.tellg()) - (line.length() + endlNbChars)); diff --git a/sources/Runner/LobbyScene.cpp b/sources/Runner/LobbyScene.cpp index 8c8daa9d..677360eb 100644 --- a/sources/Runner/LobbyScene.cpp +++ b/sources/Runner/LobbyScene.cpp @@ -41,13 +41,25 @@ namespace BBM .addComponent() .addComponent("assets/backgrounds/menu.png"); scene->addEntity("white background") - .addComponent(200, 300, 0) + .addComponent(200, 300 - 50, 0) .addComponent(Vector2f(), Vector2f(1525, 550), RAY::Color(WHITE).setA(150)); + scene->addEntity("white background") + .addComponent(1920 / 2 - 500, 1080 - 100, 0) + .addComponent(Vector2f(), Vector2f(1000, 100), RAY::Color(WHITE).setA(150)); + scene->addEntity("white background") + .addComponent(1920 / 2.75 - 10, 80, 0) + .addComponent(Vector2f(), Vector2f(650, 130), RAY::Color(WHITE).setA(150)); scene->addEntity("lobby text") - .addComponent(1920 / 2.75, 100, 0) + .addComponent(1920 / 2.75, 80, 0) .addComponent("Get Ready", 120, RAY::Vector2(), ORANGE); + scene->addEntity("lobby text") + .addComponent(1920 / 2.75, 1080 - 80, 0) + .addComponent("Join: A Button / Space / Right Ctrl", 30, RAY::Vector2(), BLACK); + scene->addEntity("lobby text") + .addComponent(1920 / 4 + 100, 1080 - 40, 0) + .addComponent("Change Skin: B Button / Shift / Left Ctrl", 30, RAY::Vector2(), BLACK); auto &play = scene->addEntity("play button") - .addComponent(1920 / 2.5, 1080 - 180, 0) + .addComponent(1920 / 2.5, 1080 - 180 - 50, 0) .addComponent("assets/buttons/button_new_game.png") .addComponent([](WAL::Entity &entity, WAL::Wal &wal) { @@ -106,7 +118,7 @@ namespace BBM texture->use("assets/buttons/button_htp_hovered.png"); }); auto &lavaOption = scene->addEntity("lava option text") - .addComponent(1920 / 6, 1.85 * 1080 / 3, 0) + .addComponent(1920 / 6, 1.85 * 1080 / 3 - 50, 0) .addComponent("Lava: Off", 70, RAY::Vector2(), BLACK) .addComponent([](WAL::Entity &entity, WAL::Wal &wal) { @@ -130,7 +142,7 @@ namespace BBM }); auto &heightOption = scene->addEntity("Height option text") - .addComponent(1920 / 6, 2.1 * 1080 / 3, 0) + .addComponent(1920 / 6, 2.1 * 1080 / 3 - 50, 0) .addComponent("2nd Level: Off", 70, RAY::Vector2(), BLACK) .addComponent([](WAL::Entity &entity, WAL::Wal &wal) { @@ -154,7 +166,7 @@ namespace BBM }); auto &aiMore = scene->addEntity("AI+") - .addComponent(1920 / 1.75, 1.85 * 1080 / 3, 0) + .addComponent(1920 / 1.75, 1.85 * 1080 / 3 - 50, 0) .addComponent("assets/buttons/cpu_add.png") .addComponent([](WAL::Entity &entity, WAL::Wal &wal) { @@ -172,7 +184,7 @@ namespace BBM }); auto &aiLess = scene->addEntity("AI-") - .addComponent(1920 / 1.75, 2.10 * 1080 / 3, 0) + .addComponent(1920 / 1.75, 2.10 * 1080 / 3 - 50, 0) .addComponent("assets/buttons/cpu_remove.png") .addComponent([](WAL::Entity &entity, WAL::Wal &wal) { @@ -191,13 +203,13 @@ namespace BBM for (int i = 0; i < 4; i++) { auto &playerTile = scene->addEntity("player tile") - .addComponent(224 * (i + 1) + 200 * i, 1080 / 3, 0) + .addComponent(224 * (i + 1) + 200 * i, 1080 / 3 - 50, 0) .addComponent(RAY::Vector2(224 * (i + 1) + 200 * i, 1080 / 3), RAY::Vector2(200, 200), RAY::Color(0, 0, 0, 0)); auto &player = scene->addEntity("player") - .addComponent(224 * (i + 1) + 200 * i, 1080 / 3, 0) + .addComponent(224 * (i + 1) + 200 * i, 1080 / 3 - 50, 0) .addComponent("assets/player/icons/none.png"); auto &ready = scene->addEntity("ready") - .addComponent(224 * (i + 1) + 200 * i, 1080 / 3, 0) + .addComponent(224 * (i + 1) + 200 * i, 1080 / 3 - 50, 0) // todo check why it does this | hacky way to fix ready texture .addComponent(); player.addComponent(i, ready, playerTile); diff --git a/sources/Runner/MainMenuScene.cpp b/sources/Runner/MainMenuScene.cpp index 58bb597a..beb1398e 100644 --- a/sources/Runner/MainMenuScene.cpp +++ b/sources/Runner/MainMenuScene.cpp @@ -77,13 +77,13 @@ namespace BBM ParserYAML::load(gameScene); } catch (std::exception const &err) { std::cout << err.what() << std::endl; - Runner::gameState._loadedScenes[GameState::SceneID::LobbyScene]->addEntity("Error message parser") + Runner::gameState._loadedScenes[GameState::SceneID::MainMenuScene]->addEntity("Error message parser") .addComponent(1920 / 5, 2 * 1080 / 4.25, 0) - .addComponent(3s, [](WAL::Entity &myEntity, WAL::Wal &wal) { + .addComponent(3s, [](WAL::Entity &myEntity, WAL::Wal &) { myEntity.scheduleDeletion(); }) - .addComponent(err.what(), 50, RAY::Vector2(), RED); - gameState.nextScene = BBM::GameState::SceneID::LobbyScene; + .addComponent("Could not load file: " + std::string(err.what()), 50, RAY::Vector2(), RED); + gameState.nextScene = BBM::GameState::SceneID::MainMenuScene; return; } Runner::gameState._loadedScenes[GameState::SceneID::GameScene] = gameScene; diff --git a/sources/Runner/Runner.cpp b/sources/Runner/Runner.cpp index 1f08300d..2f491fcb 100644 --- a/sources/Runner/Runner.cpp +++ b/sources/Runner/Runner.cpp @@ -116,7 +116,7 @@ namespace BBM .addSystem() .addSystem() .addSystem() - .addSystem() + .addSystem() .addSystem(); } diff --git a/sources/System/Renderer/CameraSystem.cpp b/sources/System/Renderer/CameraSystem.cpp index dbb4a735..e8d8d8e9 100644 --- a/sources/System/Renderer/CameraSystem.cpp +++ b/sources/System/Renderer/CameraSystem.cpp @@ -35,7 +35,7 @@ namespace BBM Runner::gameState.nextScene = GameState::ScoreScene; }) .addComponent(1920 / 2 - 2 * 30, 30, 0) - .addComponent>() + .addComponent>() .addComponent("", 60, RAY::Vector2(), ORANGE); for (WAL::Entity &player : this->_wal.getScene()->view>()) player.getComponent().disabled = false; diff --git a/sources/System/Timer/TimerUISystem.cpp b/sources/System/Timer/TimerUISystem.cpp index e28d14ff..194655e7 100644 --- a/sources/System/Timer/TimerUISystem.cpp +++ b/sources/System/Timer/TimerUISystem.cpp @@ -15,7 +15,7 @@ namespace BBM : System(wal) {} - void TimerUISystem::onUpdate(WAL::ViewEntity> &entity, std::chrono::nanoseconds dtime) + void TimerUISystem::onUpdate(WAL::ViewEntity> &entity, std::chrono::nanoseconds dtime) { auto &timer = entity.get(); RAY2D::Text *text = dynamic_cast(entity.get().drawable.get()); diff --git a/sources/System/Timer/TimerUISystem.hpp b/sources/System/Timer/TimerUISystem.hpp index a3c5c2c8..264d2bad 100644 --- a/sources/System/Timer/TimerUISystem.hpp +++ b/sources/System/Timer/TimerUISystem.hpp @@ -12,11 +12,11 @@ namespace BBM { - class TimerUISystem : public WAL::System> + class TimerUISystem : public WAL::System> { public: //! @inherit - void onUpdate(WAL::ViewEntity> &entity, std::chrono::nanoseconds dtime) override; + void onUpdate(WAL::ViewEntity> &entity, std::chrono::nanoseconds dtime) override; //! @brief A default constructor explicit TimerUISystem(WAL::Wal &); diff --git a/sources/Utils/Utils.cpp b/sources/Utils/Utils.cpp index ac20f278..e7ac109b 100644 --- a/sources/Utils/Utils.cpp +++ b/sources/Utils/Utils.cpp @@ -85,6 +85,9 @@ namespace BBM while (std::getline(f, buffer, delim)) {; strings.push_back(buffer); } + if (str.back() == delim) { + strings.emplace_back(""); + } return strings; } diff --git a/tests/ViewTest.cpp b/tests/ViewTest.cpp index aaa1bf36..2d7df652 100644 --- a/tests/ViewTest.cpp +++ b/tests/ViewTest.cpp @@ -61,6 +61,7 @@ TEST_CASE("View add entity", "[View]") .addComponent(); scene.applyChanges(); REQUIRE(scene.view().size() == 2); + (void)entity; } TEST_CASE("View remove entity", "[View]") @@ -75,6 +76,7 @@ TEST_CASE("View remove entity", "[View]") REQUIRE(scene.view().size() == 0); for (auto &it : scene.view()) REQUIRE(false); + (void)scene; } TEST_CASE("View cache switch", "[View]")