Skip to content

Commit

Permalink
UnrealURL: Use another UnrealURL instead of a string for the next url…
Browse files Browse the repository at this point in the history
… parameter
  • Loading branch information
LupertEverett authored and dpjudas committed Apr 23, 2024
1 parent 22fd19c commit eeeeba7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 26 deletions.
2 changes: 1 addition & 1 deletion SurrealEngine/Engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ void Engine::Run()
{
// To do: need to do something about that travel type and transfering of items

UnrealURL url(LevelInfo->URL, ClientTravelInfo.URL.ToString());
UnrealURL url(LevelInfo->URL, ClientTravelInfo.URL);
LogMessage("Client travel to " + url.ToString());
LoadMap(url);
LoginPlayer();
Expand Down
32 changes: 8 additions & 24 deletions SurrealEngine/UObject/UnrealURL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,18 @@

#include <sstream>

UnrealURL::UnrealURL(const UnrealURL& base, const std::string& url)
UnrealURL::UnrealURL(const UnrealURL& baseURL, const UnrealURL& nextURL)
{
// To do: this also needs to be able to handle fully qualified URLs for network support

*this = base;
*this = baseURL;

size_t pos = url.find('?');
if (pos == std::string::npos)
{
Map = url;
}
else
{
Map = url.substr(0, pos);
// Pass options from the nextURL to the base one
Map = nextURL.Map;
Portal = nextURL.Portal;

pos++;
while (pos < url.size())
{
size_t endpos = url.find('?', pos);
if (endpos == std::string::npos)
endpos = url.size();
AddOrReplaceOption(url.substr(pos, endpos - pos));
pos = endpos + 1;
}
}
for (auto& option : nextURL.Options)
AddOrReplaceOption(option);

// Unreal uses relative urls
if (Map.size() > 8 && Map.substr(0, 8) == "..\\maps\\")
Expand Down Expand Up @@ -185,10 +172,7 @@ std::string UnrealURL::GetOptions() const

std::string UnrealURL::GetPortal() const
{
if (!Portal.empty())
return "#" + Portal;
else
return std::string();
return Portal;
}

std::string UnrealURL::ToString() const
Expand Down
4 changes: 3 additions & 1 deletion SurrealEngine/UObject/UnrealURL.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ class UnrealURL
{
public:
UnrealURL() = default;
UnrealURL(const UnrealURL& base, const std::string& url);
// Constructs an UnrealURL by passing the options from nextURL to the baseURL
UnrealURL(const UnrealURL& baseURL, const UnrealURL& nextURL);
// Constructs an UnrealURL from a given parse-able string.
UnrealURL(const std::string& urlString);

void AddOrReplaceOption(const std::string& newvalue);
Expand Down

0 comments on commit eeeeba7

Please sign in to comment.