x = 1.2,
y = 3.4
},
+ Name = "bord",
init = function(self)
print(self.Position.x .. "," .. self.Position.y)
end
x = 6.5,
y = 1.3
},
+ Render = {
+ texture = "assets/tex.png",
+ visible = true
+ },
init = function(self)
print(self.Position.x .. "," .. self.Position.y)
end
}
+animal = {
+ Render = {
+ texture = "assets/anim.png",
+ visible = false
+ }
+}
+
birdSpawn = game.spawn(bird);
birdSpawn:init()
+print(birdSpawn.Name.value)
dogSpawn = game.spawn(dog);
dogSpawn:init()
dogSpawn.Position.x = 37.5
+
+animalSpawn = game.spawn(animal);
+animalSpawn.Render.texture = "assets/newText.png"
/**
+
* Copyright (C) 2019 Belle-Isle, Andrew <drumsetmonkey@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
public:
float x,y;
Position(float _x, float _y): x(_x), y(_y) {}
- Position(void){x = y = 0.0;}
+ Position(void): x(0), y(0) {}
Position FromLua(sol::object ref)
{
- if (ref.get_type() == sol::type::table){
+ if (ref.get_type() == sol::type::table) {
sol::table tab = ref;
if (tab["x"] != nullptr)
this->x = tab["x"];
return 0;
}
+// TODO move all of these below once the test printouts are gone
+#include <components/Position.hpp>
+#include <components/Name.hpp>
+#include <components/Render.hpp>
+
void ScriptSystem::doFile(void)
{
auto result = lua.script_file("Scripts/init.lua");
manager->each<Position>(
[&](entityx::Entity, Position& p)
{std::cout << p.x << "," << p.y << std::endl;});
+
+ manager->each<Name>(
+ [&](entityx::Entity, Name& n)
+ {std::cout << n.name << std::endl;});
+
+ manager->each<Render>(
+ [&](entityx::Entity, Render& r)
+ {std::cout << r.texture << ": " << r.visible << std::endl;});
}
/********************
* SCRIPT PARSING *
********************/
+// TODO here
void ScriptSystem::scriptExport()
{
"x", &Position::x,
"y", &Position::y);
+ lua.new_usertype<Name>("Name",
+ sol::constructors<Name(std::string), Name()>(),
+ "value", &Name::name);
+
+ lua.new_usertype<Render>("Render",
+ sol::constructors<Render(std::string), Render()>(),
+ "visible", &Render::visible,
+ "texture", &Render::texture);
+
auto gamespace = lua["game"].get_or_create<sol::table>();
gamespace.set_function("spawn", func);
}
toRet["init"] = tab["init"];
}
+ if (tab["Name"] != nullptr) {
+ toRet["Name"] =
+ e.assign<Name>(Name().FromLua(tab["Name"])).get();
+ }
+
+ if (tab["Render"] != nullptr) {
+ toRet["Render"] =
+ e.assign<Render>(Render().FromLua(tab["Render"])).get();
+ }
+
} else {
std::cerr << "Parameter to spawn() must be a table!" << std::endl;
}