Add the ability to remove Tags

This commit is contained in:
Alexander Bock
2017-10-24 01:47:14 -07:00
parent 269dda8aff
commit 5a9ebe552b
4 changed files with 49 additions and 4 deletions

View File

@@ -1215,7 +1215,7 @@ void OpenSpaceEngine::render(const glm::mat4& sceneMatrix,
func();
}
if (_shutdown.inShutdown) {
if (isGuiWindow && _shutdown.inShutdown) {
_renderEngine->renderShutdownInformation(_shutdown.timer, _shutdown.waitTime);
}
@@ -1388,6 +1388,12 @@ scripting::LuaLibrary OpenSpaceEngine::luaLibrary() {
&luascriptfunctions::addTag,
"string, string",
"Adds a tag (second argument) to a scene graph node (first argument)"
},
{
"removeTag",
&luascriptfunctions::removeTag,
"string, string",
"Removes a tag (second argument) from a scene graph node (first argument)"
}
}
};

View File

@@ -176,7 +176,31 @@ int addTag(lua_State* L) {
return luaL_error(L, "Unknown scene graph node type '%s'", uri.c_str());
}
node->addTag(tag);
node->addTag(std::move(tag));
return 0;
}
/**
* \ingroup LuaScripts
* removeTag():
* Removes a tag from a SceneGraphNode
*/
int removeTag(lua_State* L) {
const int nArguments = lua_gettop(L);
if (nArguments != 2) {
return luaL_error(L, "Expected %i arguments, got %i", 2, nArguments);
}
const std::string uri = lua_tostring(L, -2);
const std::string tag = lua_tostring(L, -1);
SceneGraphNode* node = OsEng.renderEngine().scene()->sceneGraphNode(uri);
if (!node) {
return luaL_error(L, "Unknown scene graph node type '%s'", uri.c_str());
}
node->removeTag(tag);
return 0;
}

View File

@@ -282,4 +282,11 @@ void PropertyOwner::addTag(std::string tag) {
_tags.push_back(std::move(tag));
}
void PropertyOwner::removeTag(const std::string& tag) {
_tags.erase(
std::remove(_tags.begin(), _tags.end(), tag),
_tags.end()
);
}
} // namespace openspace::properties