From 4eeacc60cab3d6cb070bcd19a5259b7a95832a1d Mon Sep 17 00:00:00 2001 From: Andy Belle-Isle Date: Sat, 31 Aug 2019 00:40:21 -0400 Subject: Lua spawned entities have "Idle" function Every entity spawned from Lua is given the "Scripted" component, this component holds onto the Entities master table and it's idle function --- src/components/IdleFunc.hpp | 39 ------------------------------- src/components/Script.hpp | 56 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 39 deletions(-) delete mode 100644 src/components/IdleFunc.hpp create mode 100644 src/components/Script.hpp (limited to 'src/components') diff --git a/src/components/IdleFunc.hpp b/src/components/IdleFunc.hpp deleted file mode 100644 index 29bcd7b..0000000 --- a/src/components/IdleFunc.hpp +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (C) 2019 Belle-Isle, Andrew - * Author: Belle-Isle, Andrew - * - * 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 . - */ - -#ifndef IDLEFUNC_HPP_ -#define IDLEFUNC_HPP_ - -#include - -struct IdleFunc : Component, entityx::Component -{ - sol::function luafunc; - public: - IdleFunc() {} - - IdleFunc FromLua(sol::object ref) - { - if (ref.get_type() == sol::type::function) { - this->luafunc = ref; - } - return *this; - } -}; - -#endif//IDLEFUNC_HPP_ diff --git a/src/components/Script.hpp b/src/components/Script.hpp new file mode 100644 index 0000000..0e7c9db --- /dev/null +++ b/src/components/Script.hpp @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2019 Belle-Isle, Andrew + * Author: Belle-Isle, Andrew + * + * 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 . + */ + +#ifndef SCRIPT_COMPONENT_HPP_ +#define SCRIPT_COMPONENT_HPP_ + +#include + +struct Scripted : Component, entityx::Component +{ + public: + sol::table caller; + Scripted() {} + Scripted(sol::table call): caller(call) {} + + + ~Scripted() + {} + + void cleanup() + { + caller = sol::nil; + } + + Scripted FromLua(sol::object) + { + //if (ref.get_type() == sol::type::function) { + // this->luafunc = ref; + //} + //init = true; + 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 + } +}; + +#endif//SCRIPT_COMPONENT_HPP_ -- cgit v1.2.3