mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-05 03:00:58 -06:00
sending exoplanet names for gui panel
This commit is contained in:
@@ -3,7 +3,7 @@ asset.require('./static_server')
|
||||
local guiCustomization = asset.require('customization/gui')
|
||||
|
||||
-- Select which commit hashes to use for the frontend and backend
|
||||
local frontendHash = "d85b4022813caafb0fdde18bea2c2f51768816fa"
|
||||
local frontendHash = "6b5ac33a77fff6f46088c1fffdaf04d59ec5bb5f"
|
||||
local dataProvider = "data.openspaceproject.com/files/webgui"
|
||||
|
||||
local frontend = asset.syncedResource({
|
||||
|
||||
@@ -70,6 +70,13 @@ scripting::LuaLibrary ExoplanetsModule::luaLibrary() const {
|
||||
"",
|
||||
"Prints a list with the names of all exoplanet systems that can be added to "
|
||||
"the scene graph to the OpenSpace Log. "
|
||||
},
|
||||
{
|
||||
"getListOfExoplanets",
|
||||
&exoplanets::luascriptfunctions::getListOfExoplanets,
|
||||
{},
|
||||
"",
|
||||
"gets a list with the names of all exoplanet systems that can be used by a gui"
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -241,6 +241,7 @@ void createExoplanetSystem(std::string_view starName) {
|
||||
"Position = " + ghoul::to_string(starPosition) + ""
|
||||
"}"
|
||||
"},"
|
||||
"Tag = {'exoplanet_system'},"
|
||||
"GUI = {"
|
||||
"Name = '" + starNameSpeck + " (Star)',"
|
||||
"Path = '" + guiPath + "'"
|
||||
@@ -471,6 +472,50 @@ int removeExoplanetSystem(lua_State* L) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int getListOfExoplanets(lua_State* L) {
|
||||
ghoul::lua::checkArgumentsAndThrow(L, 0, "lua::getListOfExoplanets");
|
||||
|
||||
std::ifstream file(absPath(LookUpTablePath));
|
||||
|
||||
if (!file.good()) {
|
||||
return ghoul::lua::luaError(
|
||||
L,
|
||||
fmt::format("Failed to open file '{}'", LookUpTablePath)
|
||||
);
|
||||
}
|
||||
|
||||
std::vector<std::string> names;
|
||||
// As of 2020 there are about 4000 confirmed exoplanets, so use this number
|
||||
// as a guess for the vector size
|
||||
const int nExoplanetsGuess = 4000;
|
||||
names.reserve(nExoplanetsGuess);
|
||||
|
||||
std::string line;
|
||||
while (getline(file, line)) {
|
||||
std::stringstream ss(line);
|
||||
std::string name;
|
||||
getline(ss, name, ',');
|
||||
// Remove the last two characters, that specify the planet
|
||||
name = name.substr(0, name.size() - 2);
|
||||
|
||||
names.push_back(name);
|
||||
}
|
||||
|
||||
// For easier read, sort by names and remove duplicates
|
||||
std::sort(names.begin(), names.end());
|
||||
names.erase(std::unique(names.begin(), names.end()), names.end());
|
||||
|
||||
lua_newtable(L);
|
||||
int number = 1;
|
||||
for (const std::string& s : names) {
|
||||
lua_pushstring(L, s.c_str());
|
||||
lua_rawseti(L, -2, number);
|
||||
++number;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int listAvailableExoplanetSystems(lua_State* L) {
|
||||
ghoul::lua::checkArgumentsAndThrow(L, 0, "lua::listAvailableExoplanetSystems");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user