mirror of
https://github.com/zoriya/Bomberman.git
synced 2026-06-04 10:44:42 +00:00
Adding scene functions
This commit is contained in:
@@ -10,5 +10,10 @@ namespace WAL
|
||||
{
|
||||
return this->_entities;
|
||||
}
|
||||
|
||||
void Scene::removeAll(std::function<bool (const Entity &)> &predicate)
|
||||
{
|
||||
this->_entities.erase(std::remove_if(this->_entities.begin(), this->_entities.end(), predicate), this->_entities.end());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include <functional>
|
||||
#include "Entity/Entity.hpp"
|
||||
|
||||
namespace WAL
|
||||
@@ -15,9 +16,31 @@ namespace WAL
|
||||
{
|
||||
private:
|
||||
//! @brief The list of registered entities
|
||||
std::vector<Entity> _entities;
|
||||
std::vector<Entity> _entities = {};
|
||||
public:
|
||||
//! @brief Get the list of entities.
|
||||
std::vector<Entity> &getEntities();
|
||||
|
||||
//! @brief Add a new entity to the scene, you can use this method with the same arguments as the entity's constructor.
|
||||
//! @return The current scene is returned to allow you to chain call.
|
||||
template <class ...Params>
|
||||
Scene &addEntity(Params ...params)
|
||||
{
|
||||
this->_entities.emplace_back(params...);
|
||||
return *this;
|
||||
}
|
||||
|
||||
//! @brief Remove every entity of this scene that matches the given predicate
|
||||
//! @param predicate The predicate used to filer entities
|
||||
void removeAll(std::function<bool (const Entity &)> &predicate);
|
||||
|
||||
//! @brief A default constructor
|
||||
Scene() = default;
|
||||
//! @brief A scene is copy constructable
|
||||
Scene(const Scene &) = default;
|
||||
//! @brief A default destructor
|
||||
~Scene() = default;
|
||||
//! @brief A scene is assignable
|
||||
Scene &operator=(const Scene &) = default;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -6,16 +6,16 @@
|
||||
|
||||
namespace WAL
|
||||
{
|
||||
SceneManager &WAL::SceneManager::addScene(WAL::Scene &&scene)
|
||||
Scene &WAL::SceneManager::addScene(WAL::Scene &&scene)
|
||||
{
|
||||
this->_scenes.push_front(scene);
|
||||
return *this;
|
||||
return this->getCurrent();
|
||||
}
|
||||
|
||||
SceneManager &SceneManager::addBackScene(Scene &&scene)
|
||||
Scene &SceneManager::addBackScene(Scene &&scene)
|
||||
{
|
||||
this->_scenes.insert(++this->_scenes.begin(), scene);
|
||||
return *this;
|
||||
return *(this->_scenes.begin() + 1);
|
||||
}
|
||||
|
||||
Scene &SceneManager::getCurrent()
|
||||
@@ -25,9 +25,8 @@ namespace WAL
|
||||
return this->_scenes.front();
|
||||
}
|
||||
|
||||
SceneManager &SceneManager::closeCurrent()
|
||||
void SceneManager::closeCurrent()
|
||||
{
|
||||
this->_scenes.pop_front();
|
||||
return *this;
|
||||
}
|
||||
}
|
||||
@@ -17,19 +17,18 @@ namespace WAL
|
||||
std::deque<Scene> _scenes = {};
|
||||
public:
|
||||
//! @brief Add a scene to the container and move to it.
|
||||
//! @return The manager instance used to call this function is returned. This allow method chaining.
|
||||
SceneManager &addScene(Scene &&scene);
|
||||
//! @return The newly added scene, to chain call.
|
||||
Scene &addScene(Scene &&scene);
|
||||
|
||||
//! @brief Add a scene before the current scene. This could be useful for lobbies or scene where the next scene can be constructed.
|
||||
//! @return The manager instance used to call this function is returned. This allow method chaining.
|
||||
SceneManager &addBackScene(Scene &&scene);
|
||||
//! @return The newly added scene, to chain call.
|
||||
Scene &addBackScene(Scene &&scene);
|
||||
|
||||
//! @breif Get the current scene
|
||||
Scene &getCurrent();
|
||||
|
||||
//! @brief Remove the current scene and switch to the previous scene on the stack.
|
||||
//! @return The manager instance used to call this function is returned. This allow method chaining.
|
||||
SceneManager &closeCurrent();
|
||||
void closeCurrent();
|
||||
|
||||
//! @brief A default constructor
|
||||
SceneManager() = default;
|
||||
|
||||
Reference in New Issue
Block a user