0
0
mirror of https://github.com/Nimac0/SDL_Minigame synced 2026-01-12 13:43:41 +00:00

doc: add docu

- datacomponent
- stateffectcomponent
- powerupcomponent
This commit is contained in:
Nimac0 2025-01-28 22:33:07 +01:00
parent 044d957106
commit eba3cdb6c8
4 changed files with 26 additions and 4 deletions

View File

@ -24,7 +24,6 @@ public:
AssetManager(Manager* manager);
~AssetManager();
void createProjectile(Vector2D pos, Vector2D velocity, int scale, int range, int speed, const char* texturePath, Entity* owner);
void createPowerup(Vector2D pos, std::function<void (Entity*)> pickupFunc, std::string texturePath);
Vector2D calculateSpawnPosition();

View File

@ -11,9 +11,21 @@ class DataComponent : public Component
public:
DataComponent() {};
~DataComponent() {};
/**
* @brief Set a key-value pair of any type in the data map
* @details e.g. setEntry("speed", 180); in this case the key is "speed" and the value is set to an integer of 180
* @param key The name to store the value under
* @param value The value to store of type T
*/
template <typename T>
void setEntry(const std::string& key, const T& value) { dataMap.insert_or_assign(key, value); }
/**
* @brief Get a value of type T from the data map
* @details e.g. getEntry<int>("speed"); in this case the key is "speed" and the value is returned as an integer
* @param key The name to retrieve the value from
* @return An optional of type T containing the value if it exists and matches in typeid, otherwise std::nullopt
*/
template<typename T>
std::optional<T> getEntry(std::string key) const {
if (!this->dataMap.contains(key)) return std::nullopt;

View File

@ -6,6 +6,10 @@
class PowerupComponent : public Component
{
public:
/**
* @brief Construct a new Powerup Component object
* @param func The function to be called when the powerup is picked up
*/
PowerupComponent(std::function<void (Entity*)> func);
~PowerupComponent() {};

View File

@ -5,10 +5,12 @@
#include <array>
#include <functional>
// This acts as a manager for the lifetime of a stateffect
/**
* @brief Struct to hold the duration, reset function and start time of a stat effect
*/
struct StatEffect {
uint32_t duration;
std::function<void()> resetFunction;
uint32_t duration; //!< Duration of the effect in milliseconds
std::function<void()> resetFunction; //!< Function to reset the effect, will be called on expiry of duration
uint32_t startTime;
};
@ -19,6 +21,11 @@ public:
void init() override;
void update() override;
/**
* @brief Add a stat effect to the entity
* @param duration The duration of the effect in milliseconds
* @param resetFunction The function to reset the effect, will be called on expiry of duration
*/
void addEffect(uint32_t duration, std::function<void()> resetFunction);
private: