Skip to content

Commit

Permalink
Addressed @Miepee comments
Browse files Browse the repository at this point in the history
  • Loading branch information
VladiStep committed Jun 25, 2022
1 parent 38ee488 commit 4068224
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
26 changes: 13 additions & 13 deletions UndertaleModLib/UndertaleData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -385,19 +385,19 @@ public class UndertaleData : IDisposable
public bool GMLCacheIsReady { get; set; } = true;

/// <summary>
/// An array of a <see cref="UndertaleData"/> properties with <see cref="IList{T}"/> type.
/// An array of a <see cref="UndertaleData"/> properties with <see cref="IList{T}"/> as their type.
/// </summary>
public PropertyInfo[] ListProperties { get; private set; }
public PropertyInfo[] AllListProperties { get; private set; }

/// <summary>
/// Initializes new <see cref="UndertaleData"/> instance.
/// </summary>
public UndertaleData()
{
ListProperties = GetType().GetProperties()
.Where(x => x.PropertyType.IsGenericType
&& x.PropertyType.GetGenericTypeDefinition() == typeof(IList<>))
.ToArray();
AllListProperties = GetType().GetProperties()
.Where(x => x.PropertyType.IsGenericType
&& x.PropertyType.GetGenericTypeDefinition() == typeof(IList<>))
.ToArray();
}

/// <summary>
Expand Down Expand Up @@ -437,11 +437,11 @@ public UndertaleNamedResource ByName(string name, bool ignoreCase = false)
public int IndexOf(UndertaleResource obj, bool panicIfInvalid = true)
{
Type objType = obj.GetType();
PropertyInfo objListProp = ListProperties.FirstOrDefault(x => x.PropertyType.GetGenericArguments()[0] == objType);
if (objListProp is not null)
{
if (objListProp.GetValue(this) is IList list)
return list.IndexOf(obj);
PropertyInfo objListPropInfo = AllListProperties.FirstOrDefault(x => x.PropertyType.GetGenericArguments()[0] == objType);
if (objListPropInfo is not null)
{
if (objListPropInfo.GetValue(this) is IList list)
return list.IndexOf(obj);
}

if (panicIfInvalid)
Expand Down Expand Up @@ -605,7 +605,7 @@ public void Dispose()

Type disposableType = typeof(IDisposable);
PropertyInfo[] dataProperties = GetType().GetProperties();
var dataDisposableProps = dataProperties.Except(ListProperties)
var dataDisposableProps = dataProperties.Except(AllListProperties)
.Where(x => disposableType.IsAssignableFrom(x.PropertyType));

// Dispose disposable properties
Expand All @@ -619,7 +619,7 @@ public void Dispose()
}

// Clear all object lists (sprites, code, etc.)
foreach (PropertyInfo dataListProperty in ListProperties)
foreach (PropertyInfo dataListProperty in AllListProperties)
{
// If list is null
if (dataListProperty.GetValue(this) is not IList list)
Expand Down
18 changes: 9 additions & 9 deletions UndertaleModTool/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3081,15 +3081,15 @@ private void SearchBox_TextChanged(object sender, TextChangedEventArgs e)

public void UpdateObjectLabel(object obj)
{
int foundIndex = obj is UndertaleResource res
? Data.IndexOf(res, false)
: -1;
string idString = foundIndex == -1
? "None"
: (foundIndex == -2
? "N/A"
: Convert.ToString(foundIndex)
);
int foundIndex = obj is UndertaleResource res ? Data.IndexOf(res, false) : -1;
string idString;

if (foundIndex == -1)
idString = "None";
else if (foundIndex == -2)
idString = "N/A";
else
idString = Convert.ToString(foundIndex);

SetIDString(idString);
}
Expand Down

0 comments on commit 4068224

Please sign in to comment.