Skip to content

Commit

Permalink
Update source gen reference
Browse files Browse the repository at this point in the history
  • Loading branch information
ds5678 committed May 1, 2024
1 parent bc861df commit 8c90f55
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 214 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AssetRipper.SourceGenerated" Version="1.0.12" />
<PackageReference Include="AssetRipper.SourceGenerated" Version="1.0.13" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="Moq" Version="4.20.70" />
<PackageReference Include="NUnit" Version="4.1.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,65 +110,17 @@ private static void HandleDifferingFields(IUnityObjectBase original, IUnityObjec
{
IGameObject newGameObject = (IGameObject)replacement;
PPtrConverter converter = new(gameObject, newGameObject);
if (gameObject.Has_Component_AssetList_AssetPair_Int32_PPtr_Component_3_5())
if (newGameObject.Components.Count > 0 && newGameObject.Components[0].Has_ClassID() && !gameObject.Components[0].Has_ClassID())
{
if (newGameObject.Has_Component_AssetList_AssetPair_Int32_PPtr_Component_5())
foreach (IComponentPair pair in newGameObject.Components)
{
foreach (AssetPair<int, PPtr_Component_3_5> pair in gameObject.Component_AssetList_AssetPair_Int32_PPtr_Component_3_5)
if (pair.Component.TryGetAsset(newGameObject.Collection, out IComponent? component))
{
AssetPair<int, PPtr_Component_5> newPair = newGameObject.Component_AssetList_AssetPair_Int32_PPtr_Component_5.AddNew();
newPair.Key = pair.Key;
newPair.Value.CopyValues(pair.Value, converter);
pair.ClassID = component.ClassID;
}
}
else if (newGameObject.Has_Component_AssetList_ComponentPair())
{
foreach (AssetPair<int, PPtr_Component_3_5> pair in gameObject.Component_AssetList_AssetPair_Int32_PPtr_Component_3_5)
{
newGameObject.Component_AssetList_ComponentPair.AddNew().Component.CopyValues(pair.Value, converter);
}
}
}
else if (gameObject.Has_Component_AssetList_AssetPair_Int32_PPtr_Component_5())
{
if (newGameObject.Has_Component_AssetList_AssetPair_Int32_PPtr_Component_3_5())
{
foreach (AssetPair<int, PPtr_Component_5> pair in gameObject.Component_AssetList_AssetPair_Int32_PPtr_Component_5)
{
AssetPair<int, PPtr_Component_3_5> newPair = newGameObject.Component_AssetList_AssetPair_Int32_PPtr_Component_3_5.AddNew();
newPair.Key = pair.Key;
newPair.Value.CopyValues(pair.Value, converter);
}
}
else if (newGameObject.Has_Component_AssetList_ComponentPair())
{
foreach (AssetPair<int, PPtr_Component_5> pair in gameObject.Component_AssetList_AssetPair_Int32_PPtr_Component_5)
{
newGameObject.Component_AssetList_ComponentPair.AddNew().Component.CopyValues(pair.Value, converter);
}
}
}
else
{
Debug.Assert(gameObject.Has_Component_AssetList_ComponentPair());
if (newGameObject.Has_Component_AssetList_AssetPair_Int32_PPtr_Component_3_5())
{
foreach (ComponentPair pair in gameObject.Component_AssetList_ComponentPair)
{
IComponent? component = gameObject.Collection.TryGetAsset<IComponent>(pair.Component);
AssetPair<int, PPtr_Component_3_5> newPair = newGameObject.Component_AssetList_AssetPair_Int32_PPtr_Component_3_5.AddNew();
newPair.Key = component?.ClassID ?? (int)ClassIDType.Component;
newPair.Value.SetAsset(newGameObject.Collection, component);
}
}
else if (newGameObject.Has_Component_AssetList_AssetPair_Int32_PPtr_Component_5())
{
foreach (ComponentPair pair in gameObject.Component_AssetList_ComponentPair)
else
{
IComponent? component = gameObject.Collection.TryGetAsset<IComponent>(pair.Component);
AssetPair<int, PPtr_Component_5> newPair = newGameObject.Component_AssetList_AssetPair_Int32_PPtr_Component_5.AddNew();
newPair.Key = component?.ClassID ?? (int)ClassIDType.Component;
newPair.Value.SetAsset(newGameObject.Collection, component);
pair.ClassID = (int)ClassIDType.Component;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="AssetRipper.SourceGenerated" Version="1.0.12" />
<PackageReference Include="AssetRipper.SourceGenerated" Version="1.0.13" />
</ItemGroup>

</Project>
170 changes: 13 additions & 157 deletions Source/AssetRipper.SourceGenerated.Extensions/GameObjectExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,86 +44,24 @@ public static void ConvertToEditorFormat(this IGameObject gameObject, ITagManage

public static IEnumerable<IPPtr_Component> FetchComponents(this IGameObject gameObject)
{
if (gameObject.Has_Component_AssetList_ComponentPair())
{
return gameObject.Component_AssetList_ComponentPair.Select(pair => pair.Component);
}
else if (gameObject.Has_Component_AssetList_AssetPair_Int32_PPtr_Component_3_5())
{
return gameObject.Component_AssetList_AssetPair_Int32_PPtr_Component_3_5.Select(pair => pair.Value);
}
else if (gameObject.Has_Component_AssetList_AssetPair_Int32_PPtr_Component_5())
{
return gameObject.Component_AssetList_AssetPair_Int32_PPtr_Component_5.Select(pair => pair.Value);
}
else
{
throw new Exception("All three component properties returned null");
}
return gameObject.Components.Select(pair => pair.Component);
}

public static AccessListBase<IPPtr_Component> GetComponentPPtrList(this IGameObject gameObject)
{
if (gameObject.Has_Component_AssetList_ComponentPair())
{
return new ComponentPairAccessList(gameObject.Component_AssetList_ComponentPair);
}
else if (gameObject.Has_Component_AssetList_AssetPair_Int32_PPtr_Component_3_5())
{
return new AssetPairAccessList<PPtr_Component_3_5>(gameObject.Component_AssetList_AssetPair_Int32_PPtr_Component_3_5);
}
else if (gameObject.Has_Component_AssetList_AssetPair_Int32_PPtr_Component_5())
{
return new AssetPairAccessList<PPtr_Component_5>(gameObject.Component_AssetList_AssetPair_Int32_PPtr_Component_5);
}
else
{
throw new Exception("All three component properties returned null");
}
return new ComponentPairAccessList(gameObject.Components);
}

public static int GetComponentCount(this IGameObject gameObject)
{
if (gameObject.Has_Component_AssetList_ComponentPair())
{
return gameObject.Component_AssetList_ComponentPair.Count;
}
else if (gameObject.Has_Component_AssetList_AssetPair_Int32_PPtr_Component_3_5())
{
return gameObject.Component_AssetList_AssetPair_Int32_PPtr_Component_3_5.Count;
}
else if (gameObject.Has_Component_AssetList_AssetPair_Int32_PPtr_Component_5())
{
return gameObject.Component_AssetList_AssetPair_Int32_PPtr_Component_5.Count;
}
else
{
throw new Exception("All three component properties returned null");
}
return gameObject.Components.Count;
}

public static void AddComponent(this IGameObject gameObject, ClassIDType classID, IComponent component)
{
if (gameObject.Has_Component_AssetList_ComponentPair())
{
gameObject.Component_AssetList_ComponentPair.AddNew().Component.SetAsset(gameObject.Collection, component);
}
else if (gameObject.Has_Component_AssetList_AssetPair_Int32_PPtr_Component_3_5())
{
AssetPair<int, PPtr_Component_3_5> pair = gameObject.Component_AssetList_AssetPair_Int32_PPtr_Component_3_5.AddNew();
pair.Key = (int)classID;
pair.Value.SetAsset(gameObject.Collection, component);
}
else if (gameObject.Has_Component_AssetList_AssetPair_Int32_PPtr_Component_5())
{
AssetPair<int, PPtr_Component_5> pair = gameObject.Component_AssetList_AssetPair_Int32_PPtr_Component_5.AddNew();
pair.Key = (int)classID;
pair.Value.SetAsset(gameObject.Collection, component);
}
else
{
throw new Exception("All three component properties returned null");
}
IComponentPair pair = gameObject.Components.AddNew();
pair.ClassID = (int)classID;
pair.Component.SetAsset(gameObject.Collection, component);
}

public static PPtrAccessList<IPPtr_Component, IComponent> GetComponentAccessList(this IGameObject gameObject)
Expand Down Expand Up @@ -262,9 +200,9 @@ public static IEnumerable<IEditorExtension> FetchHierarchy(this IGameObject root

private sealed class ComponentPairAccessList : AccessListBase<IPPtr_Component>
{
private readonly AssetList<ComponentPair> referenceList;
private readonly AccessListBase<IComponentPair> referenceList;

public ComponentPairAccessList(AssetList<ComponentPair> referenceList)
public ComponentPairAccessList(AccessListBase<IComponentPair> referenceList)
{
this.referenceList = referenceList;
}
Expand All @@ -286,7 +224,11 @@ public override void Add(IPPtr_Component item)

public override IPPtr_Component AddNew()
{
return referenceList.AddNew().Component;
IComponentPair componentPair = referenceList.AddNew();
componentPair.ClassID = (int)ClassIDType.Component;
return componentPair.Component;
//throw new NotSupportedException();
//Not sure the above code is safe since Unity might rely on the class id being correct.
}

public override void Clear()
Expand Down Expand Up @@ -341,91 +283,5 @@ public override void RemoveAt(int index)
referenceList.RemoveAt(index);
}
}

private sealed class AssetPairAccessList<T> : AccessListBase<IPPtr_Component> where T : IPPtr_Component, new()
{
private readonly AssetList<AssetPair<int, T>> referenceList;

public AssetPairAccessList(AssetList<AssetPair<int, T>> referenceList)
{
this.referenceList = referenceList;
}

public override IPPtr_Component this[int index]
{
get => referenceList[index].Value;
set => throw new NotSupportedException();
}

public override int Count => referenceList.Count;

public override int Capacity { get => referenceList.Capacity; set => referenceList.Capacity = value; }

public override void Add(IPPtr_Component item)
{
throw new NotSupportedException();
}

public override IPPtr_Component AddNew()
{
//AssetPair<int, T> pair = referenceList.AddNew();
//pair.Key = 2;
//return pair.Value;
throw new NotSupportedException();
//Not sure the above code is safe since Unity might rely on the class id being correct.
}

public override void Clear()
{
referenceList.Clear();
}

public override bool Contains(IPPtr_Component item)
{
return referenceList.Any(ptr => ptr.Value.Equals(item));
}

public override void CopyTo(IPPtr_Component[] array, int arrayIndex)
{
for (int i = 0; i < referenceList.Count; i++)
{
array[i + arrayIndex] = referenceList[i].Value;
}
}

public override int EnsureCapacity(int capacity)
{
return referenceList.EnsureCapacity(capacity);
}

public override int IndexOf(IPPtr_Component item)
{
return referenceList.IndexOf(pair => pair.Value.Equals(item));
}

public override void Insert(int index, IPPtr_Component item)
{
throw new NotSupportedException();
}

public override bool Remove(IPPtr_Component item)
{
int index = IndexOf(item);
if (index < 0)
{
return false;
}
else
{
RemoveAt(index);
return true;
}
}

public override void RemoveAt(int index)
{
referenceList.RemoveAt(index);
}
}
}
}
2 changes: 1 addition & 1 deletion Source/AssetRipper.Tests/Traversal/ComponentListObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace AssetRipper.Tests.Traversal;

internal sealed class ComponentListObject : CustomInjectedObjectBase
{
private readonly AssetList<ComponentPair> m_Component = new();
private readonly AssetList<ComponentPair_5_5> m_Component = new();

public const string Yaml = """
%YAML 1.1
Expand Down

0 comments on commit 8c90f55

Please sign in to comment.