Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion Core.SourceGen/ContentSerializerGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ private struct XnbPropertyInfo
public string TypeFullName;
public bool IsNullable;
public bool IsReferenceType;
public bool IsRequiredReferenceType;
public int Order;
public bool UseConverter;
public bool Optional;
Expand Down Expand Up @@ -106,7 +107,8 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
Name = member.Name,
TypeFullName = underlyingPropertyType.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat),
IsNullable = propertyNullable,
IsReferenceType = !propertyNullable && member.Type.IsReferenceType,
IsReferenceType = member.Type.IsReferenceType,
IsRequiredReferenceType = member.Type.IsReferenceType && member.NullableAnnotation == NullableAnnotation.NotAnnotated,
Order = order,
UseConverter = useConverter,
Optional = optional,
Expand Down Expand Up @@ -261,6 +263,16 @@ private static void EmitSerialize(CodeStringBuilder cb, XnbTypeInfo model)
{
cb.AppendLine($"var content = ({model.TypeFullName})data;");

foreach (var prop in model.Properties)
{
EmitRequiredPropertyValidation(cb, model, prop);
}

if (model.Properties.Any(prop => !prop.Optional && prop.IsRequiredReferenceType))
{
cb.AppendLine();
}

foreach (var prop in model.Properties)
{
EmitPropertySerialize(cb, prop);
Expand All @@ -269,6 +281,20 @@ private static void EmitSerialize(CodeStringBuilder cb, XnbTypeInfo model)
cb.EndCodeBlock();
}

private static void EmitRequiredPropertyValidation(CodeStringBuilder cb, XnbTypeInfo model, XnbPropertyInfo prop)
{
if (prop is { Optional: false, IsRequiredReferenceType: true })
{
cb.AppendLine($"if (content.{prop.Name} is null)");
cb.BeginCodeBlock();
{
cb.AppendLine(
$"throw new global::System.InvalidOperationException(\"Cannot serialize required XNB property {model.TypeName}.{prop.Name} because it is null.\");");
}
cb.EndCodeBlock();
}
}

private static void EmitPropertySerialize(CodeStringBuilder cb, XnbPropertyInfo prop)
{
var valueExpression = $"content.{prop.Name}";
Expand Down
4 changes: 2 additions & 2 deletions Core/Definitions/Game/ArtObject/ArtObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ public class ArtObject

[JsonIgnore]
[XnbProperty(UseConverter = true)]
public Texture2D Cubemap { get; set; } = new();
public Texture2D? Cubemap { get; set; }

[XnbProperty]
public Vector3 Size { get; set; }

[JsonIgnore]
[XnbProperty(UseConverter = true)]
public IndexedPrimitives<VertexInstance, Matrix> Geometry { get; set; } = new();
public IndexedPrimitives<VertexInstance, Matrix>? Geometry { get; set; }

[XnbProperty(UseConverter = true)]
public ActorType ActorType { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion Core/Definitions/Game/Graphics/AnimatedTexture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ public class AnimatedTexture
public byte[] TextureData { get; set; } = { };

[XnbProperty(UseConverter = true)]
public List<FrameContent> Frames { get; set; } = new();
public List<FrameContent>? Frames { get; set; } = new();
}
}
10 changes: 2 additions & 8 deletions Core/Definitions/Game/Graphics/IndexedPrimitives.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,9 @@ public class IndexedPrimitives<TemplateType, InstanceType>
public PrimitiveType PrimitiveType { get; set; }

[XnbProperty(UseConverter = true)]
public TemplateType[] Vertices { get; set; }
public TemplateType[]? Vertices { get; set; }

[XnbProperty(UseConverter = true)]
public ushort[] Indices { get; set; }

public IndexedPrimitives()
{
Vertices = new TemplateType[0];
Indices = new ushort[0];
}
public ushort[]? Indices { get; set; }
}
}
2 changes: 1 addition & 1 deletion Core/Definitions/Game/Level/AmbienceTrack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
public class AmbienceTrack
{
[XnbProperty(UseConverter = true)]
public string Name { get; set; } = "";
public string? Name { get; set; }

[XnbProperty]
public bool Day { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion Core/Definitions/Game/Level/ArtObjectActorSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public class ArtObjectActorSettings
public string? TreasureMapName { get; set; }

[XnbProperty(UseConverter = true)]
public FaceOrientation[] InvisibleSides { get; set; } = { };
public FaceOrientation[]? InvisibleSides { get; set; } = { };

[XnbProperty]
public float TimeswitchWindBackSpeed { get; set; }
Expand Down
6 changes: 3 additions & 3 deletions Core/Definitions/Game/Level/ArtObjectInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ public class ArtObjectInstance
public Vector3 Position { get; set; }

[XnbProperty]
public Quaternion Rotation { get; set; }
public Quaternion Rotation { get; set; } = Quaternion.Identity;

[XnbProperty]
public Vector3 Scale { get; set; }
public Vector3 Scale { get; set; } = Vector3.One;

[XnbProperty(UseConverter = true)]
public ArtObjectActorSettings? ActorSettings { get; set; }
public ArtObjectActorSettings? ActorSettings { get; set; } = new();
}
}
2 changes: 1 addition & 1 deletion Core/Definitions/Game/Level/DotDialogueLine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
public class DotDialogueLine
{
[XnbProperty(UseConverter = true)]
public string ResourceText { get; set; } = "";
public string? ResourceText { get; set; }

[XnbProperty]
public bool Grouped { get; set; }
Expand Down
26 changes: 13 additions & 13 deletions Core/Definitions/Game/Level/Level.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace FEZRepacker.Core.Definitions.Game.Level
public class Level
{
[XnbProperty(UseConverter = true)]
public string Name { get; set; } = "";
public string? Name { get; set; }

[XnbProperty]
public Vector3 Size { get; set; }
Expand All @@ -37,7 +37,7 @@ public class Level
public string? GomezHaloName { get; set; }

[XnbProperty]
public bool HaloFiltering { get; set; }
public bool HaloFiltering { get; set; } = true;

[XnbProperty]
public bool BlinkingAlpha { get; set; }
Expand All @@ -55,13 +55,13 @@ public class Level
public string SkyName { get; set; } = "";

[XnbProperty(UseConverter = true)]
public string TrileSetName { get; set; } = "";
public string? TrileSetName { get; set; }

[XnbProperty(UseConverter = true)]
public IDictionary<int, Volume> Volumes { get; set; } = new OrderedDictionary<int, Volume>();
public IDictionary<int, Volume>? Volumes { get; set; } = new OrderedDictionary<int, Volume>();

[XnbProperty(UseConverter = true)]
public IDictionary<int, Script> Scripts { get; set; } = new OrderedDictionary<int, Script>();
public IDictionary<int, Script>? Scripts { get; set; } = new OrderedDictionary<int, Script>();

[XnbProperty(UseConverter = true)]
public string? SongName { get; set; }
Expand All @@ -73,22 +73,22 @@ public class Level
public int FAPFadeOutLength { get; set; }

[XnbProperty(UseConverter = true)]
public IDictionary<TrileEmplacement, TrileInstance> Triles { get; set; } = new OrderedDictionary<TrileEmplacement, TrileInstance>();
public IDictionary<TrileEmplacement, TrileInstance>? Triles { get; set; } = new OrderedDictionary<TrileEmplacement, TrileInstance>();

[XnbProperty(UseConverter = true)]
public IDictionary<int, ArtObjectInstance> ArtObjects { get; set; } = new OrderedDictionary<int, ArtObjectInstance>();
public IDictionary<int, ArtObjectInstance>? ArtObjects { get; set; } = new OrderedDictionary<int, ArtObjectInstance>();

[XnbProperty(UseConverter = true)]
public IDictionary<int, BackgroundPlane> BackgroundPlanes { get; set; } = new OrderedDictionary<int, BackgroundPlane>();
public IDictionary<int, BackgroundPlane>? BackgroundPlanes { get; set; } = new OrderedDictionary<int, BackgroundPlane>();

[XnbProperty(UseConverter = true)]
public IDictionary<int, TrileGroup> Groups { get; set; } = new OrderedDictionary<int, TrileGroup>();
public IDictionary<int, TrileGroup>? Groups { get; set; } = new OrderedDictionary<int, TrileGroup>();

[XnbProperty(UseConverter = true)]
public IDictionary<int, NpcInstance> NonPlayerCharacters { get; set; } = new OrderedDictionary<int, NpcInstance>();
public IDictionary<int, NpcInstance>? NonPlayerCharacters { get; set; } = new OrderedDictionary<int, NpcInstance>();

[XnbProperty(UseConverter = true)]
public IDictionary<int, MovementPath> Paths { get; set; } = new OrderedDictionary<int, MovementPath>();
public IDictionary<int, MovementPath>? Paths { get; set; } = new OrderedDictionary<int, MovementPath>();

[XnbProperty]
public bool Descending { get; set; }
Expand All @@ -100,10 +100,10 @@ public class Level
public bool LowPass { get; set; }

[XnbProperty(UseConverter = true)]
public List<string> MutedLoops { get; set; } = new();
public List<string>? MutedLoops { get; set; } = new();

[XnbProperty(UseConverter = true)]
public List<AmbienceTrack> AmbienceTracks { get; set; } = new();
public List<AmbienceTrack>? AmbienceTracks { get; set; } = new();

[XnbProperty(UseConverter = true)]
public LevelNodeType NodeType { get; set; }
Expand Down
4 changes: 2 additions & 2 deletions Core/Definitions/Game/Level/MovementPath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
public class MovementPath
{
[XnbProperty(UseConverter = true)]
public List<PathSegment> Segments { get; set; } = new();
public List<PathSegment>? Segments { get; set; } = new();

[XnbProperty]
public bool NeedsTrigger { get; set; }
Expand All @@ -25,4 +25,4 @@ public class MovementPath
[XnbProperty]
public bool SaveTrigger { get; set; }
}
}
}
4 changes: 2 additions & 2 deletions Core/Definitions/Game/Level/NpcActionContent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
public class NpcActionContent
{
[XnbProperty(UseConverter = true)]
public string AnimationName { get; set; } = "";
public string? AnimationName { get; set; }

[XnbProperty(UseConverter = true)]
public string SoundName { get; set; } = "";
public string? SoundName { get; set; }
}
}
8 changes: 4 additions & 4 deletions Core/Definitions/Game/Level/NpcInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class NpcInstance
public Vector3 DestinationOffset { get; set; }

