|
@@ -15,6 +15,35 @@
|
|
|
#include <ECS.h>
|
|
|
|
|
|
#include <Components/Script.h>
|
|
|
+#include <Components/Transform.h>
|
|
|
+
|
|
|
+static int getEntityPosition(Entity entity)
|
|
|
+{
|
|
|
+ if (entity.hasComponent<TransformComponent>())
|
|
|
+ {
|
|
|
+ auto &transform = entity.getComponent<TransformComponent>();
|
|
|
+
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Logger::Error("Entity %d do not have a TransformComponent.", entity.getId());
|
|
|
+ }
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
+static void setEntityPosition(Entity entity, double x, double y)
|
|
|
+{
|
|
|
+ if (entity.hasComponent<TransformComponent>())
|
|
|
+ {
|
|
|
+ auto &transform = entity.getComponent<TransformComponent>();
|
|
|
+ transform.position.x = x;
|
|
|
+ transform.position.y = y;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Logger::Error("Entity %d do not have a TransformComponent.", entity.getId());
|
|
|
+ }
|
|
|
+}
|
|
|
|
|
|
class ScriptExecutorSystem : public System
|
|
|
{
|
|
@@ -24,13 +53,25 @@ public:
|
|
|
this->requireComponent<ScriptComponent>();
|
|
|
}
|
|
|
|
|
|
- void update()
|
|
|
+ void setup(sol::state &lua)
|
|
|
+ {
|
|
|
+ lua.new_usertype<Entity>("entity",
|
|
|
+ "get_id", &Entity::getId,
|
|
|
+ "destroy", &Entity::kill,
|
|
|
+ "has_tag", &Entity::hasTag,
|
|
|
+ "belongs_to_group", &Entity::belongsToGroup);
|
|
|
+
|
|
|
+ lua.set_function("set_position", setEntityPosition);
|
|
|
+ //lua.set_function("set_position", setEntityPosition);
|
|
|
+ }
|
|
|
+
|
|
|
+ void update(double deltaTime, uint32_t ellapsedTime)
|
|
|
{
|
|
|
for(auto entity : this->getSystemEntities())
|
|
|
{
|
|
|
const auto script = entity.getComponent<ScriptComponent>();
|
|
|
|
|
|
- script.func();
|
|
|
+ script.func(entity, deltaTime, ellapsedTime);
|
|
|
}
|
|
|
}
|
|
|
};
|