mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-02-23 13:29:12 -06:00
Feature/virtualproperty (#286)
* Add virtual property owner to OpenSpaceEngine * Ability to add and remove virtual properties * Do not try to render empty PropertyOwner name Compile fix for iswaComponent Add example in default.scene * Delete virtual properties also in the OpenSpaceEngine dtor * Make RenderablePlanet not crash if the nighttextures are not present * - Add VirtualPropertyManager to manage ownership of virtual properties - Only execute regex when it was necessary -
This commit is contained in:
@@ -32,13 +32,14 @@ namespace luascriptfunctions {
|
||||
* reached
|
||||
*/
|
||||
int toggleShutdown(lua_State* L) {
|
||||
int nArguments = lua_gettop(L);
|
||||
if (nArguments != 0)
|
||||
const int nArguments = lua_gettop(L);
|
||||
if (nArguments != 0) {
|
||||
return luaL_error(L, "Expected %i arguments, got %i", 0, nArguments);
|
||||
}
|
||||
|
||||
OsEng.toggleShutdownMode();
|
||||
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -47,13 +48,92 @@ int toggleShutdown(lua_State* L) {
|
||||
* Writes out documentation files
|
||||
*/
|
||||
int writeDocumentation(lua_State* L) {
|
||||
int nArguments = lua_gettop(L);
|
||||
if (nArguments != 0)
|
||||
const int nArguments = lua_gettop(L);
|
||||
if (nArguments != 0) {
|
||||
return luaL_error(L, "Expected %i arguments, got %i", 0, nArguments);
|
||||
}
|
||||
|
||||
OsEng.writeDocumentation();
|
||||
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* \ingroup LuaScripts
|
||||
* addVirtualProperty():
|
||||
* Adds a virtual property that will set a group of properties
|
||||
*/
|
||||
int addVirtualProperty(lua_State* L) {
|
||||
using namespace properties;
|
||||
|
||||
const int nArguments = lua_gettop(L);
|
||||
if (nArguments != 6) {
|
||||
return luaL_error(L, "Expected %i arguments, got %i", 6, nArguments);
|
||||
}
|
||||
|
||||
const std::string type = lua_tostring(L, -6);
|
||||
const std::string name = lua_tostring(L, -5);
|
||||
const std::string identifier = lua_tostring(L, -4);
|
||||
|
||||
std::unique_ptr<Property> prop;
|
||||
if (type == "BoolProperty") {
|
||||
bool v = lua_toboolean(L, -3);
|
||||
prop = std::make_unique<BoolProperty>(identifier, name, v);
|
||||
}
|
||||
else if (type == "IntProperty") {
|
||||
int v = static_cast<int>(lua_tonumber(L, -3));
|
||||
int min = static_cast<int>(lua_tonumber(L, -2));
|
||||
int max = static_cast<int>(lua_tonumber(L, -1));
|
||||
|
||||
prop = std::make_unique<IntProperty>(identifier, name, v, min, max);
|
||||
}
|
||||
else if (type == "FloatProperty") {
|
||||
float v = static_cast<float>(lua_tonumber(L, -3));
|
||||
float min = static_cast<float>(lua_tonumber(L, -2));
|
||||
float max = static_cast<float>(lua_tonumber(L, -1));
|
||||
|
||||
prop = std::make_unique<FloatProperty>(identifier, name, v, min, max);
|
||||
}
|
||||
else if (type == "TriggerProperty") {
|
||||
prop = std::make_unique<TriggerProperty>(identifier, name);
|
||||
}
|
||||
else {
|
||||
return luaL_error(L, "Unknown property type '%s'", type.c_str());
|
||||
}
|
||||
|
||||
OsEng.virtualPropertyManager().addProperty(std::move(prop));
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* \ingroup LuaScripts
|
||||
* removeVirtualProperty():
|
||||
* Removes a previously added virtual property
|
||||
*/
|
||||
int removeVirtualProperty(lua_State* L) {
|
||||
const int nArguments = lua_gettop(L);
|
||||
if (nArguments != 1) {
|
||||
return luaL_error(L, "Expected %i arguments, got %i", 1, nArguments);
|
||||
}
|
||||
|
||||
const std::string name = lua_tostring(L, -1);
|
||||
properties::Property* p = OsEng.virtualPropertyManager().property(name);
|
||||
OsEng.virtualPropertyManager().removeProperty(p);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* \ingroup LuaScripts
|
||||
* removeAllVirtualProperties():
|
||||
* Remove all registered virtual properties
|
||||
*/
|
||||
int removeAllVirtualProperties(lua_State* L) {
|
||||
std::vector<properties::Property*> ps = OsEng.virtualPropertyManager().properties();
|
||||
for (properties::Property* p : ps) {
|
||||
OsEng.virtualPropertyManager().removeProperty(p);
|
||||
delete p;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user