diff --git a/data/assets/scene/solarsystem/missions/newhorizons/newhorizons.mission b/data/assets/scene/solarsystem/missions/newhorizons/mission.asset similarity index 96% rename from data/assets/scene/solarsystem/missions/newhorizons/newhorizons.mission rename to data/assets/scene/solarsystem/missions/newhorizons/mission.asset index ea2080d9ea..e0567d0521 100644 --- a/data/assets/scene/solarsystem/missions/newhorizons/newhorizons.mission +++ b/data/assets/scene/solarsystem/missions/newhorizons/mission.asset @@ -2,7 +2,7 @@ -- Many of the values (especially days of the month if 01 or 30 or 31 and hh::mm::ss if all 0) -- are approximate and need fixing -return { +local Mission = { Name = "New Horizons", Phases = { { @@ -120,3 +120,11 @@ return { } } +asset.onInitialize(function() + openspace.loadMission(Mission) + end) + + asset.onDeinitialize(function() + openspace.unloadMission(Mission.Name) + end) + \ No newline at end of file diff --git a/data/assets/scene/solarsystem/missions/newhorizons/newhorizons.asset b/data/assets/scene/solarsystem/missions/newhorizons/newhorizons.asset index ac7159463c..3db0b18600 100644 --- a/data/assets/scene/solarsystem/missions/newhorizons/newhorizons.asset +++ b/data/assets/scene/solarsystem/missions/newhorizons/newhorizons.asset @@ -8,13 +8,4 @@ asset.require('./charon') asset.require('./othermoons') -local mission = asset.localResource("newhorizons.mission") -local missionName - -asset.onInitialize(function() - missionName = openspace.loadMission(mission) -end) - -asset.onDeinitialize(function() - openspace.unloadMission(missionName) -end) +asset.require('./mission') diff --git a/data/assets/scene/solarsystem/missions/osirisrex/osirisrex.mission b/data/assets/scene/solarsystem/missions/osirisrex/mission.asset similarity index 98% rename from data/assets/scene/solarsystem/missions/osirisrex/osirisrex.mission rename to data/assets/scene/solarsystem/missions/osirisrex/mission.asset index 2693825cdf..49bfb6b6bb 100644 --- a/data/assets/scene/solarsystem/missions/osirisrex/osirisrex.mission +++ b/data/assets/scene/solarsystem/missions/osirisrex/mission.asset @@ -24,7 +24,7 @@ References: --]] -return { +local Mission = { Name = "OSIRIS-REx", Phases = { -- All 1-level phases based on [1] @@ -384,3 +384,12 @@ return { -- End of [1] } } + + +asset.onInitialize(function() + openspace.loadMission(Mission) +end) + +asset.onDeinitialize(function() + openspace.unloadMission(Mission.Name) +end) diff --git a/data/assets/scene/solarsystem/missions/osirisrex/osirisrex.asset b/data/assets/scene/solarsystem/missions/osirisrex/osirisrex.asset index ff5d7658b6..f7f6460bb2 100644 --- a/data/assets/scene/solarsystem/missions/osirisrex/osirisrex.asset +++ b/data/assets/scene/solarsystem/missions/osirisrex/osirisrex.asset @@ -4,14 +4,4 @@ asset.require('./trail') asset.require('scene/solarsystem/sun/marker') asset.require('./script_schedule') - -local mission = asset.localResource('osirisrex.mission') -local missionName - -asset.onInitialize(function() - missionName = openspace.loadMission(mission) -end) - -asset.onDeinitialize(function() - openspace.unloadMission(missionName) -end) +asset.require('./mission') diff --git a/data/assets/scene/solarsystem/missions/osirisrex/spice_kernel_times.mission b/data/assets/scene/solarsystem/missions/osirisrex/spice_kernel_times.asset similarity index 97% rename from data/assets/scene/solarsystem/missions/osirisrex/spice_kernel_times.mission rename to data/assets/scene/solarsystem/missions/osirisrex/spice_kernel_times.asset index 26293ec878..4acfd894e7 100644 --- a/data/assets/scene/solarsystem/missions/osirisrex/spice_kernel_times.mission +++ b/data/assets/scene/solarsystem/missions/osirisrex/spice_kernel_times.asset @@ -1,5 +1,5 @@ -return -{ Name = "Nominal_Observations_Science", Phases = { +local Mission = { + Name = "Nominal_Observations_Science", Phases = { { Name = "03_Approach", Phases = { { Name = "DustSearch_v1", Phases = { { Name = "Phase03_AP_DustSearch_1.bc", TimeRange = { Start = "2018-SEP-11 21:31:01.183", End = "2018-SEP-12 02:18:41.183" }}, @@ -93,3 +93,12 @@ return }}, }}, }} + + +asset.onInitialize(function() + openspace.loadMission(Mission) +end) + +asset.onDeinitialize(function() + openspace.unloadMission(Mission.Name) +end) diff --git a/include/openspace/mission/mission.h b/include/openspace/mission/mission.h index d5b55c5c7b..6798139d9f 100644 --- a/include/openspace/mission/mission.h +++ b/include/openspace/mission/mission.h @@ -150,7 +150,7 @@ using Mission = MissionPhase; * \pre \p filename must not contain tokens * \pre \p filename must exist */ -Mission missionFromFile(const std::string& filename); +//Mission missionFromFile(const std::string& filename); } // namespace openspace diff --git a/include/openspace/mission/missionmanager.h b/include/openspace/mission/missionmanager.h index dddf0797ec..6bd589ad28 100644 --- a/include/openspace/mission/missionmanager.h +++ b/include/openspace/mission/missionmanager.h @@ -48,16 +48,11 @@ public: MissionManager(); /** - * Reads a mission from file and maps the mission name to the Mission object. If - * this is the first mission to be loaded, the mission will also be set as the - * current active mission. - * \param filename The file that contains the mission that is to be loaded - * \return The name of the mission that was loaded - * \pre \p filename must not be empty - * \pre \p filename must not contain tokens - * \pre \p filename must exist - */ - std::string loadMission(const std::string& filename); + * Loads a mission into the mission manager. + * + * \param mission The mission to be loaded + */ + void loadMission(Mission mission); /** * Unloads a previously loaded mission identified by the provided \p missionName. @@ -76,31 +71,29 @@ public: bool hasMission(const std::string& missionName); /** - * Sets the mission with the name as the current mission. The current - * mission is what is return by `currentMission()`. - * \pre missionName must not be empty - */ + * Sets the mission with the name as the current mission. The current + * mission is what is return by `currentMission()`. + * \pre missionName must not be empty + */ void setCurrentMission(const std::string& missionName); /** - * Returns true if a current mission exists - */ + * Returns true if a current mission exists + */ bool hasCurrentMission() const; /** - * Returns the latest mission specified to `setCurrentMission()`. If no mission has - * been specified, the first mission loaded will be returned. If no mission has been - * loaded, a warning will be printed and a dummy mission will be returned. - */ + * Returns the latest mission specified to `setCurrentMission()`. If no mission has + * been specified, the first mission loaded will be returned. If no mission has been + * loaded, a warning will be printed and a dummy mission will be returned. + */ const Mission& currentMission(); static scripting::LuaLibrary luaLibrary(); private: - using MissionMap = std::map; - MissionMap _missionMap; - - MissionMap::iterator _currentMission; + std::map _missionMap; + std::map::iterator _currentMission; }; } // namespace openspace diff --git a/src/mission/mission.cpp b/src/mission/mission.cpp index feadaac081..32770f8e07 100644 --- a/src/mission/mission.cpp +++ b/src/mission/mission.cpp @@ -162,21 +162,21 @@ void MissionPhase::phaseTrace(double time, Trace& trace, int maxDepth) const { } } -Mission missionFromFile(const std::string& filename) { - ghoul_assert(!filename.empty(), "filename must not be empty"); - ghoul_assert(!FileSys.containsToken(filename), "filename must not contain tokens"); - ghoul_assert(FileSys.fileExists(filename), "filename must exist"); - - ghoul::Dictionary missionDict; - ghoul::lua::loadDictionaryFromFile(filename, missionDict); - - documentation::testSpecificationAndThrow( - MissionPhase::Documentation(), - missionDict, - "Mission" - ); - - return MissionPhase(missionDict); -} +//Mission missionFromFile(const std::string& filename) { +// ghoul_assert(!filename.empty(), "filename must not be empty"); +// ghoul_assert(!FileSys.containsToken(filename), "filename must not contain tokens"); +// ghoul_assert(FileSys.fileExists(filename), "filename must exist"); +// +// ghoul::Dictionary missionDict; +// ghoul::lua::loadDictionaryFromFile(filename, missionDict); +// +// documentation::testSpecificationAndThrow( +// MissionPhase::Documentation(), +// missionDict, +// "Mission" +// ); +// +// return MissionPhase(missionDict); +//} } // namespace openspace diff --git a/src/mission/missionmanager.cpp b/src/mission/missionmanager.cpp index c84cbd8399..aa1217b477 100644 --- a/src/mission/missionmanager.cpp +++ b/src/mission/missionmanager.cpp @@ -55,15 +55,9 @@ bool MissionManager::hasCurrentMission() const { return _currentMission != _missionMap.end(); } -std::string MissionManager::loadMission(const std::string& filename) { - ghoul_assert(!filename.empty(), "filename must not be empty"); - ghoul_assert(!FileSys.containsToken(filename), "filename must not contain tokens"); - ghoul_assert(FileSys.fileExists(filename), "filename " + filename + " must exist"); +void MissionManager::loadMission(Mission mission) { + std::string currentMission = hasCurrentMission() ? _currentMission->first : ""; - // Changing the values might invalidate the _currentMission iterator - std::string currentMission = hasCurrentMission() ? _currentMission->first : ""; - - Mission mission = missionFromFile(filename); std::string missionName = mission.name(); _missionMap.insert({ missionName, std::move(mission) }); if (_missionMap.size() == 1) { @@ -73,8 +67,6 @@ std::string MissionManager::loadMission(const std::string& filename) { if (!currentMission.empty()) { setCurrentMission(currentMission); } - - return missionName; } void MissionManager::unloadMission(const std::string& missionName) { @@ -109,7 +101,7 @@ scripting::LuaLibrary MissionManager::luaLibrary() { &luascriptfunctions::loadMission, {}, "string", - "Load mission phases from file" + "Load mission phases specified in a dictionary" }, { "unloadMission", @@ -123,14 +115,14 @@ scripting::LuaLibrary MissionManager::luaLibrary() { &luascriptfunctions::hasMission, {}, "string", - "Returns whether a mission with the provided name has been loaded" + "Returns whether a mission with the provided identifier has been loaded" }, { "setCurrentMission", &luascriptfunctions::setCurrentMission, {}, "string", - "Set the currnet mission" + "Set the current mission" }, } }; diff --git a/src/mission/missionmanager_lua.inl b/src/mission/missionmanager_lua.inl index 5d9f3ea890..b7e10244a6 100644 --- a/src/mission/missionmanager_lua.inl +++ b/src/mission/missionmanager_lua.inl @@ -29,20 +29,17 @@ namespace openspace::luascriptfunctions { int loadMission(lua_State* L) { ghoul::lua::checkArgumentsAndThrow(L, 1, "lua::loadMission"); - const std::string& missionFileName = ghoul::lua::value( + ghoul::Dictionary dict = ghoul::lua::value( L, 1, ghoul::lua::PopValue::Yes ); - if (missionFileName.empty()) { - return ghoul::lua::luaError(L, "Filepath is empty"); - } - std::string name = global::missionManager->loadMission(absPath(missionFileName)); - ghoul::lua::push(L, name); + Mission mission = Mission(dict); + global::missionManager->loadMission(mission); - ghoul_assert(lua_gettop(L) == 1, "Incorrect number of items left on stack"); - return 1; + ghoul_assert(lua_gettop(L) == 0, "Incorrect number of items left on stack"); + return 0; } int unloadMission(lua_State* L) {