Skip to content

Commit

Permalink
fixes serialization of nested generics
Browse files Browse the repository at this point in the history
  • Loading branch information
saint11 committed May 11, 2024
1 parent fdb23b6 commit 214b84e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 10 deletions.
5 changes: 4 additions & 1 deletion src/Murder.Editor/EditorScene_Shortcuts.cs
Expand Up @@ -169,7 +169,10 @@ private void DrawMainMenuBar()
if (Game.Input.Shortcut(Keys.W, _leftOsActionModifier) ||
Game.Input.Shortcut(Keys.W, _rightOsActionModifier))
{
CloseTab(_selectedAssets[_selectedTab]);
if (_selectedAssets.Count > 0)
{
CloseTab(_selectedAssets[_selectedTab]);
}
}

if (Game.Input.Shortcut(Keys.F, _leftOsActionModifier) ||
Expand Down
33 changes: 24 additions & 9 deletions src/Murder.Serializer/Metadata/MetadataFetcher.cs
Expand Up @@ -375,7 +375,7 @@ private void AddPendingPolymorphicType(INamedTypeSymbol t)

private IEnumerable<INamedTypeSymbol> FetchComponents(
MurderTypeSymbols symbols,
IEnumerable<INamedTypeSymbol> allValueTypesToBeCompiled) =>
IEnumerable<INamedTypeSymbol> allValueTypesToBeCompiled) =>
allValueTypesToBeCompiled
.Where(t => !t.IsGenericType && t.ImplementsInterface(symbols.ComponentInterface))
.OrderBy(c => c.Name);
Expand Down Expand Up @@ -536,15 +536,30 @@ private void LookForPrivateCandidateFields(MurderTypeSymbols murderSymbols, ITyp
ComplexDictionaries.Add(args);
}

foreach (INamedTypeSymbol a in memberNamedType.TypeArguments)
{
if (IsPolymorphicCandidate(murderSymbols, a))
{
AddPendingPolymorphicType(a);
}
TrackAllGenericArguments(murderSymbols, memberNamedType);
}
}
}

MaybeLookForPrivateFields(murderSymbols, a);
}
/// <summary>
/// Track all the generic arguments of a generic <paramref name="symbol"/>.
/// </summary>
private void TrackAllGenericArguments(MurderTypeSymbols murderSymbols, INamedTypeSymbol symbol)
{
foreach (INamedTypeSymbol a in symbol.TypeArguments)
{
if (IsPolymorphicCandidate(murderSymbols, a))
{
AddPendingPolymorphicType(a);
}

MaybeLookForPrivateFields(murderSymbols, a);

// This might happen for nested generics, e.g.:
// ImmutableArray<A>? will be: Nullable<ImmutableArray<a>> and we will need to recurse over it twice.
if (a.IsGenericType)
{
TrackAllGenericArguments(murderSymbols, a);
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/Murder/Core/Geometry/IntRectangle.cs
@@ -1,4 +1,5 @@
using Murder.Utilities;
using System.ComponentModel;
using System.Numerics;
using System.Text.Json.Serialization;

Expand Down Expand Up @@ -56,6 +57,7 @@ public Point Size
public IntRectangle AddPosition(Vector2 position) => new IntRectangle(X + Calculator.RoundToInt(position.X), Y + Calculator.RoundToInt(position.Y), Width, Height);
public IntRectangle AddPosition(Point position) => new IntRectangle(X + position.X, Y + position.Y, Width, Height);
public IntRectangle Expand(int value) => new IntRectangle(X - value, Y - value, Width + value * 2, Height + value * 2);
public IntRectangle Expand(int x, int y) => new IntRectangle(X - x, Y - y, Width + x * 2, Height + y * 2);
public IntRectangle Expand(float value) => new IntRectangle(X - value, Y - value, Width + value * 2, Height + value * 2);

public IntRectangle(Point position, Point size)
Expand Down

0 comments on commit 214b84e

Please sign in to comment.