From 49134199fc89922d66fc1f1a11e968896a665bca Mon Sep 17 00:00:00 2001 From: "J.D. Purcell" Date: Mon, 17 Apr 2017 20:56:21 -0400 Subject: [PATCH] SystemInfo cleanup. --- BizHawk.Client.Common/SystemInfo.cs | 142 ++++++++-------------------- 1 file changed, 39 insertions(+), 103 deletions(-) diff --git a/BizHawk.Client.Common/SystemInfo.cs b/BizHawk.Client.Common/SystemInfo.cs index 0198701e03..052c42c098 100644 --- a/BizHawk.Client.Common/SystemInfo.cs +++ b/BizHawk.Client.Common/SystemInfo.cs @@ -14,57 +14,12 @@ namespace BizHawk.Client.Common private const JoypadButton UpDownLeftRight = JoypadButton.Up | JoypadButton.Down | JoypadButton.Left | JoypadButton.Right; private const JoypadButton StandardButtons = JoypadButton.A | JoypadButton.B | JoypadButton.Start | JoypadButton.Select | UpDownLeftRight; - private static readonly List allSystemInfos; - - private string _DisplayName; - private CoreSystem _System; - private JoypadButton _AvailableButtons; - private int _MaxControllers; + private static readonly List _allSystemInfos = new List(); #endregion #region cTor(s) - /// - /// Initializes static members of the class. - /// Global initialization stuff - /// - /// - /// DO NOT CHANGE List order because properties depends on it (and it is hardcoded) - /// - static SystemInfo() - { - allSystemInfos = new List(26) - { - new SystemInfo(string.Empty), - new SystemInfo("NES", CoreSystem.NES, 2, StandardButtons), - new SystemInfo("Intellivision", CoreSystem.Intellivision, 2), - new SystemInfo("Sega Master System", CoreSystem.MasterSystem, 2, UpDownLeftRight | JoypadButton.B1 | JoypadButton.B2), - new SystemInfo("SG-1000", CoreSystem.MasterSystem, 1), - new SystemInfo("Game Gear", CoreSystem.MasterSystem, 1, UpDownLeftRight | JoypadButton.B1 | JoypadButton.B2), - new SystemInfo("TurboGrafx-16", CoreSystem.PCEngine, 1), - new SystemInfo("TurboGrafx - 16(CD)", CoreSystem.PCEngine, 1), - new SystemInfo("SuperGrafx", CoreSystem.PCEngine, 1), - new SystemInfo("Genesis", CoreSystem.Genesis, 2, UpDownLeftRight | JoypadButton.A | JoypadButton.B | JoypadButton.C | JoypadButton.X | JoypadButton.Y | JoypadButton.Z), - new SystemInfo("TI - 83", CoreSystem.TI83, 1), - new SystemInfo("SNES", CoreSystem.SNES, 8, StandardButtons | JoypadButton.X | JoypadButton.Y | JoypadButton.L | JoypadButton.R), - new SystemInfo("GB", CoreSystem.GameBoy, 1, StandardButtons), - new SystemInfo("Gameboy Color", CoreSystem.GameBoy, 1, StandardButtons), // 13 (0 based) - new SystemInfo("Atari 2600", CoreSystem.Atari2600, 1), - new SystemInfo("Atari 7800", CoreSystem.Atari7800, 1), - new SystemInfo("Commodore 64", CoreSystem.Commodore64, 1), - new SystemInfo("ColecoVision", CoreSystem.ColecoVision, 1), - new SystemInfo("Gameboy Advance", CoreSystem.GameBoyAdvance, 1, StandardButtons | JoypadButton.L | JoypadButton.R), - new SystemInfo("Nintendo 64", CoreSystem.Nintendo64, 4, StandardButtons ^ JoypadButton.Select | JoypadButton.Z | JoypadButton.CUp | JoypadButton.CDown | JoypadButton.CLeft | JoypadButton.CRight | JoypadButton.AnalogStick | JoypadButton.L | JoypadButton.R), - new SystemInfo("Saturn", CoreSystem.Saturn, 2, UpDownLeftRight | JoypadButton.A | JoypadButton.B | JoypadButton.C | JoypadButton.X | JoypadButton.Y | JoypadButton.Z), - new SystemInfo("Game Boy Link", CoreSystem.DualGameBoy, 2, StandardButtons), - new SystemInfo("WonderSwan", CoreSystem.WonderSwan, 1), - new SystemInfo("Lynx", CoreSystem.Lynx, 1), - new SystemInfo("PlayStation", CoreSystem.Playstation, 2), - new SystemInfo("Apple II", CoreSystem.AppleII, 1) - }; - } - /// /// Initialize a new instance of /// @@ -72,32 +27,14 @@ namespace BizHawk.Client.Common /// A that specify what core is used /// Maximum controller allowed by this system /// Which buttons are available (i.e. are actually on the controller) for this system - private SystemInfo(string displayName, CoreSystem system, int maxControllers, JoypadButton availableButtons) + private SystemInfo(string displayName, CoreSystem system, int maxControllers, JoypadButton availableButtons = 0) { - _DisplayName = displayName; - _System = system; - _MaxControllers = maxControllers; - _AvailableButtons = availableButtons; - } + DisplayName = displayName; + System = system; + MaxControllers = maxControllers; + AvailableButtons = availableButtons; - /// - /// Initialize a new instance of - /// - /// A that specify how the system name is displayed - /// A that specify what core is used - /// Maximum controller allowed by this system - private SystemInfo(string displayName, CoreSystem system, int maxControllers) - : this(displayName, system, maxControllers, 0) - { - } - - /// - /// Initialize a new instance of - /// - /// A that specify how the system name is displayed - private SystemInfo(string displayName) - : this(displayName, CoreSystem.Null, 0, 0) - { + _allSystemInfos.Add(this); } #endregion @@ -109,132 +46,132 @@ namespace BizHawk.Client.Common /// /// Gets the instance for Apple II /// allSystemInfos[25]; + public static SystemInfo AppleII { get; } = new SystemInfo("Apple II", CoreSystem.AppleII, 1); /// /// Gets the instance for Atari 2600 /// allSystemInfos[14]; + public static SystemInfo Atari2600 { get; } = new SystemInfo("Atari 2600", CoreSystem.Atari2600, 1); /// /// Gets the instance for Atari 7800 /// - public static SystemInfo Atari7800 => allSystemInfos[15]; + public static SystemInfo Atari7800 { get; } = new SystemInfo("Atari 7800", CoreSystem.Atari7800, 1); /// /// Gets the instance for Commodore 64 /// - public static SystemInfo C64 => allSystemInfos[16]; + public static SystemInfo C64 { get; } = new SystemInfo("Commodore 64", CoreSystem.Commodore64, 1); /// /// Gets the instance for Coleco Vision /// - public static SystemInfo Coleco => allSystemInfos[17]; + public static SystemInfo Coleco { get; } = new SystemInfo("ColecoVision", CoreSystem.ColecoVision, 1); /// /// Gets the instance for Dual Gameboy /// - public static SystemInfo DualGB => allSystemInfos[21]; + public static SystemInfo DualGB { get; } = new SystemInfo("Game Boy Link", CoreSystem.DualGameBoy, 2, StandardButtons); /// /// Gets the instance for Gameboy /// - public static SystemInfo GB => allSystemInfos[12]; + public static SystemInfo GB { get; } = new SystemInfo("GB", CoreSystem.GameBoy, 1, StandardButtons); /// /// Gets the instance for Gameboy Advance /// - public static SystemInfo GBA => allSystemInfos[18]; + public static SystemInfo GBA { get; } = new SystemInfo("Gameboy Advance", CoreSystem.GameBoyAdvance, 1, StandardButtons | JoypadButton.L | JoypadButton.R); /// /// Gets the instance for Gameboy Color /// - public static SystemInfo GBC => allSystemInfos[13]; + public static SystemInfo GBC { get; } = new SystemInfo("Gameboy Color", CoreSystem.GameBoy, 1, StandardButtons); /// /// Gets the instance for Genesis /// - public static SystemInfo Genesis => allSystemInfos[9]; + public static SystemInfo Genesis { get; } = new SystemInfo("Genesis", CoreSystem.Genesis, 2, UpDownLeftRight | JoypadButton.A | JoypadButton.B | JoypadButton.C | JoypadButton.X | JoypadButton.Y | JoypadButton.Z); /// /// Gets the instance for Game Gear /// - public static SystemInfo GG => allSystemInfos[5]; + public static SystemInfo GG { get; } = new SystemInfo("Game Gear", CoreSystem.MasterSystem, 1, UpDownLeftRight | JoypadButton.B1 | JoypadButton.B2); /// /// Gets the instance for Intellivision /// - public static SystemInfo Intellivision => allSystemInfos[2]; + public static SystemInfo Intellivision { get; } = new SystemInfo("Intellivision", CoreSystem.Intellivision, 2); /// /// Gets the instance for Lynx /// - public static SystemInfo Lynx => allSystemInfos[23]; + public static SystemInfo Lynx { get; } = new SystemInfo("Lynx", CoreSystem.Lynx, 1); /// /// Gets the instance for NES /// - public static SystemInfo Nes => allSystemInfos[1]; + public static SystemInfo Nes { get; } = new SystemInfo("NES", CoreSystem.NES, 2, StandardButtons); /// /// Gets the instance for Nintendo 64 /// - public static SystemInfo N64 => allSystemInfos[19]; + public static SystemInfo N64 { get; } = new SystemInfo("Nintendo 64", CoreSystem.Nintendo64, 4, StandardButtons ^ JoypadButton.Select | JoypadButton.Z | JoypadButton.CUp | JoypadButton.CDown | JoypadButton.CLeft | JoypadButton.CRight | JoypadButton.AnalogStick | JoypadButton.L | JoypadButton.R); /// /// Gets the instance for Null (i.e. nothing is emulated) emulator /// - public static SystemInfo Null => allSystemInfos[0]; + public static SystemInfo Null { get; } = new SystemInfo(string.Empty, CoreSystem.Null, 0); /// /// Gets the instance for PCEngine (TurboGrafx-16) /// - public static SystemInfo PCE => allSystemInfos[6]; + public static SystemInfo PCE { get; } = new SystemInfo("TurboGrafx-16", CoreSystem.PCEngine, 1); /// /// Gets the instance for PCEngine (TurboGrafx-16) + CD /// - public static SystemInfo PCECD => allSystemInfos[7]; + public static SystemInfo PCECD { get; } = new SystemInfo("TurboGrafx - 16(CD)", CoreSystem.PCEngine, 1); /// /// Gets the instance for PlayStation /// - public static SystemInfo PSX => allSystemInfos[24]; + public static SystemInfo PSX { get; } = new SystemInfo("PlayStation", CoreSystem.Playstation, 2); /// /// Gets the instance for Sega Saturn /// - public static SystemInfo Saturn => allSystemInfos[20]; + public static SystemInfo Saturn { get; } = new SystemInfo("Saturn", CoreSystem.Saturn, 2, UpDownLeftRight | JoypadButton.A | JoypadButton.B | JoypadButton.C | JoypadButton.X | JoypadButton.Y | JoypadButton.Z); /// /// Gets the instance for SG-1000 (Sega Game 1000) /// - public static SystemInfo SG => allSystemInfos[4]; + public static SystemInfo SG { get; } = new SystemInfo("SG-1000", CoreSystem.MasterSystem, 1); /// /// Gets the instance for PCEngine (Supergraph FX) /// - public static SystemInfo SGX => allSystemInfos[8]; + public static SystemInfo SGX { get; } = new SystemInfo("SuperGrafx", CoreSystem.PCEngine, 1); /// /// Gets the instance for Sega Master System /// - public static SystemInfo SMS => allSystemInfos[3]; + public static SystemInfo SMS { get; } = new SystemInfo("Sega Master System", CoreSystem.MasterSystem, 2, UpDownLeftRight | JoypadButton.B1 | JoypadButton.B2); /// /// Gets the instance for SNES /// - public static SystemInfo SNES => allSystemInfos[11]; + public static SystemInfo SNES { get; } = new SystemInfo("SNES", CoreSystem.SNES, 8, StandardButtons | JoypadButton.X | JoypadButton.Y | JoypadButton.L | JoypadButton.R); /// /// Gets the instance for TI-83 /// - public static SystemInfo TI83 => allSystemInfos[10]; + public static SystemInfo TI83 { get; } = new SystemInfo("TI - 83", CoreSystem.TI83, 1); /// /// Gets the instance for TI-83 /// - public static SystemInfo WonderSwan => allSystemInfos[22]; + public static SystemInfo WonderSwan { get; } = new SystemInfo("WonderSwan", CoreSystem.WonderSwan, 1); #endregion Get SystemInfo @@ -245,7 +182,7 @@ namespace BizHawk.Client.Common /// Mathing public static SystemInfo FindByCoreSystem(CoreSystem system) { - return allSystemInfos.Find(s => s._System == system); + return _allSystemInfos.Find(s => s.System == system); } /// @@ -279,10 +216,9 @@ namespace BizHawk.Client.Common /// public override string ToString() { - return _DisplayName; + return DisplayName; } - /// /// Determine if two are equals. /// As it is all static instance, it just compare their reference @@ -314,22 +250,22 @@ namespace BizHawk.Client.Common /// /// Gets available for this system /// - public JoypadButton AvailableButtons => _AvailableButtons; + public JoypadButton AvailableButtons { get; } /// /// Gets the sytem name as /// - public string DisplayName => _DisplayName; + public string DisplayName { get; } /// /// Gets the maximum amount of controller allowed for this system /// - public int MaxControllers => _MaxControllers; + public int MaxControllers { get; } /// /// Gets core used for this system as enum /// - public CoreSystem System => _System; + public CoreSystem System { get; } #endregion }