Skip to content

Commit

Permalink
Made "internalList" private, replaced "internalList.Add()" with "AddD…
Browse files Browse the repository at this point in the history
…irect()"
  • Loading branch information
VladiStep committed Jan 24, 2023
1 parent 98558f6 commit 0d6055a
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
2 changes: 1 addition & 1 deletion UndertaleModLib/Models/UndertaleGameObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public UndertaleGameObject()
{
Events.SetCapacity(eventTypesLength);
for (int i = 0; i < eventTypesLength; i++)
Events.internalList.Add(new UndertalePointerList<Event>());
Events.AddDirect(new UndertalePointerList<Event>());
}

/// <inheritdoc />
Expand Down
4 changes: 2 additions & 2 deletions UndertaleModLib/Models/UndertaleRoom.cs
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,9 @@ public UndertaleRoom()
Backgrounds.SetCapacity(8);
Views.SetCapacity(8);
for (int i = 0; i < 8; i++)
Backgrounds.internalList.Add(new Background());
Backgrounds.AddDirect(new Background());
for (int i = 0; i < 8; i++)
Views.internalList.Add(new View());
Views.AddDirect(new View());
if (Flags.HasFlag(RoomEntryFlags.EnableViews))
Views[0].Enabled = true;
}
Expand Down
2 changes: 1 addition & 1 deletion UndertaleModLib/UndertaleChunkTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ internal override void UnserializeChunk(UndertaleReader reader)
if (reader.ReadByte() != 0)
throw new IOException("AlignUpdatedListChunk padding error");
}
List.internalList.Add(reader.ReadUndertaleObject<T>());
List.AddDirect(reader.ReadUndertaleObject<T>());
}
}
}
Expand Down
17 changes: 11 additions & 6 deletions UndertaleModLib/UndertaleLists.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace UndertaleModLib
{
public abstract class UndertaleListBase<T> : ObservableCollection<T>
{
public readonly List<T> internalList;
private readonly List<T> internalList;

public UndertaleListBase()
{
Expand Down Expand Up @@ -45,6 +45,11 @@ public void SetCapacity(int capacity)
}
}
public void SetCapacity(uint capacity) => SetCapacity((int)capacity);

public void AddDirect(T item)
{
internalList.Add(item);
}
}

public class UndertaleSimpleList<T> : UndertaleListBase<T>, UndertaleObject where T : UndertaleObject, new()
Expand Down Expand Up @@ -76,7 +81,7 @@ public override void Unserialize(UndertaleReader reader)
{
try
{
internalList.Add(reader.ReadUndertaleObject<T>());
AddDirect(reader.ReadUndertaleObject<T>());
}
catch (UndertaleSerializationException e)
{
Expand Down Expand Up @@ -115,7 +120,7 @@ public override void Unserialize(UndertaleReader reader)
{
try
{
internalList.Add(reader.ReadUndertaleString());
AddDirect(reader.ReadUndertaleString());
}
catch (UndertaleSerializationException e)
{
Expand Down Expand Up @@ -160,7 +165,7 @@ public override void Unserialize(UndertaleReader reader)
{
try
{
internalList.Add(reader.ReadUndertaleObject<T>());
AddDirect(reader.ReadUndertaleObject<T>());
EnsureShortCount();
}
catch (UndertaleSerializationException e)
Expand Down Expand Up @@ -221,7 +226,7 @@ public override void Unserialize(UndertaleReader reader)
{
try
{
internalList.Add(reader.ReadUndertaleObjectPointer<T>());
AddDirect(reader.ReadUndertaleObjectPointer<T>());
}
catch (UndertaleSerializationException e)
{
Expand Down Expand Up @@ -279,7 +284,7 @@ public void Unserialize(UndertaleReader reader, uint endPosition)
{
uint ptr = reader.ReadUInt32();
pointers.Add(ptr);
internalList.Add(reader.GetUndertaleObjectAtAddress<T>(ptr));
AddDirect(reader.GetUndertaleObjectAtAddress<T>(ptr));
}
catch (UndertaleSerializationException e)
{
Expand Down

0 comments on commit 0d6055a

Please sign in to comment.