mirror of
https://github.com/zoriya/Bomberman.git
synced 2026-06-07 03:25:10 +00:00
Merge branch 'parser' of github.com:AnonymusRaccoon/Bomberman into parser
This commit is contained in:
+3
-1
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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";
|
||||
}
|
||||
|
||||
@@ -46,12 +46,7 @@ namespace BBM
|
||||
|
||||
std::vector<Node> Node::getChildNodes(void)
|
||||
{
|
||||
std::vector<Node> childs;
|
||||
|
||||
for (const auto &child : this->_childNodes) {
|
||||
childs.emplace_back(child);
|
||||
}
|
||||
return childs;
|
||||
return this->_childNodes;
|
||||
}
|
||||
|
||||
void Node::setName(const std::string &name)
|
||||
|
||||
@@ -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<MapGenerator::BlockType>(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::BonusType>(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<float>(indentLevel)) {
|
||||
throw ParserError("indent issue");
|
||||
throw ParserError("Indent issue");
|
||||
}
|
||||
if (lineIndentLevel < static_cast<float>(indentLevel)) {
|
||||
file.seekg(static_cast<size_t>(file.tellg()) - (line.length() + endlNbChars));
|
||||
|
||||
@@ -41,13 +41,25 @@ namespace BBM
|
||||
.addComponent<PositionComponent>()
|
||||
.addComponent<Drawable2DComponent, RAY::Texture>("assets/backgrounds/menu.png");
|
||||
scene->addEntity("white background")
|
||||
.addComponent<PositionComponent>(200, 300, 0)
|
||||
.addComponent<PositionComponent>(200, 300 - 50, 0)
|
||||
.addComponent<Drawable2DComponent, RAY2D::Rectangle>(Vector2f(), Vector2f(1525, 550), RAY::Color(WHITE).setA(150));
|
||||
scene->addEntity("white background")
|
||||
.addComponent<PositionComponent>(1920 / 2 - 500, 1080 - 100, 0)
|
||||
.addComponent<Drawable2DComponent, RAY2D::Rectangle>(Vector2f(), Vector2f(1000, 100), RAY::Color(WHITE).setA(150));
|
||||
scene->addEntity("white background")
|
||||
.addComponent<PositionComponent>(1920 / 2.75 - 10, 80, 0)
|
||||
.addComponent<Drawable2DComponent, RAY2D::Rectangle>(Vector2f(), Vector2f(650, 130), RAY::Color(WHITE).setA(150));
|
||||
scene->addEntity("lobby text")
|
||||
.addComponent<PositionComponent>(1920 / 2.75, 100, 0)
|
||||
.addComponent<PositionComponent>(1920 / 2.75, 80, 0)
|
||||
.addComponent<Drawable2DComponent, RAY2D::Text>("Get Ready", 120, RAY::Vector2(), ORANGE);
|
||||
scene->addEntity("lobby text")
|
||||
.addComponent<PositionComponent>(1920 / 2.75, 1080 - 80, 0)
|
||||
.addComponent<Drawable2DComponent, RAY2D::Text>("Join: A Button / Space / Right Ctrl", 30, RAY::Vector2(), BLACK);
|
||||
scene->addEntity("lobby text")
|
||||
.addComponent<PositionComponent>(1920 / 4 + 100, 1080 - 40, 0)
|
||||
.addComponent<Drawable2DComponent, RAY2D::Text>("Change Skin: B Button / Shift / Left Ctrl", 30, RAY::Vector2(), BLACK);
|
||||
auto &play = scene->addEntity("play button")
|
||||
.addComponent<PositionComponent>(1920 / 2.5, 1080 - 180, 0)
|
||||
.addComponent<PositionComponent>(1920 / 2.5, 1080 - 180 - 50, 0)
|
||||
.addComponent<Drawable2DComponent, RAY::Texture>("assets/buttons/button_new_game.png")
|
||||
.addComponent<OnIdleComponent>([](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<PositionComponent>(1920 / 6, 1.85 * 1080 / 3, 0)
|
||||
.addComponent<PositionComponent>(1920 / 6, 1.85 * 1080 / 3 - 50, 0)
|
||||
.addComponent<Drawable2DComponent, RAY2D::Text>("Lava: Off", 70, RAY::Vector2(), BLACK)
|
||||
.addComponent<OnClickComponent>([](WAL::Entity &entity, WAL::Wal &wal)
|
||||
{
|
||||
@@ -130,7 +142,7 @@ namespace BBM
|
||||
});
|
||||
|
||||
auto &heightOption = scene->addEntity("Height option text")
|
||||
.addComponent<PositionComponent>(1920 / 6, 2.1 * 1080 / 3, 0)
|
||||
.addComponent<PositionComponent>(1920 / 6, 2.1 * 1080 / 3 - 50, 0)
|
||||
.addComponent<Drawable2DComponent, RAY2D::Text>("2nd Level: Off", 70, RAY::Vector2(), BLACK)
|
||||
.addComponent<OnClickComponent>([](WAL::Entity &entity, WAL::Wal &wal)
|
||||
{
|
||||
@@ -154,7 +166,7 @@ namespace BBM
|
||||
});
|
||||
|
||||
auto &aiMore = scene->addEntity("AI+")
|
||||
.addComponent<PositionComponent>(1920 / 1.75, 1.85 * 1080 / 3, 0)
|
||||
.addComponent<PositionComponent>(1920 / 1.75, 1.85 * 1080 / 3 - 50, 0)
|
||||
.addComponent<Drawable2DComponent, RAY::Texture>("assets/buttons/cpu_add.png")
|
||||
.addComponent<OnClickComponent>([](WAL::Entity &entity, WAL::Wal &wal)
|
||||
{
|
||||
@@ -172,7 +184,7 @@ namespace BBM
|
||||
});
|
||||
|
||||
auto &aiLess = scene->addEntity("AI-")
|
||||
.addComponent<PositionComponent>(1920 / 1.75, 2.10 * 1080 / 3, 0)
|
||||
.addComponent<PositionComponent>(1920 / 1.75, 2.10 * 1080 / 3 - 50, 0)
|
||||
.addComponent<Drawable2DComponent, RAY::Texture>("assets/buttons/cpu_remove.png")
|
||||
.addComponent<OnClickComponent>([](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<PositionComponent>(224 * (i + 1) + 200 * i, 1080 / 3, 0)
|
||||
.addComponent<PositionComponent>(224 * (i + 1) + 200 * i, 1080 / 3 - 50, 0)
|
||||
.addComponent<Drawable2DComponent, RAY2D::Rectangle>(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<PositionComponent>(224 * (i + 1) + 200 * i, 1080 / 3, 0)
|
||||
.addComponent<PositionComponent>(224 * (i + 1) + 200 * i, 1080 / 3 - 50, 0)
|
||||
.addComponent<Drawable2DComponent, RAY::Texture>("assets/player/icons/none.png");
|
||||
auto &ready = scene->addEntity("ready")
|
||||
.addComponent<PositionComponent>(224 * (i + 1) + 200 * i, 1080 / 3, 0)
|
||||
.addComponent<PositionComponent>(224 * (i + 1) + 200 * i, 1080 / 3 - 50, 0)
|
||||
// todo check why it does this | hacky way to fix ready texture
|
||||
.addComponent<Drawable2DComponent, RAY::Texture>();
|
||||
player.addComponent<LobbyComponent>(i, ready, playerTile);
|
||||
|
||||
@@ -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<PositionComponent>(1920 / 5, 2 * 1080 / 4.25, 0)
|
||||
.addComponent<TimerComponent>(3s, [](WAL::Entity &myEntity, WAL::Wal &wal) {
|
||||
.addComponent<TimerComponent>(3s, [](WAL::Entity &myEntity, WAL::Wal &) {
|
||||
myEntity.scheduleDeletion();
|
||||
})
|
||||
.addComponent<Drawable2DComponent, RAY2D::Text>(err.what(), 50, RAY::Vector2(), RED);
|
||||
gameState.nextScene = BBM::GameState::SceneID::LobbyScene;
|
||||
.addComponent<Drawable2DComponent, RAY2D::Text>("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;
|
||||
|
||||
@@ -116,7 +116,7 @@ namespace BBM
|
||||
.addSystem<EndConditionSystem>()
|
||||
.addSystem<ScoreSystem>()
|
||||
.addSystem<CameraSystem>()
|
||||
.addSystem<ResumeLobbySystem>()
|
||||
.addSystem<ResumeLobbySystem>()
|
||||
.addSystem<MusicSystem>();
|
||||
}
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ namespace BBM
|
||||
Runner::gameState.nextScene = GameState::ScoreScene;
|
||||
})
|
||||
.addComponent<PositionComponent>(1920 / 2 - 2 * 30, 30, 0)
|
||||
.addComponent<TagComponent<"Timer">>()
|
||||
.addComponent<TagComponent<Timer>>()
|
||||
.addComponent<Drawable2DComponent, RAY2D::Text>("", 60, RAY::Vector2(), ORANGE);
|
||||
for (WAL::Entity &player : this->_wal.getScene()->view<TagComponent<Player>>())
|
||||
player.getComponent<ControllableComponent>().disabled = false;
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace BBM
|
||||
: System(wal)
|
||||
{}
|
||||
|
||||
void TimerUISystem::onUpdate(WAL::ViewEntity<TimerComponent, Drawable2DComponent, TagComponent<"Timer">> &entity, std::chrono::nanoseconds dtime)
|
||||
void TimerUISystem::onUpdate(WAL::ViewEntity<TimerComponent, Drawable2DComponent, TagComponent<Timer>> &entity, std::chrono::nanoseconds dtime)
|
||||
{
|
||||
auto &timer = entity.get<TimerComponent>();
|
||||
RAY2D::Text *text = dynamic_cast<RAY2D::Text *>(entity.get<Drawable2DComponent>().drawable.get());
|
||||
|
||||
@@ -12,11 +12,11 @@
|
||||
|
||||
namespace BBM
|
||||
{
|
||||
class TimerUISystem : public WAL::System<TimerComponent, Drawable2DComponent, TagComponent<"Timer">>
|
||||
class TimerUISystem : public WAL::System<TimerComponent, Drawable2DComponent, TagComponent<Timer>>
|
||||
{
|
||||
public:
|
||||
//! @inherit
|
||||
void onUpdate(WAL::ViewEntity<TimerComponent, Drawable2DComponent, TagComponent<"Timer">> &entity, std::chrono::nanoseconds dtime) override;
|
||||
void onUpdate(WAL::ViewEntity<TimerComponent, Drawable2DComponent, TagComponent<Timer>> &entity, std::chrono::nanoseconds dtime) override;
|
||||
|
||||
//! @brief A default constructor
|
||||
explicit TimerUISystem(WAL::Wal &);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -61,6 +61,7 @@ TEST_CASE("View add entity", "[View]")
|
||||
.addComponent<PositionComponent>();
|
||||
scene.applyChanges();
|
||||
REQUIRE(scene.view<PositionComponent>().size() == 2);
|
||||
(void)entity;
|
||||
}
|
||||
|
||||
TEST_CASE("View remove entity", "[View]")
|
||||
@@ -75,6 +76,7 @@ TEST_CASE("View remove entity", "[View]")
|
||||
REQUIRE(scene.view<PositionComponent>().size() == 0);
|
||||
for (auto &it : scene.view<PositionComponent>())
|
||||
REQUIRE(false);
|
||||
(void)scene;
|
||||
}
|
||||
|
||||
TEST_CASE("View cache switch", "[View]")
|
||||
|
||||
Reference in New Issue
Block a user