47 lines
1.3 KiB
C++
47 lines
1.3 KiB
C++
#pragma once
|
|
|
|
#include <map>
|
|
#include <iostream>
|
|
#include "../math.hpp"
|
|
#include "../UsefulException.hpp"
|
|
#include "../Mono/Mono.hpp"
|
|
|
|
class GameObject;
|
|
|
|
class Component {
|
|
Mono::ObjectHandle object_handle;
|
|
GameObject* owner;
|
|
public:
|
|
inline Component(Mono::Object managed_obj, GameObject* owner)
|
|
: object_handle(managed_obj), owner(owner) {}
|
|
};
|
|
|
|
struct Transform {
|
|
Vec2 scale = { 1, 1 };
|
|
Vec2 position = { 0, 0 };
|
|
angle_t rotation = 0;
|
|
};
|
|
|
|
std::ostream& operator<<(std::ostream& s, Transform& t);
|
|
|
|
|
|
class GameObject {
|
|
Transform transform;
|
|
std::map<std::u16string, Component> components;
|
|
Mono::ObjectHandle object_handle;
|
|
GameObject* parent;
|
|
public:
|
|
GameObject(Mono::Object managed_obj, GameObject* parent);
|
|
GameObject(const GameObject& o) = delete;
|
|
GameObject(GameObject&& o);
|
|
|
|
GameObject& operator=(GameObject&& o);
|
|
|
|
inline Transform& getTransform() { return transform; }
|
|
inline const Transform& getTransform() const { return transform; }
|
|
inline Mono::ObjectHandle& getObjectHandle() { return object_handle; }
|
|
inline const Mono::ObjectHandle& getObjectHandle() const { return object_handle; }
|
|
bool tryGetComponent(const std::u16string& name, Component** out_component);
|
|
bool tryAddComponent(const std::u16string& name, Component&& component);
|
|
};
|