0
0
mirror of https://github.com/Nimac0/SDL_Minigame synced 2026-01-13 20:33:42 +00:00

Compare commits

..

1 Commits

3 changed files with 14 additions and 18 deletions

View File

@ -31,20 +31,23 @@ public:
return game;
}*/
void registerClass(CreateFunc createFunc) {
this->creatorFunc = createFunc;
void registerClass(const std::string& className, CreateFunc createFunc) {
this->creators[className] = createFunc;
}
Game* create(GameInternal* gameInternal) {
if (this->creatorFunc == nullptr)
return nullptr;
Game* game = (this->creatorFunc)();
game->gameInternal = gameInternal;
return game;
Game* create(const std::string& className, GameInternal* gameInternal) {
auto it = this->creators.find(className);
if (it != creators.end()) {
Game* game = it->second();
game->gameInternal = gameInternal;
return game;
}
return nullptr;
}
private:
CreateFunc creatorFunc = nullptr;
CreateFunc creator;
std::map<std::string, CreateFunc> creators;
};
/*

View File

@ -6,17 +6,10 @@ namespace vego {
template<typename T>
class GameRegistryHelper {
public:
[[deprecated("GameRegistryHelper() does not take a className anymore")]]
GameRegistryHelper(const std::string& className) {
static_assert(std::is_base_of<Game, T>::value, "Your class must inherit from Game");
GameFactory::instance().registerClass(
[]() -> Game* { return new T; }
);
};
GameRegistryHelper() {
static_assert(std::is_base_of<Game, T>::value, "Your class must inherit from Game");
GameFactory::instance().registerClass(
className,
[]() -> Game* { return new T; }
);
};

View File

@ -179,7 +179,7 @@ void GameInternal::init(const char* title, int xpos, int ypos, int width, int he
// player2.addComponent<StatEffectsComponent>();
// player2.addGroup((size_t) Entity::GroupLabel::PLAYERS);
this->gameInstance = GameFactory::instance().create(this);
this->gameInstance = GameFactory::instance().create("Chickengame", this); //!< \todo Should be specified via a config file
this->gameInstance->init();
}