From 009da9426ecf3b4b716c34915effdf19ed0e67b9 Mon Sep 17 00:00:00 2001 From: Emma Broman Date: Thu, 20 Oct 2022 13:13:40 +0200 Subject: [PATCH] Add a function to target previous interesting anchor Not only next --- src/navigation/navigationhandler.cpp | 3 ++- src/navigation/navigationhandler_lua.inl | 32 ++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/navigation/navigationhandler.cpp b/src/navigation/navigationhandler.cpp index fc6c60dc50..27ca0633ce 100644 --- a/src/navigation/navigationhandler.cpp +++ b/src/navigation/navigationhandler.cpp @@ -630,7 +630,8 @@ scripting::LuaLibrary NavigationHandler::luaLibrary() { codegen::lua::AddGlobalRoll, codegen::lua::TriggerIdleBehavior, codegen::lua::ListAllJoysticks, - codegen::lua::TargetNextInterestingAnchor + codegen::lua::TargetNextInterestingAnchor, + codegen::lua::TargetPreviousInterestingAnchor } }; } diff --git a/src/navigation/navigationhandler_lua.inl b/src/navigation/navigationhandler_lua.inl index baa7a0b88a..9e838cebab 100644 --- a/src/navigation/navigationhandler_lua.inl +++ b/src/navigation/navigationhandler_lua.inl @@ -140,6 +140,38 @@ namespace { global::navigationHandler->orbitalNavigator().startRetargetAnchor(); } +// Picks the previous node from the interesting nodes out of the profile and selects that. +// If the current anchor is not an interesting node, the first will be selected +[[codegen::luawrap]] void targetPreviousInterestingAnchor() { + using namespace openspace; + if (global::profile->markNodes.empty()) { + LWARNINGC( + "targetPreviousInterestingAnchor", + "Profile does not define any interesting nodes" + ); + return; + } + const std::vector& markNodes = global::profile->markNodes; + + std::string currAnchor = + global::navigationHandler->orbitalNavigator().anchorNode()->identifier(); + + auto it = std::find(markNodes.begin(), markNodes.end(), currAnchor); + if (it == markNodes.end()) { + // We want to use the first node if the current node is not an interesting node + global::navigationHandler->orbitalNavigator().setFocusNode(markNodes.front()); + } + else if (it == markNodes.begin()) { + // We want to use the last node if the current node is the first in the list + global::navigationHandler->orbitalNavigator().setFocusNode(markNodes.back()); + } + else { + // Otherwise we can just select the previous one + global::navigationHandler->orbitalNavigator().setFocusNode(*(it - 1)); + } + global::navigationHandler->orbitalNavigator().startRetargetAnchor(); +} + /** * Finds the input joystick with the given 'name' and binds the axis identified by the * second argument to be used as the type identified by the third argument. If