Improve AssetPath::split

also fixed a bug with the cursor changes
This commit is contained in:
Kae 2023-06-27 01:04:58 +10:00
parent 63b68b3a55
commit 4e6e342169
2 changed files with 19 additions and 37 deletions

View File

@ -25,52 +25,34 @@ static Maybe<pair<size_t, size_t>> findFilenameRange(std::string const& pathUtf8
} }
AssetPath AssetPath::split(String const& path) { AssetPath AssetPath::split(String const& path) {
auto i = path.begin();
auto end = path.end();
AssetPath components; AssetPath components;
// base paths cannot have any ':' or '?' characters, stop at the first one. std::string const& str = path.utf8();
while (i != end) {
String::Char c = *i;
if (c == ':' || c == '?')
break;
components.basePath += c; //base paths cannot have any ':' or '?' characters, stop at the first one.
++i; 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 ':', // Sub-paths must immediately follow base paths and must start with a ':',
// after this point any further ':' characters are not special. // after this point any further ':' characters are not special.
if (i != end && *i == ':') { if (str[end] == ':') {
++i; size_t beg = end;
while (i != end) { end = str.find_first_of("?", beg);
String::Char c = *i; size_t len = end - beg - 1;
if (c == '?') if (len)
break; components.subPath.emplace(str.substr(beg + 1, len));
if (!components.subPath)
components.subPath.emplace();
*components.subPath += c;
++i;
}
} }
if (end == NPos)
return components;
// Directives must follow the base path and optional sub-path, and each // Directives must follow the base path and optional sub-path, and each
// directive is separated by one or more '?' characters. // directive is separated by one or more '?' characters.
while (i != end && *i == '?') { if (str[end] == '?')
String directives; components.directives = String(str.substr(end));
while (i != end) {
directives.append(*i);
++i;
}
if (!directives.empty())
components.directives.append(move(directives));
}
starAssert(i == end);
return components; return components;
} }

View File

@ -1407,7 +1407,7 @@ void MainInterface::renderCursor() {
VerticalAnchor::VMidAnchor)); 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()) if (auto swapItem = m_client->mainPlayer()->inventory()->swapSlotItem())
m_cursorItem->setItem(swapItem); m_cursorItem->setItem(swapItem);