feat? add basich ah scene loading

This commit is contained in:
2026-07-25 21:46:01 +02:00
parent aa5c497f29
commit 4b6f773c0c
18 changed files with 523 additions and 73 deletions
@@ -0,0 +1,37 @@
#ifndef DESTRUM_COMPONENTFACTORY_H
#define DESTRUM_COMPONENTFACTORY_H
#include <functional>
#include <memory>
#include <string>
#include <unordered_map>
#include <destrum/ObjectModel/Component.h>
#include <destrum/ObjectModel/GameObject.h>
class ComponentFactory final {
public:
using CreateFn = std::function<Component*(GameObject&)>;
static void Register(const std::string& typeName, CreateFn createFn) {
Registry()[typeName] = std::move(createFn);
}
static Component* Create(const std::string& typeName, GameObject& owner) {
const auto it = Registry().find(typeName);
if (it == Registry().end()) {
return nullptr;
}
return it->second(owner);
}
private:
static std::unordered_map<std::string, CreateFn>& Registry() {
static std::unordered_map<std::string, CreateFn> registry;
return registry;
}
};
#endif //DESTRUM_COMPONENTFACTORY_H