CardGame
Rogue-like card videogame
Loading...
Searching...
No Matches
CardFactory Class Reference

Factory responsible for creating runtime CardInstances. More...

#include <cardFactory.h>

Inheritance diagram for CardFactory:
Collaboration diagram for CardFactory:

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< CardInstancemakeSingleCard (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< CardInstancemakeSingleCard (const std::string &cardId) const =0
 Creates a new CardInstance identified by the given card ID.
 
virtual ~ICardFactory ()=default
 Virtual destructor.
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ CardFactory()

CardFactory::CardFactory ( )

Constructs and registers all cards at startup.

Construct a new Card Factory:: Card Factory object.

◆ ~CardFactory()

CardFactory::~CardFactory ( )

Destructor.

Member Function Documentation

◆ makeSingleCard()

std::unique_ptr< CardInstance > CardFactory::makeSingleCard ( const std::string &  cardId) const
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.

Parameters
cardIdID of the card to create.
Returns
A unique_ptr to the new CardInstance.

Implements ICardFactory.

◆ registerCards()

void CardFactory::registerCards ( )

Populates the factory with all static card definitions.

Called during construction.

◆ registerDefinition()

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.

Parameters
cardIdUnique string identifier for the card.
uniqueCardDefinitionOwnership of the new definition.

The documentation for this class was generated from the following files: