2024-12-26 00:29:24 +00:00
|
|
|
// src/Components/GameObject.h
|
2024-12-25 23:58:56 +00:00
|
|
|
#pragma once
|
2024-12-26 00:29:24 +00:00
|
|
|
|
|
|
|
#include <string>
|
2024-12-27 01:34:34 +00:00
|
|
|
#include <unordered_map>
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
#include "Component.h"
|
2024-12-25 23:58:56 +00:00
|
|
|
#include "Transform.h"
|
2024-12-27 21:27:05 +00:00
|
|
|
#include "ScriptComponent.h"
|
2024-12-25 23:58:56 +00:00
|
|
|
#include "Mesh.h"
|
|
|
|
|
2024-12-27 01:34:34 +00:00
|
|
|
#include <yaml-cpp/yaml.h>
|
|
|
|
|
|
|
|
// GetComponent<CameraComponent>()
|
2024-12-26 00:29:24 +00:00
|
|
|
|
2024-12-27 01:34:34 +00:00
|
|
|
class GameObject
|
2024-12-25 23:58:56 +00:00
|
|
|
{
|
2024-12-27 01:34:34 +00:00
|
|
|
public:
|
|
|
|
int id;
|
|
|
|
std::string name;
|
|
|
|
std::unordered_map<std::string, std::shared_ptr<Component>> components;
|
|
|
|
|
|
|
|
int GetComponentCount() const;
|
|
|
|
|
|
|
|
GameObject(int id, const std::string &name);
|
|
|
|
|
|
|
|
void AddComponent(const std::shared_ptr<Component> &component);
|
|
|
|
std::shared_ptr<Component> GetComponentByName(const std::string &name) const;
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
std::shared_ptr<T> GetComponent()
|
|
|
|
{
|
|
|
|
auto it = components.find(T::GetStaticName());
|
|
|
|
if (it != components.end())
|
|
|
|
{
|
|
|
|
return std::dynamic_pointer_cast<T>(it->second);
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Serialization methods
|
|
|
|
YAML::Node Serialize();
|
|
|
|
void Deserialize(const YAML::Node &node);
|
2024-12-26 00:29:24 +00:00
|
|
|
};
|