|
CardGame
Rogue-like card videogame
|
Factory responsible for creating runtime CardInstances. More...
#include <cardFactory.h>
Public Member Functions | |
| CardFactory () | |
| Constructs and registers all cards at startup. | |
| void | registerDefinition (std::string_view cardId, std::unique_ptr< CardDefinition > uniqueCardDefinition) |
| Registers a new card definition. | |
| void | registerCards () |
| Populates the factory with all static card definitions. | |
| std::unique_ptr< CardInstance > | makeSingleCard (const std::string &cardId) const override |
| Creates a new CardInstance based on the registered definition. | |
| ~CardFactory () | |
| Destructor. | |
Public Member Functions inherited from ICardFactory | |
| virtual std::unique_ptr< CardInstance > | makeSingleCard (const std::string &cardId) const =0 |
| Creates a new CardInstance identified by the given card ID. | |
| virtual | ~ICardFactory ()=default |
| Virtual destructor. | |
Factory responsible for creating runtime CardInstances.
CardFactory owns all immutable CardDefinitions registered at startup. It provides a centralized mechanism for instantiating CardInstances from these definitions during combat.
CardFactory is responsible only for card data and instantiation. Deck construction and combat flow are handled elsewhere.
| CardFactory::CardFactory | ( | ) |
Constructs and registers all cards at startup.
Construct a new Card Factory:: Card Factory object.
| CardFactory::~CardFactory | ( | ) |
Destructor.
|
overridevirtual |
Creates a new CardInstance based on the registered definition.
Looks up the card ID and returns a runtime copy (CardInstance). Throws if the ID is not registered.
| cardId | ID of the card to create. |
Implements ICardFactory.
| void CardFactory::registerCards | ( | ) |
Populates the factory with all static card definitions.
Called during construction.
| void CardFactory::registerDefinition | ( | std::string_view | cardId, |
| std::unique_ptr< CardDefinition > | uniqueCardDefinition | ||
| ) |
Registers a new card definition.
Adds the CardDefinition to the internal map, keyed by its unique ID. If the ID is already present, the definition is not replaced.
| cardId | Unique string identifier for the card. |
| uniqueCardDefinition | Ownership of the new definition. |