]> code.bitgloo.com Git - clyne/gamedev2.git/commitdiff
Added physics to the script system
authorAndy Belle-Isle <drumsetmonkey@gmail.com>
Sat, 7 Sep 2019 05:14:51 +0000 (01:14 -0400)
committerAndy Belle-Isle <drumsetmonkey@gmail.com>
Sat, 7 Sep 2019 05:14:51 +0000 (01:14 -0400)
src/script.cpp

index d8f23ecd7f29a7abc3be43f23549bcffbd0a9472..e1dea6a2bd8af7d806fcc06982af962e02fbfe1b 100644 (file)
@@ -86,6 +86,7 @@ void ScriptSystem::doFile(void)
 #include <components/Script.hpp>
 #include <components/Velocity.hpp>
 #include <components/Light.hpp>
+#include <components/Physics.hpp>
 
 void ScriptSystem::scriptExport(void)
 {
@@ -122,6 +123,10 @@ void ScriptSystem::scriptExport(void)
             "b", &Light::b,
             "strength", &Light::strength);
 
+    lua.new_usertype<Physics>("Physics",
+            sol::constructors<Physics(void), Physics()>(),
+            "standing", &Physics::standing);
+
     auto gamespace = lua["game"].get_or_create<sol::table>();
     gamespace.set_function("spawn", func);
 }
@@ -176,6 +181,15 @@ sol::table ScriptSystem::spawn(sol::object param)
             (*toRet)["Player"] = e.assign<Player>().get();
         }
 
+        if (tab["Physics"] != nullptr) {
+            if (!e.has_component<Position>()) // Position must exist for phys.
+                (*toRet)["Position"] = e.assign<Position>().get();
+            if (!e.has_component<Velocity>()) // Velocity must exist for phys.
+                (*toRet)["Velocity"] = e.assign<Velocity>().get();
+
+            (*toRet)["Physics"] = e.assign<Physics>().get();
+        }
+
         if (tab["Light"] != nullptr) {
             if (!e.has_component<Position>()) // Position must exist for vel.
                 (*toRet)["Position"] = e.assign<Position>().get();