Use explicit Optional<T> type for OptionalCFrame.
This commit is contained in:
parent
0e7f9030c8
commit
f421743b08
@ -414,9 +414,13 @@ namespace RobloxFiles.BinaryFormat.Chunks
|
||||
|
||||
for (int i = 0; i < instCount; i++)
|
||||
{
|
||||
var cf = CFrames[i];
|
||||
bool active = reader.ReadBoolean();
|
||||
CFrames[i] = active ? cf : null;
|
||||
CFrame cf = CFrames[i];
|
||||
bool archivable = reader.ReadBoolean();
|
||||
|
||||
if (!archivable)
|
||||
cf = null;
|
||||
|
||||
CFrames[i] = new Optional<CFrame>(cf);
|
||||
}
|
||||
}
|
||||
|
||||
@ -984,7 +988,14 @@ namespace RobloxFiles.BinaryFormat.Chunks
|
||||
return;
|
||||
}
|
||||
|
||||
writer.Write(true);
|
||||
if (prop.Value is Optional<CFrame> optional)
|
||||
{
|
||||
writer.Write(optional.HasValue);
|
||||
return;
|
||||
}
|
||||
|
||||
var cf = prop.Value as CFrame;
|
||||
writer.Write(cf != null);
|
||||
});
|
||||
}
|
||||
|
||||
|
35
DataTypes/Optional.cs
Normal file
35
DataTypes/Optional.cs
Normal file
@ -0,0 +1,35 @@
|
||||
namespace RobloxFiles.DataTypes
|
||||
{
|
||||
// Optional represents a value that can be explicitly
|
||||
// marked as an optional variant to a specified type.
|
||||
// In practice this is used for OptionalCFrame.
|
||||
|
||||
public struct Optional<T>
|
||||
{
|
||||
public T Value;
|
||||
public bool HasValue => (Value != null);
|
||||
|
||||
public Optional(T value)
|
||||
{
|
||||
Value = value;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Value?.ToString() ?? "null";
|
||||
}
|
||||
|
||||
public static implicit operator T(Optional<T> optional)
|
||||
{
|
||||
if (optional.HasValue)
|
||||
return optional.Value;
|
||||
|
||||
return default(T);
|
||||
}
|
||||
|
||||
public static implicit operator Optional<T>(T value)
|
||||
{
|
||||
return new Optional<T>(value);
|
||||
}
|
||||
}
|
||||
}
|
@ -2408,7 +2408,7 @@ namespace RobloxFiles
|
||||
public Vector3 ModelMeshSize = new Vector3();
|
||||
public bool NeedsPivotMigration;
|
||||
public BasePart PrimaryPart;
|
||||
public CFrame WorldPivotData;
|
||||
public Optional<CFrame> WorldPivotData;
|
||||
}
|
||||
|
||||
public class Actor : Model
|
||||
|
Binary file not shown.
@ -378,7 +378,7 @@ return
|
||||
ModelMeshData = "SharedString";
|
||||
ModelMeshSize = "Vector3";
|
||||
NeedsPivotMigration = "bool";
|
||||
WorldPivotData = "OptionalCFrame";
|
||||
WorldPivotData = "Optional<CFrame>";
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -640,10 +640,6 @@ local function generateClasses()
|
||||
|
||||
writeLine("[Obsolete]")
|
||||
end
|
||||
|
||||
if valueType == "OptionalCFrame" then
|
||||
valueType = "CFrame"
|
||||
end
|
||||
|
||||
writeLine("public %s %s%s;", valueType, name, default)
|
||||
|
||||
|
@ -89,6 +89,7 @@
|
||||
<Compile Include="BinaryFormat\IO\BinaryFileReader.cs" />
|
||||
<Compile Include="BinaryFormat\IO\BinaryFileWriter.cs" />
|
||||
<Compile Include="DataTypes\Color3uint8.cs" />
|
||||
<Compile Include="DataTypes\Optional.cs" />
|
||||
<Compile Include="DataTypes\ProtectedString.cs" />
|
||||
<Compile Include="DataTypes\Content.cs" />
|
||||
<Compile Include="DataTypes\Region3int16.cs" />
|
||||
|
Binary file not shown.
@ -599,7 +599,7 @@ namespace RobloxFiles
|
||||
propType = Property.Types[fieldType];
|
||||
else if (fieldType.IsEnum)
|
||||
propType = PropertyType.Enum;
|
||||
|
||||
|
||||
if (propType != PropertyType.Unknown)
|
||||
{
|
||||
if (fieldName.EndsWith("_"))
|
||||
@ -615,24 +615,35 @@ namespace RobloxFiles
|
||||
case "String":
|
||||
case "Double":
|
||||
case "Int64":
|
||||
{
|
||||
xmlToken = xmlToken.ToLowerInvariant();
|
||||
break;
|
||||
}
|
||||
case "Boolean":
|
||||
{
|
||||
xmlToken = "bool";
|
||||
break;
|
||||
}
|
||||
case "Single":
|
||||
{
|
||||
xmlToken = "float";
|
||||
break;
|
||||
}
|
||||
case "Int32":
|
||||
{
|
||||
xmlToken = "int";
|
||||
break;
|
||||
}
|
||||
case "Rect":
|
||||
{
|
||||
xmlToken = "Rect2D";
|
||||
break;
|
||||
}
|
||||
case "CFrame":
|
||||
{
|
||||
xmlToken = "CoordinateFrame";
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!props.ContainsKey(fieldName))
|
||||
|
@ -88,8 +88,9 @@ namespace RobloxFiles
|
||||
{ typeof(SharedString), PropertyType.SharedString },
|
||||
{ typeof(Vector3int16), PropertyType.Vector3int16 },
|
||||
|
||||
{ typeof(ColorSequence), PropertyType.ColorSequence },
|
||||
{ typeof(NumberSequence), PropertyType.NumberSequence },
|
||||
{ typeof(ColorSequence), PropertyType.ColorSequence },
|
||||
{ typeof(NumberSequence), PropertyType.NumberSequence },
|
||||
{ typeof(Optional<CFrame>), PropertyType.OptionalCFrame },
|
||||
|
||||
{ typeof(ProtectedString), PropertyType.String },
|
||||
{ typeof(PhysicalProperties), PropertyType.PhysicalProperties },
|
||||
|
Loading…
Reference in New Issue
Block a user