Add CoreInventory.SystemsFlat list and use in UI gen elsewhere

This commit is contained in:
YoshiRulz 2020-10-14 08:31:06 +10:00
parent fca37ddccf
commit ed4ddb13ce
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
3 changed files with 17 additions and 23 deletions

View File

@ -4,7 +4,7 @@ using System.Linq;
using System.Windows.Forms;
using BizHawk.Client.EmuHawk.Properties;
using BizHawk.Common;
using BizHawk.Emulation.Common;
using BizHawk.Emulation.Cores;
namespace BizHawk.Client.EmuHawk
{
@ -46,16 +46,10 @@ namespace BizHawk.Client.EmuHawk
VersionLabel.Text = $"Version {mainVersion}";
DateLabel.Text = VersionInfo.ReleaseDate;
var cores = Emulation.Cores.ReflectionCache.Types
.Where(t => typeof(IEmulator).IsAssignableFrom(t))
.Select(t => t.GetCustomAttributes(false).OfType<CoreAttribute>().FirstOrDefault())
.Where(a => a != null)
.Where(a => a.Released)
.OrderByDescending(a => a.CoreName.ToLower());
foreach (var core in cores)
foreach (var core in CoreInventory.Instance.SystemsFlat.Where(core => core.CoreAttr.Released)
.OrderByDescending(core => core.Name.ToLowerInvariant()))
{
CoreInfoPanel.Controls.Add(new BizBoxInfoControl(core)
CoreInfoPanel.Controls.Add(new BizBoxInfoControl(core.CoreAttr)
{
Dock = DockStyle.Top
});

View File

@ -7,6 +7,7 @@ using System.Reflection;
using BizHawk.Client.Common;
using BizHawk.Emulation.Common;
using BizHawk.Emulation.Cores;
namespace BizHawk.Client.EmuHawk
{
@ -201,15 +202,9 @@ namespace BizHawk.Client.EmuHawk
CoreTree.ImageList.Images.Add("Bad", Properties.Resources.ExclamationRed);
CoreTree.ImageList.Images.Add("Unknown", Properties.Resources.RetroQuestion);
var possibleCoreTypes = Emulation.Cores.ReflectionCache.Types
.Where(t => typeof(IEmulator).IsAssignableFrom(t) && !t.IsAbstract)
.Select(t => new
{
Type = t,
CoreAttributes = (CoreAttribute)t.GetCustomAttributes(typeof(CoreAttribute), false).First()
})
.OrderByDescending(t => t.CoreAttributes.Released)
.ThenBy(t => t.CoreAttributes.CoreName)
var possibleCoreTypes = CoreInventory.Instance.SystemsFlat
.OrderByDescending(core => core.CoreAttr.Released)
.ThenBy(core => core.Name)
.ToList();
toolStripStatusLabel1.Text = $"Total: {possibleCoreTypes.Count} Released: {KnownCores.Values.Count(c => c.Released)} Profiled: {KnownCores.Count}";
@ -228,15 +223,15 @@ namespace BizHawk.Client.EmuHawk
CoreTree.Nodes.Add(coreNode);
}
foreach (var t in possibleCoreTypes)
foreach (var core in possibleCoreTypes)
{
if (!KnownCores.ContainsKey(t.CoreAttributes.CoreName))
if (!KnownCores.ContainsKey(core.Name))
{
string img = "Unknown";
var coreNode = new TreeNode
{
Text = t.CoreAttributes.CoreName + (t.CoreAttributes.Released ? "" : " (UNRELEASED)"),
ForeColor = t.CoreAttributes.Released ? Color.Black : Color.DarkGray,
Text = core.Name + (core.CoreAttr.Released ? "" : " (UNRELEASED)"),
ForeColor = core.CoreAttr.Released ? Color.Black : Color.DarkGray,
ImageKey = img,
SelectedImageKey = img,
StateImageKey = img

View File

@ -13,6 +13,8 @@ namespace BizHawk.Emulation.Cores
{
private readonly Dictionary<string, List<Core>> _systems = new Dictionary<string, List<Core>>();
public readonly IReadOnlyCollection<Core> SystemsFlat;
public class Core
{
private class RomGameFake : IRomAsset
@ -135,6 +137,7 @@ namespace BizHawk.Emulation.Cores
/// </summary>
public CoreInventory(IEnumerable<IEnumerable<Type>> assys)
{
var systemsFlat = new Dictionary<Type, Core>();
void ProcessConstructor(Type type, CoreConstructorAttribute consAttr, CoreAttribute coreAttr, ConstructorInfo cons)
{
var core = new Core(type, consAttr, coreAttr, cons);
@ -145,6 +148,7 @@ namespace BizHawk.Emulation.Cores
}
ss.Add(core);
systemsFlat[type] = core;
}
foreach (var assy in assys)
{
@ -167,6 +171,7 @@ namespace BizHawk.Emulation.Cores
}
}
}
SystemsFlat = systemsFlat.Values;
}
public static readonly CoreInventory Instance = new CoreInventory(new[] { Emulation.Cores.ReflectionCache.Types });