79 lines
2.0 KiB
C#
Raw Normal View History

2024-06-11 23:07:59 -04:00
using AssemblyRemapper.Utils;
2024-06-11 19:18:48 -04:00
using Mono.Cecil;
namespace AssemblyRemapper.Models;
internal class ScoringModel
{
public string ProposedNewName { get; set; }
2024-06-12 00:05:59 -04:00
public int Score { get; set; } = 0;
2024-06-11 19:18:48 -04:00
public TypeDefinition Definition { get; set; }
2024-06-12 00:05:59 -04:00
public RemapModel RemapModel { get; internal set; }
2024-06-11 19:18:48 -04:00
public ScoringModel()
{
}
}
internal static class ScoringModelExtensions
{
public static void AddModelToResult(this ScoringModel model)
{
try
{
2024-06-11 23:07:59 -04:00
if (DataProvider.ScoringModels.TryGetValue(model.ProposedNewName, out HashSet<ScoringModel> modelHashset))
2024-06-11 19:18:48 -04:00
{
2024-06-11 23:07:59 -04:00
foreach (var outVal in modelHashset)
{
if (outVal.Definition.FullName == model.Definition.FullName)
{
Logger.Log("Skipping adding duplicate type match to list", ConsoleColor.Yellow);
return;
}
}
2024-06-11 19:18:48 -04:00
modelHashset.Add(model);
return;
}
var newHash = new HashSet<ScoringModel>
{
model
};
2024-06-11 23:07:59 -04:00
DataProvider.ScoringModels.Add(model.ProposedNewName, newHash);
2024-06-11 19:18:48 -04:00
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
}
2024-06-12 15:47:11 -04:00
public static int CalculateMaxScore(this ScoringModel score)
{
// Score should never be null here, but if it is we're fucked so just return 0.
if (score == null) { return 0; }
var propInfos = typeof(SearchParams).GetProperties();
int maxScore = 0;
foreach (var propInfo in propInfos)
{
object value = propInfo.GetValue(score.RemapModel.SearchParams);
if (value == null) continue;
if (value is HashSet<string> hashset)
{
maxScore += hashset.Count * 2;
}
else
{
maxScore++;
}
}
return maxScore;
}
2024-06-11 19:18:48 -04:00
}