From 4e6e342169e2dc8f86960bc31840e3a3b281814a Mon Sep 17 00:00:00 2001 From: Kae <80987908+Novaenia@users.noreply.github.com> Date: Tue, 27 Jun 2023 01:04:58 +1000 Subject: [PATCH] Improve AssetPath::split also fixed a bug with the cursor changes --- source/core/StarAssetPath.cpp | 54 +++++++++------------------ source/frontend/StarMainInterface.cpp | 2 +- 2 files changed, 19 insertions(+), 37 deletions(-) diff --git a/source/core/StarAssetPath.cpp b/source/core/StarAssetPath.cpp index 90116bb..a99ecfa 100644 --- a/source/core/StarAssetPath.cpp +++ b/source/core/StarAssetPath.cpp @@ -25,52 +25,34 @@ static Maybe> findFilenameRange(std::string const& pathUtf8 } AssetPath AssetPath::split(String const& path) { - auto i = path.begin(); - auto end = path.end(); - AssetPath components; - // base paths cannot have any ':' or '?' characters, stop at the first one. - while (i != end) { - String::Char c = *i; - if (c == ':' || c == '?') - break; + std::string const& str = path.utf8(); - components.basePath += c; - ++i; - } + //base paths cannot have any ':' or '?' characters, stop at the first one. + size_t end = str.find_first_of(":?"); + components.basePath = str.substr(0, end); + + if (end == NPos) + return components; // Sub-paths must immediately follow base paths and must start with a ':', // after this point any further ':' characters are not special. - if (i != end && *i == ':') { - ++i; - while (i != end) { - String::Char c = *i; - if (c == '?') - break; - - if (!components.subPath) - components.subPath.emplace(); - - *components.subPath += c; - ++i; - } + if (str[end] == ':') { + size_t beg = end; + end = str.find_first_of("?", beg); + size_t len = end - beg - 1; + if (len) + components.subPath.emplace(str.substr(beg + 1, len)); } + if (end == NPos) + return components; + // Directives must follow the base path and optional sub-path, and each // directive is separated by one or more '?' characters. - while (i != end && *i == '?') { - String directives; - while (i != end) { - directives.append(*i); - ++i; - } - - if (!directives.empty()) - components.directives.append(move(directives)); - } - - starAssert(i == end); + if (str[end] == '?') + components.directives = String(str.substr(end)); return components; } diff --git a/source/frontend/StarMainInterface.cpp b/source/frontend/StarMainInterface.cpp index 6c29587..cc09895 100644 --- a/source/frontend/StarMainInterface.cpp +++ b/source/frontend/StarMainInterface.cpp @@ -1407,7 +1407,7 @@ void MainInterface::renderCursor() { VerticalAnchor::VMidAnchor)); } - m_cursorItem->setPosition(m_cursorScreenPos / cursorScale + m_config->inventoryItemMouseOffset); + m_cursorItem->setPosition(m_cursorScreenPos / interfaceScale() + m_config->inventoryItemMouseOffset); if (auto swapItem = m_client->mainPlayer()->inventory()->swapSlotItem()) m_cursorItem->setItem(swapItem);