|
@@ -14,21 +14,24 @@
|
|
|
|
|
|
#include <ECS.h>
|
|
|
|
|
|
+#include <Components/RigidBody.h>
|
|
|
+#include <Components/Animation.h>
|
|
|
#include <Components/Script.h>
|
|
|
#include <Components/Transform.h>
|
|
|
+#include <Components/ProjectileEmitter.h>
|
|
|
|
|
|
-static int getEntityPosition(Entity entity)
|
|
|
+static std::tuple<double, double> getEntityPosition(Entity entity)
|
|
|
{
|
|
|
if (entity.hasComponent<TransformComponent>())
|
|
|
{
|
|
|
auto &transform = entity.getComponent<TransformComponent>();
|
|
|
-
|
|
|
+ return std::make_tuple(transform.position.x, transform.position.y);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
Logger::Error("Entity %d do not have a TransformComponent.", entity.getId());
|
|
|
}
|
|
|
- return 0;
|
|
|
+ return std::make_tuple(0, 0);
|
|
|
}
|
|
|
|
|
|
static void setEntityPosition(Entity entity, double x, double y)
|
|
@@ -45,6 +48,74 @@ static void setEntityPosition(Entity entity, double x, double y)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+static void setEntityVelocity(Entity entity, double x, double y)
|
|
|
+{
|
|
|
+ if (entity.hasComponent<RigidBodyComponent>())
|
|
|
+ {
|
|
|
+ auto &rigidbody = entity.getComponent<RigidBodyComponent>();
|
|
|
+ rigidbody.velocity.x = x;
|
|
|
+ rigidbody.velocity.y = y;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Logger::Error("Entity %d do not have a RigidBodyComponent.", entity.getId());
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+static std::tuple<double, double> getEntityVelocity(Entity entity)
|
|
|
+{
|
|
|
+ if (entity.hasComponent<RigidBodyComponent>())
|
|
|
+ {
|
|
|
+ auto &rigidbody = entity.getComponent<RigidBodyComponent>();
|
|
|
+ return std::make_tuple(rigidbody.velocity.x, rigidbody.velocity.y);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Logger::Error("Entity %d do not have a RigidBodyComponent.", entity.getId());
|
|
|
+ }
|
|
|
+ return std::make_tuple(0, 0);
|
|
|
+}
|
|
|
+
|
|
|
+static void setEntityRotation(Entity entity, double rotation)
|
|
|
+{
|
|
|
+ if (entity.hasComponent<TransformComponent>())
|
|
|
+ {
|
|
|
+ auto &transform = entity.getComponent<TransformComponent>();
|
|
|
+ transform.rotation = rotation;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Logger::Error("Entity %d do not have a TransformComponent.", entity.getId());
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+static void setProjectileVelocity(Entity entity, double x, double y)
|
|
|
+{
|
|
|
+ if (entity.hasComponent<ProjectileEmitterComponent>())
|
|
|
+ {
|
|
|
+ auto &projectileEmiter = entity.getComponent<ProjectileEmitterComponent>();
|
|
|
+ projectileEmiter.projectileVelocity.x = x;
|
|
|
+ projectileEmiter.projectileVelocity.y = y;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Logger::Error("Entity id#%d do not have a ProjectileEmitterComponent.", entity.getId());
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+static void setEntityAnimationFrame(Entity entity, uint32_t frame)
|
|
|
+{
|
|
|
+ if (entity.hasComponent<AnimationComponent>())
|
|
|
+ {
|
|
|
+ auto &animation = entity.getComponent<AnimationComponent>();
|
|
|
+ animation.currentFrame = frame;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Logger::Error("Entity %d do not have a AnimationComponent.", entity.getId());
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
class ScriptExecutorSystem : public System
|
|
|
{
|
|
|
public:
|
|
@@ -62,7 +133,16 @@ public:
|
|
|
"belongs_to_group", &Entity::belongsToGroup);
|
|
|
|
|
|
lua.set_function("set_position", setEntityPosition);
|
|
|
- //lua.set_function("set_position", setEntityPosition);
|
|
|
+ lua.set_function("get_position", getEntityPosition);
|
|
|
+
|
|
|
+ lua.set_function("set_velocity", setEntityVelocity);
|
|
|
+ lua.set_function("get_velocity", getEntityVelocity);
|
|
|
+
|
|
|
+ lua.set_function("set_rotation", setEntityRotation);
|
|
|
+
|
|
|
+ lua.set_function("set_projectile_velocity", setProjectileVelocity);
|
|
|
+
|
|
|
+ lua.set_function("set_animation_frame", setEntityAnimationFrame);
|
|
|
}
|
|
|
|
|
|
void update(double deltaTime, uint32_t ellapsedTime)
|