Start using OneOf<>for unions/variant

This commit is contained in:
Hondacrx
2025-12-07 23:34:34 -05:00
parent 8cc270b895
commit 7f2baab1da
3 changed files with 30 additions and 31 deletions
@@ -239,7 +239,7 @@ namespace Game.DataStorage
var spline = splinesByCreateProperties.LookupByKey(createProperties.Id);
if (spline != null)
createProperties.SplinePoints = spline;
createProperties.Movement = spline;
_areaTriggerCreateProperties[createProperties.Id] = createProperties;
}
@@ -288,7 +288,7 @@ namespace Game.DataStorage
orbitInfo.CounterClockwise = circularMovementInfos.Read<bool>(7);
orbitInfo.CanLoop = circularMovementInfos.Read<bool>(8);
createProperties.OrbitInfo = orbitInfo;
createProperties.Movement = orbitInfo;
}
while (circularMovementInfos.NextRow());
}
@@ -344,15 +344,15 @@ namespace Game.DataStorage
continue;
}
if (createProperties.OrbitInfo != null)
if (!createProperties.Movement.IsT0)
{
Log.outError(LogFilter.Sql, $"Table `areatrigger` has listed AreaTriggerCreatePropertiesId (Id: {createPropertiesId.Id}, IsCustom: {createPropertiesId.IsCustom}) with orbit info");
continue;
}
string movementType = createProperties.Movement.Match(
_ => "",
splineInfo => "spline",
OrbitInfo => "orbit"
);
if (createProperties.SplinePoints != null)
{
Log.outError(LogFilter.Sql, $"Table `areatrigger` has listed AreaTriggerCreatePropertiesId (Id: {createPropertiesId.Id}, IsCustom: {createPropertiesId.IsCustom}) with splines");
Log.outError(LogFilter.Sql, $"Table `areatrigger` has listed AreaTriggerCreatePropertiesId (Id: {createPropertiesId.Id}, IsCustom: {createPropertiesId.IsCustom}) with {movementType}");
continue;
}
@@ -219,22 +219,20 @@ namespace Game.Entities
UpdateShape();
if (GetCreateProperties().OrbitInfo != null)
GetCreateProperties().Movement.Switch(
_ => SetUpdateFieldValue(areaTriggerData.ModifyValue(m_areaTriggerData.PathType), (byte)AreaTriggerPathType.None),
splineInfo => InitSplineOffsets(splineInfo),
orbitInfo =>
{
AreaTriggerOrbitInfo orbit = GetCreateProperties().OrbitInfo;
AreaTriggerOrbitInfo orbit = orbitInfo;
if (target != null && HasAreaTriggerFlag(AreaTriggerFieldFlags.Attached))
orbit.PathTarget = target.GetGUID();
else
orbit.Center = new(pos.posX, pos.posY, pos.posZ);
orbit.Center = pos;
InitOrbit(orbit, GetCreateProperties().Speed);
}
else if (GetCreateProperties().SplinePoints != null)
{
InitSplineOffsets(GetCreateProperties().SplinePoints);
}
else
SetUpdateFieldValue(areaTriggerData.ModifyValue(m_areaTriggerData.PathType), (byte)AreaTriggerPathType.None);
InitOrbit(orbit);
});
SetUpdateFieldValue(areaTriggerData.ModifyValue(m_areaTriggerData.Facing), _stationaryPosition.GetOrientation());
@@ -248,8 +248,7 @@ namespace Game.Entities
public AreaTriggerShapeInfo Shape = new();
public float Speed = 1.0f;
public List<Vector3> SplinePoints = new();
public AreaTriggerOrbitInfo OrbitInfo;
public OneOf<EmptyStruct, List<Vector3>, AreaTriggerOrbitInfo> Movement;
public uint ScriptId;
@@ -259,6 +258,8 @@ namespace Game.Entities
}
}
public struct EmptyStruct { }
public class AreaTriggerSpawn : SpawnData
{
public new AreaTriggerId Id;