[XnbProperty]
public float WalkSpeed { get; set; }
public float WalkSpeed { get; set; } = 1.5f;

[XnbProperty]
public bool RandomizeSpeech { get; set; }
Expand All @@ -32,9 +32,9 @@ public class NpcInstance
public ActorType ActorType { get; set; }

[XnbProperty(UseConverter = true)]
public List<SpeechLine> Speech { get; set; } = null!;
public List<SpeechLine>? Speech { get; set; } = new();

[XnbProperty(UseConverter = true)]
public IDictionary<NpcAction, NpcActionContent> Actions { get; set; } = null!;
public IDictionary<NpcAction, NpcActionContent>? Actions { get; set; } = new FEZRepacker.Core.Helpers.OrderedDictionary<NpcAction, NpcActionContent>();
}
}
}
4 changes: 2 additions & 2 deletions Core/Definitions/Game/Level/Scripting/Script.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ public class Script
public TimeSpan? Timeout { get; set; }

[XnbProperty(UseConverter = true)]
public List<ScriptTrigger>? Triggers { get; set; }
public List<ScriptTrigger>? Triggers { get; set; } = new();

[XnbProperty(UseConverter = true)]
public List<ScriptCondition>? Conditions { get; set; }

[XnbProperty(UseConverter = true)]
public List<ScriptAction>? Actions { get; set; }
public List<ScriptAction>? Actions { get; set; } = new();

[XnbProperty]
public bool OneTime { get; set; }
Expand Down
4 changes: 2 additions & 2 deletions Core/Definitions/Game/Level/Scripting/ScriptAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
public class ScriptAction
{
[XnbProperty(UseConverter = true)]
public Entity Object { get; set; } = new();
public Entity? Object { get; set; } = new();

[XnbProperty]
public string Operation { get; set; } = "";

[XnbProperty(UseConverter = true)]
public string[] Arguments { get; set; } = { };
public string[]? Arguments { get; set; } = { };

[XnbProperty]
public bool Killswitch { get; set; } // whether action should kill this script
Expand Down
2 changes: 1 addition & 1 deletion Core/Definitions/Game/Level/Scripting/ScriptCondition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
public class ScriptCondition
{
[XnbProperty(UseConverter = true)]
public Entity Object { get; set; } = new();
public Entity? Object { get; set; } = new();

[XnbProperty(UseConverter = true)]
public ComparisonOperator Operator { get; set; } = ComparisonOperator.None;
Expand Down
2 changes: 1 addition & 1 deletion Core/Definitions/Game/Level/Scripting/ScriptTrigger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
public class ScriptTrigger
{
[XnbProperty(UseConverter = true)]
public Entity Object { get; set; } = new();
public Entity? Object { get; set; } = new();

[XnbProperty]
public string Event { get; set; } = "";
Expand Down
4 changes: 2 additions & 2 deletions Core/Definitions/Game/Level/SpeechLine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
public class SpeechLine
{
[XnbProperty(UseConverter = true)]
public string Text { get; set; } = "";
public string? Text { get; set; }

[XnbProperty(UseConverter = true)]
public NpcActionContent? OverrideContent { get; set; }
}
}
}
4 changes: 2 additions & 2 deletions Core/Definitions/Game/Level/TrileGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace FEZRepacker.Core.Definitions.Game.Level
public class TrileGroup
{
[XnbProperty(UseConverter = true)]
public List<TrileInstance> Triles { get; set; } = new();
public List<TrileInstance>? Triles { get; set; } = new();

[XnbProperty(UseConverter = true)]
public MovementPath? Path { get; set; } = null;
Expand Down Expand Up @@ -55,4 +55,4 @@ public class TrileGroup
[XnbProperty(UseConverter = true)]
public string? AssociatedSound { get; set; }
}
}
}
2 changes: 1 addition & 1 deletion Core/Definitions/Game/Level/Volume.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace FEZRepacker.Core.Definitions.Game.Level
public class Volume
{
[XnbProperty(UseConverter = true)]
public FaceOrientation[] Orientations { get; set; } = { };
public FaceOrientation[]? Orientations { get; set; } = { };

[XnbProperty]
public Vector3 From { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion Core/Definitions/Game/Level/VolumeActorSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class VolumeActorSettings
public bool IsPointOfInterest { get; set; }

[XnbProperty(UseConverter = true)]
public List<DotDialogueLine> DotDialogue { get; set; } = new();
public List<DotDialogueLine>? DotDialogue { get; set; } = new();

[XnbProperty]
public bool WaterLocked { get; set; }
Expand Down
4 changes: 2 additions & 2 deletions Core/Definitions/Game/MapTree/MapNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ public class MapNode
public string LevelName { get; set; } = "";

[XnbProperty(UseConverter = true)]
public List<MapNodeConnection> Connections { get; set; } = new();
public List<MapNodeConnection>? Connections { get; set; } = new();

[XnbProperty(UseConverter = true)]
public LevelNodeType NodeType { get; set; }

[XnbProperty(UseConverter = true)]
public WinConditions Conditions { get; set; } = new();
public WinConditions? Conditions { get; set; } = new();

[XnbProperty]
public bool HasLesserGate { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion Core/Definitions/Game/MapTree/MapNodeConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class MapNodeConnection
public FaceOrientation Face { get; set; }

[XnbProperty(UseConverter = true)]
public MapNode Node { get; set; } = new();
public MapNode? Node { get; set; } = new();

[XnbProperty]
public float BranchOversize { get;set; }
Expand Down
2 changes: 1 addition & 1 deletion Core/Definitions/Game/MapTree/MapTree.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
public class MapTree
{
[XnbProperty(UseConverter = true)]
public MapNode Root { get; set; } = new();
public MapNode? Root { get; set; }
}
}
Loading