Skip to content

Commit 286a2a6

Browse files
committed
feat: use full assembly qualifier naming in xnbs
1 parent 12e3594 commit 286a2a6

84 files changed

Lines changed: 200 additions & 173 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Core.SourceGen/ContentSerializerGenerator.cs

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ private struct XnbTypeInfo
1818
public string TypeName;
1919
public string TypeFullName;
2020
public string QualifierString;
21-
public List<string> GenericParameters;
2221
public List<XnbPropertyInfo> Properties;
2322
}
2423

@@ -51,19 +50,32 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
5150
return null;
5251
}
5352

53+
if (typeSymbol.IsGenericType)
54+
{
55+
return null;
56+
}
57+
5458
var xnbReaderTypeAttribute = typeSymbol.GetAttributes()
5559
.FirstOrDefault(a => a.AttributeClass?.ToDisplayString() == XnbReaderTypeAttributeName);
5660

5761
if (xnbReaderTypeAttribute is not {ConstructorArguments.Length: > 0})
5862
{
5963
return null;
6064
}
65+
66+
bool useBaseClass = xnbReaderTypeAttribute.NamedArguments
67+
.FirstOrDefault(x => x.Key == "UseBaseClass").Value.Value is true;
68+
69+
var logicalTypeSymbol = typeSymbol;
70+
if (useBaseClass && typeSymbol.BaseType is not null)
71+
{
72+
logicalTypeSymbol = typeSymbol.BaseType;
73+
}
6174

6275
var qualifierString = xnbReaderTypeAttribute.ConstructorArguments[0].Value as string ?? string.Empty;
63-
var genericParameters = typeSymbol.TypeParameters.Select(tp => tp.Name).ToList();
6476
var properties = new List<XnbPropertyInfo>();
6577

66-
foreach (var member in typeSymbol.GetMembers().OfType<IPropertySymbol>())
78+
foreach (var member in logicalTypeSymbol.GetMembers().OfType<IPropertySymbol>())
6779
{
6880
ct.ThrowIfCancellationRequested();
6981

@@ -84,21 +96,21 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
8496
bool skipIdentifier = xnbPropertyAttribute.NamedArguments
8597
.FirstOrDefault(x => x.Key == "SkipIdentifier").Value.Value is true;
8698

87-
ITypeSymbol underlyingType = member.Type;
88-
bool isNullableValueType = false;
99+
ITypeSymbol underlyingPropertyType = member.Type;
100+
bool propertyNullable = false;
89101

90102
if (member.Type is INamedTypeSymbol {ConstructedFrom.SpecialType: SpecialType.System_Nullable_T} namedType)
91103
{
92-
underlyingType = namedType.TypeArguments[0];
93-
isNullableValueType = true;
104+
underlyingPropertyType = namedType.TypeArguments[0];
105+
propertyNullable = true;
94106
}
95107

96108
properties.Add(new XnbPropertyInfo
97109
{
98110
Name = member.Name,
99-
TypeFullName = underlyingType.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat),
100-
IsNullable = isNullableValueType,
101-
IsReferenceType = !isNullableValueType && member.Type.IsReferenceType,
111+
TypeFullName = underlyingPropertyType.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat),
112+
IsNullable = propertyNullable,
113+
IsReferenceType = !propertyNullable && member.Type.IsReferenceType,
102114
Order = order,
103115
UseConverter = useConverter,
104116
Optional = optional,
@@ -111,10 +123,9 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
111123
return new XnbTypeInfo
112124
{
113125
TypeName = typeSymbol.Name,
114-
TypeFullName = typeSymbol.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat),
126+
TypeFullName = logicalTypeSymbol.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat),
115127
QualifierString = qualifierString,
116128
Properties = properties,
117-
GenericParameters = genericParameters
118129
};
119130
}
120131

