From eba3cdb6c8429c9de476ed4a3aa9cced0418685e Mon Sep 17 00:00:00 2001 From: Nimac0 Date: Tue, 28 Jan 2025 22:33:07 +0100 Subject: [PATCH] doc: add docu - datacomponent - stateffectcomponent - powerupcomponent --- include/AssetManager.h | 1 - include/DataComponent.h | 12 ++++++++++++ include/PowerupComponent.h | 4 ++++ include/StatEffectsComponent.h | 13 ++++++++++--- 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/include/AssetManager.h b/include/AssetManager.h index 1d3c97a..1ba04c9 100644 --- a/include/AssetManager.h +++ b/include/AssetManager.h @@ -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 pickupFunc, std::string texturePath); Vector2D calculateSpawnPosition(); diff --git a/include/DataComponent.h b/include/DataComponent.h index 8d514bf..805fd30 100644 --- a/include/DataComponent.h +++ b/include/DataComponent.h @@ -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 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("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 std::optional getEntry(std::string key) const { if (!this->dataMap.contains(key)) return std::nullopt; diff --git a/include/PowerupComponent.h b/include/PowerupComponent.h index 53f365b..2e58880 100644 --- a/include/PowerupComponent.h +++ b/include/PowerupComponent.h @@ -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 func); ~PowerupComponent() {}; diff --git a/include/StatEffectsComponent.h b/include/StatEffectsComponent.h index 8c438f9..356d417 100644 --- a/include/StatEffectsComponent.h +++ b/include/StatEffectsComponent.h @@ -5,10 +5,12 @@ #include #include -// 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 resetFunction; + uint32_t duration; //!< Duration of the effect in milliseconds + std::function 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 resetFunction); private: