Skip to content

Commit

Permalink
Handle the travel object reference linking in LoginPlayer
Browse files Browse the repository at this point in the history
  • Loading branch information
dpjudas committed May 12, 2024
1 parent a2d58b1 commit 638e1d0
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 102 deletions.
17 changes: 16 additions & 1 deletion SurrealEngine/Engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,22 @@ void Engine::LoginPlayer()
const ObjectTravelInfo& objInfo = it.second;

for (auto it = objInfo.Properties.begin(); it != objInfo.Properties.end(); it++)
acceptedActor->SetPropertyFromString(it->first, it->second);
{
UProperty* prop = acceptedActor->GetMemberProperty(it->first);
if (UObject::TryCast<UObjectProperty>(prop))
{
auto properties = ParsePropertiesFromString(it->second);
UObject* foundObject = FindObject(properties["Name"], properties["Class"]);
if (foundObject)
{
*static_cast<UObject**>(acceptedActor->GetProperty(prop)) = foundObject;
}
}
else
{
acceptedActor->SetPropertyFromString(it->first, it->second);
}
}
}
}
}
Expand Down
127 changes: 26 additions & 101 deletions SurrealEngine/UObject/UObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,24 +87,34 @@ PropertyDataOffset UObject::GetPropertyDataOffset(const NameString& name) const
return PropertyDataOffset();
}

const void* UObject::GetProperty(const NameString& propName) const
UProperty* UObject::GetMemberProperty(const NameString& propName) const
{
for (UProperty* prop : PropertyData.Class->Properties)
{
if (prop->Name == propName)
return PropertyData.Ptr(prop);
return prop;
}
throw std::runtime_error("Object Property '" + Name.ToString() + "." + propName.ToString() + "' not found");
}

void* UObject::GetProperty(UProperty* prop)
{
return PropertyData.Ptr(prop);
}

const void* UObject::GetProperty(UProperty* prop) const
{
return PropertyData.Ptr(prop);
}

const void* UObject::GetProperty(const NameString& propName) const
{
return GetProperty(GetMemberProperty(propName));
}

void* UObject::GetProperty(const NameString& propName)
{
for (UProperty* prop : PropertyData.Class->Properties)
{
if (prop->Name == propName)
return PropertyData.Ptr(prop);
}
throw std::runtime_error("Object Property '" + Name.ToString() + "." + propName.ToString() + "' not found");
return GetProperty(GetMemberProperty(propName));
}

bool UObject::HasProperty(const NameString& name) const
Expand All @@ -119,92 +129,14 @@ bool UObject::HasProperty(const NameString& name) const

std::string UObject::GetPropertyAsString(const NameString& propName) const
{
for (UProperty* prop : PropertyData.Class->Properties)
{
if (prop->Name == propName)
return prop->PrintValue(PropertyData.Ptr(prop));
}
throw std::runtime_error("Object Property '" + Name.ToString() + "." + propName.ToString() + "' not found");
UProperty* prop = GetMemberProperty(propName);
return prop->PrintValue(PropertyData.Ptr(prop));
}

void UObject::SetPropertyFromString(const NameString& name, const std::string& value)
{
for (UProperty* prop : PropertyData.Class->Properties)
{
if (prop->Name == name)
{
switch (prop->ValueType)
{
case ExpressionValueType::Nothing:
throw std::runtime_error("Attempted to change a None property: " + name.ToString());

case ExpressionValueType::ValueByte:
{
uint8_t parsedValue = std::stoi(value);
SetByte(name, parsedValue);
}
return;

case ExpressionValueType::ValueInt:
{
uint32_t parsedValue = std::stoul(value);
SetInt(name, parsedValue);
}
return;

case ExpressionValueType::ValueBool:
{
if (value == "True" || value == "true" || value == "1")
SetBool(name, true);
else if (value == "False" || value == "false" || value == "0")
SetBool(name, false);
else
throw std::invalid_argument("Encountered a non-boolean value: " + value);
}
return;

case ExpressionValueType::ValueFloat:
{
double parsedValue = std::stod(value);
SetFloat(name, parsedValue);
}
return;

case ExpressionValueType::ValueObject:
{
auto properties = ParsePropertiesFromString(value);

if (properties.empty())
return;

UObject* foundObject = engine->FindObject(properties["Name"], properties["Class"]);

if (!foundObject)
return;

SetObject(name, foundObject);
}
return;

// These are all struct types
case ExpressionValueType::ValueVector:
case ExpressionValueType::ValueRotator:
case ExpressionValueType::ValueStruct:
case ExpressionValueType::ValueColor:
prop->SetValueFromString(PropertyData.Ptr(prop), value);
return;

case ExpressionValueType::ValueString:
SetString(name, value);
return;

case ExpressionValueType::ValueName:
SetName(name, value);
return;
}
}

}
UProperty* prop = GetMemberProperty(name);
prop->SetValueFromString(PropertyData.Ptr(prop), value);
}

void UObject::SaveConfig()
Expand All @@ -224,12 +156,8 @@ uint32_t UObject::GetInt(const NameString& name) const

bool UObject::GetBool(const NameString& propName) const
{
for (UProperty* prop : PropertyData.Class->Properties)
{
if (prop->Name == propName)
return static_cast<UBoolProperty*>(prop)->GetBool(PropertyData.Ptr(prop));
}
throw std::runtime_error("Object Property '" + Name.ToString() + "." + propName.ToString() + "' not found");
UProperty* prop = GetMemberProperty(propName);
return static_cast<UBoolProperty*>(prop)->GetBool(PropertyData.Ptr(prop));
}

float UObject::GetFloat(const NameString& name) const
Expand Down Expand Up @@ -289,11 +217,8 @@ void UObject::SetInt(const NameString& name, uint32_t value)

void UObject::SetBool(const NameString& name, bool value)
{
for (UProperty* prop : PropertyData.Class->Properties)
{
if (prop->Name == name)
static_cast<UBoolProperty*>(prop)->SetBool(PropertyData.Ptr(prop), value);
}
UProperty* prop = GetMemberProperty(name);
static_cast<UBoolProperty*>(prop)->SetBool(PropertyData.Ptr(prop), value);
}

void UObject::SetFloat(const NameString& name, float value)
Expand Down
3 changes: 3 additions & 0 deletions SurrealEngine/UObject/UObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,10 @@ class UObject
bool HasProperty(const NameString& name) const;
void* GetProperty(const NameString& name);
const void* GetProperty(const NameString& name) const;
void* GetProperty(UProperty* prop);
const void* GetProperty(UProperty* prop) const;
PropertyDataOffset GetPropertyDataOffset(const NameString& name) const;
UProperty* GetMemberProperty(const NameString& name) const;

virtual std::string GetPropertyAsString(const NameString& name) const;
virtual void SetPropertyFromString(const NameString& name, const std::string& value);
Expand Down

0 comments on commit 638e1d0

Please sign in to comment.