@@ -137,7 +148,7 @@ private static void EmitSerializer(CodeStringBuilder cb, XnbTypeInfo xnbTypeInfo
137148
cb.AppendLine();
138149
cb.AppendLine("namespace FEZRepacker.Core.XNB.ContentSerialization;");
139150
cb.AppendLine();
140-
cb.Append($"internal sealed class {ConstructSerializerName(xnbTypeInfo)}");
151+
cb.Append($"internal sealed class {xnbTypeInfo.TypeName}ContentSerializer");
141152
cb.AppendLine($" : XnbContentSerializer<{xnbTypeInfo.TypeFullName}>");
142153
cb.BeginCodeBlock();
143154
{
@@ -150,17 +161,6 @@ private static void EmitSerializer(CodeStringBuilder cb, XnbTypeInfo xnbTypeInfo
150161
cb.EndCodeBlock();
151162
}
152163

153-
private static string ConstructSerializerName(XnbTypeInfo xnbTypeInfo)
154-
{
155-
var name = $"{xnbTypeInfo.TypeName}ContentSerializer";
156-
if (xnbTypeInfo.GenericParameters.Count > 0)
157-
{
158-
var genericParametersList = string.Join(", " , xnbTypeInfo.GenericParameters);
159-
name += $"<{genericParametersList}>";
160-
}
161-
return name;
162-
}
163-
164164
private static void EmitDeserialize(CodeStringBuilder cb, XnbTypeInfo model)
165165
{
166166
cb.AppendLine("public override object Deserialize(XnbContentReader reader)");

Core/Definitions/Game/ArtObject/ArtObject.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88
namespace FEZRepacker.Core.Definitions.Game.ArtObject
99
{
10-
[XnbType("FezEngine.Structure.ArtObject")]
11-
[XnbReaderType("FezEngine.Readers.ArtObjectReader")]
10+
[XnbType("FezEngine.Structure.ArtObject, FezEngine, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null")]
11+
[XnbReaderType("FezEngine.Readers.ArtObjectReader, FezEngine")]
1212
public class ArtObject
1313
{
1414
[XnbProperty]

Core/Definitions/Game/ArtObject/VertexInstance.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
namespace FEZRepacker.Core.Definitions.Game.ArtObject
44
{
5-
[XnbType("FezEngine.Structure.Geometry.VertexPositionNormalTextureInstance")]
6-
[XnbReaderType("FezEngine.Readers.VertexPositionNormalTextureInstanceReader")]
5+
[XnbType("FezEngine.Structure.Geometry.VertexPositionNormalTextureInstance, FezEngine, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null")]
6+
[XnbReaderType("FezEngine.Readers.VertexPositionNormalTextureInstanceReader, FezEngine")]
77
// Original name in FezEngine: VertexPositionNormalTextureInstance
88
public class VertexInstance
99
{

Core/Definitions/Game/Common/ActorType.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
namespace FEZRepacker.Core.Definitions.Game.Common
22
{
3-
[XnbType("FezEngine.Structure.ActorType")]
3+
[XnbType("FezEngine.Structure.ActorType, FezEngine, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null")]
44
public enum ActorType
55
{
66
None,

Core/Definitions/Game/Common/FaceOrientation.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
namespace FEZRepacker.Core.Definitions.Game.Common
22
{
3-
[XnbType("FezEngine.FaceOrientation")]
3+
[XnbType("FezEngine.FaceOrientation, FezEngine, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null")]
44
public enum FaceOrientation
55
{
66
Left,

Core/Definitions/Game/Common/LevelNodeType.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
namespace FEZRepacker.Core.Definitions.Game.Common
22
{
3-
[XnbType("FezEngine.LevelNodeType")]
3+
[XnbType("FezEngine.LevelNodeType, FezEngine, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null")]
44
public enum LevelNodeType
55
{
66
Node,

Core/Definitions/Game/Common/NpcAction.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
namespace FEZRepacker.Core.Definitions.Game.Common
22
{
3-
[XnbType("FezEngine.Structure.NpcAction")]
3+
[XnbType("FezEngine.Structure.NpcAction, FezEngine, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null")]
44
public enum NpcAction
55
{
66
None,

Core/Definitions/Game/Graphics/AnimatedTexture.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
namespace FEZRepacker.Core.Definitions.Game.Graphics
22
{
3-
[XnbType("FezEngine.Structure.AnimatedTexture")]
4-
[XnbReaderType("FezEngine.Readers.AnimatedTextureReader")]
3+
[XnbType("FezEngine.Structure.AnimatedTexture, FezEngine, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null")]
4+
[XnbReaderType("FezEngine.Readers.AnimatedTextureReader, FezEngine")]
55
public class AnimatedTexture
66
{
77
// Definition has been altered since the Texture property is

Core/Definitions/Game/Graphics/FrameContent.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
namespace FEZRepacker.Core.Definitions.Game.Graphics
55
{
6-
[XnbType("FezEngine.Content.FrameContent")]
7-
[XnbReaderType("FezEngine.Readers.FrameReader")]
6+
[XnbType("FezEngine.Content.FrameContent, FezEngine, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null")]
7+
[XnbReaderType("FezEngine.Readers.FrameReader, FezEngine")]
88
public class FrameContent
99
{
1010
[XnbProperty(UseConverter = true)]

Core/Definitions/Game/Graphics/IndexedPrimitives.cs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
using FEZRepacker.Core.Definitions.Game.XNA;
1+
using FEZRepacker.Core.Definitions.Game.ArtObject;
2+
using FEZRepacker.Core.Definitions.Game.XNA;
23

34
namespace FEZRepacker.Core.Definitions.Game.Graphics
45
{
5-
[XnbType("FezEngine.Structure.Geometry.ShaderInstancedIndexedPrimitives")]
6-
[XnbReaderType("FezEngine.Readers.ShaderInstancedIndexedPrimitivesReader")]
6+
[XnbType("FezEngine.Structure.Geometry.ShaderInstancedIndexedPrimitives, FezEngine, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null")]
7+
[XnbReaderType("FezEngine.Readers.ShaderInstancedIndexedPrimitivesReader, FezEngine")]
78
// Original name in FezEngine: ShaderInstancedIndexedPrimitives
89
public class IndexedPrimitives<TemplateType, InstanceType>
910
{
@@ -22,4 +23,21 @@ public IndexedPrimitives()
2223
Indices = new ushort[0];
2324
}
2425
}
26+
27+
28+
/* Helper subclasses for serialization sourcegen - easier to control qualifier name this way. */
29+
30+
[XnbReaderType("FezEngine.Readers.ShaderInstancedIndexedPrimitivesReader`2" +
31+
"[[FezEngine.Structure.Geometry.VertexPositionNormalTextureInstance, FezEngine]," +
32+
"[Microsoft.Xna.Framework.Matrix, Microsoft.Xna.Framework, Version=4.0.0.0, " +
33+
"Culture=neutral, PublicKeyToken=842cf8be1de50553]], FezEngine",
34+
UseBaseClass = true)]
35+
internal class ArtObjectIndexedPrimitives : IndexedPrimitives<VertexInstance, Matrix>;
36+
37+
[XnbReaderType("FezEngine.Readers.ShaderInstancedIndexedPrimitivesReader`2" +
38+
"[[FezEngine.Structure.Geometry.VertexPositionNormalTextureInstance, FezEngine]," +
39+
"[Microsoft.Xna.Framework.Vector4, Microsoft.Xna.Framework, Version=4.0.0.0, " +
40+
"Culture=neutral, PublicKeyToken=842cf8be1de50553]], FezEngine",
41+
UseBaseClass = true)]
42+
internal class TrileSetIndexedPrimitives : IndexedPrimitives<VertexInstance, Vector4>;
2543
}

0 commit comments

Comments
 (0)