aboutsummaryrefslogtreecommitdiffstats
path: root/src/components
diff options
context:
space:
mode:
Diffstat (limited to 'src/components')
-rw-r--r--src/components/Light.hpp54
-rw-r--r--src/components/Render.hpp11
-rw-r--r--src/components/Script.hpp15
3 files changed, 77 insertions, 3 deletions
diff --git a/src/components/Light.hpp b/src/components/Light.hpp
new file mode 100644
index 0000000..ee215a6
--- /dev/null
+++ b/src/components/Light.hpp
@@ -0,0 +1,54 @@
+/**
+ * @file Light.hpp
+ *
+ * Copyright (C) 2019 Belle-Isle, Andrew <drumsetmonkey@gmail.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef COMPONENT_LIGHT_HPP_
+#define COMPONENT_LIGHT_HPP_
+
+#include "Component.hpp"
+
+struct Light : Component<Light>, entityx::Component<Light>
+{
+public:
+ float r, g, b;
+ float strength;
+
+ Light() {}
+ Light(float _r, float _g, float _z, float _s) :
+ r(_r), g(_g), b(_z), strength(_s) {}
+
+ Light FromLua(sol::object ref)
+ {
+ if (ref.get_type() == sol::type::table) {
+ sol::table tab = ref;
+ if (tab["r"] == sol::type::number)
+ this->r = tab["r"];
+ if (tab["g"] == sol::type::number)
+ this->g = tab["g"];
+ if (tab["b"] == sol::type::number)
+ this->b = tab["b"];
+ if (tab["strength"] == sol::type::number)
+ this->strength = tab["strength"];
+ } else {
+ throw std::string("Light component must be a table");
+ }
+ return *this;
+ }
+};
+
+#endif//COMPONENT_LIGHT_HPP_
diff --git a/src/components/Render.hpp b/src/components/Render.hpp
index 451f2d1..3f1750f 100644
--- a/src/components/Render.hpp
+++ b/src/components/Render.hpp
@@ -19,12 +19,15 @@
#define COMPONENT_RENDER_HPP_
#include "Component.hpp"
+#include "texture.hpp"
struct Render : Component<Render>, entityx::Component<Render>
{
public:
- std::string texture;
+ Texture texture;
+ Texture normal;
bool visible;
+ bool flipX = false;
Render(std::string _file) :
texture(_file), visible(true) {}
@@ -38,7 +41,11 @@ public:
if (tab["visible"].get_type() == sol::type::boolean)
this->visible = tab["visible"];
if (tab["texture"].get_type() == sol::type::string)
- this->texture = tab["texture"];
+ this->texture = Texture(static_cast<std::string>(tab["texture"]));
+ if (tab["normal"].get_type() == sol::type::string)
+ this->normal = Texture(static_cast<std::string>(tab["normal"]));
+ if (tab["flipx"].get_type() == sol::type::boolean)
+ this->flipX = tab["flipx"];
} else {
throw std::string(
"Render component table formatted incorrectly"
diff --git a/src/components/Script.hpp b/src/components/Script.hpp
index 66addc8..b3c89f3 100644
--- a/src/components/Script.hpp
+++ b/src/components/Script.hpp
@@ -42,11 +42,24 @@ public:
return *this;
}
- void exec(void) {
+ void exec(void)
+ {
if (caller["Idle"] == sol::type::function)
caller["Idle"](caller); // Call idle function and pass itself
// in or to fulfill the 'self' param
}
+
+ void updatePhysics(void)
+ {
+ if (caller["PhysicsIdle"] == sol::type::function)
+ caller["PhysicsIdle"](caller);
+ }
+
+ void updateRender(void)
+ {
+ if (caller["RenderIdle"] == sol::type::function)
+ caller["RenderIdle"](caller);
+ }
};
#endif // COMPONENT_SCRIPT_HPP_