diff options
Diffstat (limited to 'src/components')
-rw-r--r-- | src/components/Component.hpp | 9 | ||||
-rw-r--r-- | src/components/Name.hpp | 37 | ||||
-rw-r--r-- | src/components/Player.hpp | 16 | ||||
-rw-r--r-- | src/components/Position.hpp | 44 | ||||
-rw-r--r-- | src/components/Render.hpp | 52 | ||||
-rw-r--r-- | src/components/Script.hpp | 57 | ||||
-rw-r--r-- | src/components/Velocity.hpp | 42 |
7 files changed, 132 insertions, 125 deletions
diff --git a/src/components/Component.hpp b/src/components/Component.hpp index 98095ba..5a062bd 100644 --- a/src/components/Component.hpp +++ b/src/components/Component.hpp @@ -20,13 +20,12 @@ #include <sol/sol.hpp> -template <typename T> +template<typename T> class Component { - public: - Component(){}; - +public: virtual T FromLua(sol::object) = 0; }; -#endif//COMPONENT_HPP_ +#endif // COMPONENT_HPP_ + diff --git a/src/components/Name.hpp b/src/components/Name.hpp index c472cbb..94b7531 100644 --- a/src/components/Name.hpp +++ b/src/components/Name.hpp @@ -15,29 +15,30 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef NAME_HPP_ -#define NAME_HPP_ +#ifndef COMPONENT_NAME_HPP_ +#define COMPONENT_NAME_HPP_ -#include "components/Component.hpp" +#include "Component.hpp" #include <string> struct Name : Component<Name>, entityx::Component<Name> { - public: - std::string name; - Name(std::string _name) : name(_name) {} - Name(void): name() {}; - - Name FromLua(sol::object ref) - { - if (ref.get_type() == sol::type::string) { - this->name = ref.as<std::string>(); - } else { - throw std::string("Name component not formatted properly"); - } - return *this; - } +public: + std::string name; + Name(std::string _name = std::string()) : + name(_name) {} + + Name FromLua(sol::object ref) + { + if (ref.get_type() == sol::type::string) + this->name = ref.as<std::string>(); + else + throw std::string("Name component not formatted properly"); + + return *this; + } }; -#endif//NAME_HPP_ +#endif // COMPONENT_NAME_HPP_ + diff --git a/src/components/Player.hpp b/src/components/Player.hpp index 6fb6311..5c1e870 100644 --- a/src/components/Player.hpp +++ b/src/components/Player.hpp @@ -18,17 +18,19 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef PLAYER_HPP_ -#define PLAYER_HPP_ +#ifndef COMPONENT_PLAYER_HPP_ +#define COMPONENT_PLAYER_HPP_ #include "Component.hpp" struct Player : Component<Player>, entityx::Component<Player> { - Player FromLua([[maybe_unused]] sol::object ref) - { - return *this; - } +public: + Player FromLua([[maybe_unused]] sol::object ref) + { + return *this; + } }; -#endif // PLAYER_HPP_ +#endif // COMPONENT_PLAYER_HPP_ + diff --git a/src/components/Position.hpp b/src/components/Position.hpp index 8a6bd74..c801998 100644 --- a/src/components/Position.hpp +++ b/src/components/Position.hpp @@ -16,31 +16,33 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef POSITION_HPP_ -#define POSITION_HPP_ +#ifndef COMPONENT_POSITION_HPP_ +#define COMPONENT_POSITION_HPP_ -#include "components/Component.hpp" +#include "Component.hpp" struct Position : Component<Position>, entityx::Component<Position> { - public: - double x, y; - Position(double _x, double _y): x(_x), y(_y) {} - Position(void): x(0), y(0) {} - - Position FromLua(sol::object ref) - { - if (ref.get_type() == sol::type::table) { - sol::table tab = ref; - if (tab["x"] != nullptr) - this->x = tab["x"]; - if (tab["y"] != nullptr) - this->y = tab["y"]; - } else { - throw std::string("Position table not formatted properly"); - } - return *this; +public: + double x, y; + + Position(double _x = 0, double _y = 0) : + x(_x), y(_y) {} + + Position FromLua(sol::object ref) + { + if (ref.get_type() == sol::type::table) { + sol::table tab = ref; + if (tab["x"] != nullptr) + this->x = tab["x"]; + if (tab["y"] != nullptr) + this->y = tab["y"]; + } else { + throw std::string("Position table not formatted properly"); } + return *this; + } }; -#endif//POSITION_HPP_ +#endif // COMPONENT_POSITION_HPP_ + diff --git a/src/components/Render.hpp b/src/components/Render.hpp index 5a9b1a4..451f2d1 100644 --- a/src/components/Render.hpp +++ b/src/components/Render.hpp @@ -15,38 +15,38 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef RENDERC_HPP_ -#define RENDERC_HPP_ +#ifndef COMPONENT_RENDER_HPP_ +#define COMPONENT_RENDER_HPP_ -#include <components/Component.hpp> +#include "Component.hpp" struct Render : Component<Render>, entityx::Component<Render> { - public: - std::string texture; - bool visible; +public: + std::string texture; + bool visible; - Render(std::string _file): texture(_file), visible(true) {} - Render(): texture(), visible(false) {} + Render(std::string _file) : + texture(_file), visible(true) {} + Render(void) : + texture(), visible(false) {} - Render FromLua(sol::object ref) - { - if (ref.get_type() == sol::type::table) { - sol::table tab = ref; - if (tab["visible"].get_type() == sol::type::boolean) { - this->visible = tab["visible"]; - } - if (tab["texture"].get_type() == sol::type::string) { - this->texture = tab["texture"]; - } - } else { - throw std::string( - "Render component table formatted incorrectly" - ); - } - return *this; + Render FromLua(sol::object ref) + { + if (ref.get_type() == sol::type::table) { + sol::table tab = ref; + if (tab["visible"].get_type() == sol::type::boolean) + this->visible = tab["visible"]; + if (tab["texture"].get_type() == sol::type::string) + this->texture = tab["texture"]; + } else { + throw std::string( + "Render component table formatted incorrectly" + ); } - + return *this; + } }; -#endif//RENDERC_HPP_ +#endif // COMPONENT_RENDER_HPP_ + diff --git a/src/components/Script.hpp b/src/components/Script.hpp index 7570802..66addc8 100644 --- a/src/components/Script.hpp +++ b/src/components/Script.hpp @@ -16,37 +16,38 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef SCRIPT_COMPONENT_HPP_ -#define SCRIPT_COMPONENT_HPP_ +#ifndef COMPONENT_SCRIPT_HPP_ +#define COMPONENT_SCRIPT_HPP_ -#include <components/Component.hpp> +#include "Component.hpp" struct Scripted : Component<Scripted>, entityx::Component<Scripted> { - public: - sol::table caller; - Scripted() {} - Scripted(sol::table call): caller(call) {} - - - ~Scripted() - {} - - void cleanup() - { - caller = sol::nil; - } - - Scripted FromLua(sol::object) - { - return *this; - } - - void exec() { - if (caller["Idle"] == sol::type::function) - caller["Idle"](caller); // Call idle function and pass itself - // in or to fulfill the 'self' param - } +public: + sol::table caller; + + Scripted(void) {} + Scripted(sol::table call) : + caller(call) {} + + ~Scripted() {} + + void cleanup(void) + { + caller = sol::nil; + } + + Scripted FromLua([[maybe_unused]] sol::object ref) + { + return *this; + } + + 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 + } }; -#endif//SCRIPT_COMPONENT_HPP_ +#endif // COMPONENT_SCRIPT_HPP_ + diff --git a/src/components/Velocity.hpp b/src/components/Velocity.hpp index c2b85e8..29c0e5c 100644 --- a/src/components/Velocity.hpp +++ b/src/components/Velocity.hpp @@ -17,31 +17,33 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef VELOCITY_HPP_ -#define VELOCITY_HPP_ +#ifndef COMPONENT_VELOCITY_HPP_ +#define COMPONENT_VELOCITY_HPP_ -#include <components/Component.hpp> +#include "Component.hpp" struct Velocity : Component<Velocity>, entityx::Component<Velocity> { - public: - double x, y; - Velocity(): x(0), y(0) {} - Velocity(double _x, double _y): x(_x), y(_y) {} +public: + double x, y; - Velocity FromLua(sol::object ref) - { - if (ref.get_type() == sol::type::table) { - sol::table tab = ref; - if (tab["x"] != nullptr) - this->x = tab["x"]; - if (tab["y"] != nullptr) - this->y = tab["y"]; - } else { - throw std::string("Velocity table not formatted properly"); - } - return *this; + Velocity(double _x = 0, double _y = 0) : + x(_x), y(_y) {} + + Velocity FromLua(sol::object ref) + { + if (ref.get_type() == sol::type::table) { + sol::table tab = ref; + if (tab["x"] != nullptr) + this->x = tab["x"]; + if (tab["y"] != nullptr) + this->y = tab["y"]; + } else { + throw std::string("Velocity table not formatted properly"); } + return *this; + } }; -#endif//VELOCITY_HPP_ +#endif // COMPONENT_VELOCITY_HPP_ + |