21 lines
537 B
C++
21 lines
537 B
C++
#include "scenes/scene_registry.hpp"
|
|
|
|
namespace scenes {
|
|
|
|
SceneRegistry& SceneRegistry::instance() {
|
|
static SceneRegistry inst;
|
|
return inst;
|
|
}
|
|
|
|
void SceneRegistry::registerScene(int state_key, Factory factory) {
|
|
factories_[state_key] = std::move(factory);
|
|
}
|
|
|
|
std::unique_ptr<Scene> SceneRegistry::tryCreate(int state_key) const {
|
|
const auto it = factories_.find(state_key);
|
|
if (it == factories_.end()) return nullptr;
|
|
return it->second();
|
|
}
|
|
|
|
} // namespace scenes
|