This repository has been archived on 2021-04-24. You can view files and clone it, but cannot push or open issues or pull requests.
game/include/Components/TopLevel/GameObject.hpp
2021-04-12 18:04:25 +03:00

58 lines
No EOL
1.5 KiB
C++

#ifndef _GAMEOBJECT_H
#define _GAMEOBJECT_H
#include <iostream>
#include <vector>
#include <map>
#include <functional>
extern "C" {
#include <lua.h>
#include <lauxlib.h>
}
#include <Components/TopLevel/GameObject.hpp>
#include <vendor/LuaBridge3/Source/LuaBridge/LuaBridge.h> // Pain
#include <vendor/LuaBridge3/Source/LuaBridge/Vector.h> // Pain
struct GameObject {
GameObject(std::string name) : name(name) {}
std::string name;
std::string type;
GameObject* parent;
std::vector<GameObject*> children;
std::map<std::string, std::function<void()>> handlers;
std::vector<GameObject*>& GetChildren() {
return this->children;
}
GameObject& Get(std::string name) {
// NOTE(hippoz): This is a mess.
// I should be using find_if, not a loop
for (int i = this->children.size()-1; i >= 0; i--) {
if (this->children[i]->name == name) {
return *this->children[i];
}
}
}
void Add(GameObject* gameObject) {
this->children.push_back(gameObject);
}
};
void registerGameObject(lua_State* L) {
luabridge::getGlobalNamespace (L)
.beginNamespace ("Core")
.beginClass <GameObject> ("GameObject")
.addProperty ("name", &GameObject::name)
.addFunction ("GetChildren", &GameObject::GetChildren)
.addFunction ("Add", &GameObject::Add)
.addFunction ("Get", &GameObject::Get)
.endClass ()
.endNamespace ();
}
#endif