From 21774b937b10b05ab4161c0f360e3414c1ff7f73 Mon Sep 17 00:00:00 2001 From: Micah Date: Tue, 13 Oct 2020 05:24:26 -0400 Subject: [PATCH] sending exoplanet names for gui panel --- data/assets/util/webgui.asset | 2 +- modules/exoplanets/exoplanetsmodule.cpp | 7 ++++ modules/exoplanets/exoplanetsmodule_lua.inl | 45 +++++++++++++++++++++ 3 files changed, 53 insertions(+), 1 deletion(-) diff --git a/data/assets/util/webgui.asset b/data/assets/util/webgui.asset index 63d785dcbc..42932e3636 100644 --- a/data/assets/util/webgui.asset +++ b/data/assets/util/webgui.asset @@ -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({ diff --git a/modules/exoplanets/exoplanetsmodule.cpp b/modules/exoplanets/exoplanetsmodule.cpp index d9a4fdf386..ef6969781e 100644 --- a/modules/exoplanets/exoplanetsmodule.cpp +++ b/modules/exoplanets/exoplanetsmodule.cpp @@ -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" } }; diff --git a/modules/exoplanets/exoplanetsmodule_lua.inl b/modules/exoplanets/exoplanetsmodule_lua.inl index a10f63dbd1..59c02774c3 100644 --- a/modules/exoplanets/exoplanetsmodule_lua.inl +++ b/modules/exoplanets/exoplanetsmodule_lua.inl @@ -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 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");