From 9a05512a485708507d233368babf12733c13709e Mon Sep 17 00:00:00 2001 From: Hathor86 Date: Sun, 20 Mar 2016 23:05:38 +0100 Subject: [PATCH] EmulatedSystem enum for ApiHawk Created an enum (and a convertion function) for emulated system. It provides a more sexy way to work with SystemID. It also means that convertion function and enum has to be updated if we add a new system. --- ...ute.cs => BizHawkExternalToolAttribute.cs} | 0 .../BizHawkExternalToolUsageAttribute.cs | 68 ++++-- .../BizHawk.Client.ApiHawk.csproj | 5 +- BizHawk.Client.ApiHawk/Classes/ClientApi.cs | 194 +++++++++++++++++- .../Classes/ExternalToolManager.cs | 4 +- .../BizHawkExternalToolUsage.cs | 0 .../Enums/EmulatedSystem.cs | 32 +++ .../Resources/ApiClassDiagram.cd | 15 +- 8 files changed, 288 insertions(+), 30 deletions(-) rename BizHawk.Client.ApiHawk/Attributes/{ExternalToolAttribute.cs => BizHawkExternalToolAttribute.cs} (100%) rename BizHawk.Client.ApiHawk/{Classes => Enums}/BizHawkExternalToolUsage.cs (100%) create mode 100644 BizHawk.Client.ApiHawk/Enums/EmulatedSystem.cs diff --git a/BizHawk.Client.ApiHawk/Attributes/ExternalToolAttribute.cs b/BizHawk.Client.ApiHawk/Attributes/BizHawkExternalToolAttribute.cs similarity index 100% rename from BizHawk.Client.ApiHawk/Attributes/ExternalToolAttribute.cs rename to BizHawk.Client.ApiHawk/Attributes/BizHawkExternalToolAttribute.cs diff --git a/BizHawk.Client.ApiHawk/Attributes/BizHawkExternalToolUsageAttribute.cs b/BizHawk.Client.ApiHawk/Attributes/BizHawkExternalToolUsageAttribute.cs index 5526e4878e..672de2a054 100644 --- a/BizHawk.Client.ApiHawk/Attributes/BizHawkExternalToolUsageAttribute.cs +++ b/BizHawk.Client.ApiHawk/Attributes/BizHawkExternalToolUsageAttribute.cs @@ -12,7 +12,8 @@ namespace BizHawk.Client.ApiHawk #region Fields private BizHawkExternalToolUsage _ToolUsage; - private string _Parameter; + private EmulatedSystem _System; + private string _GameHash; #endregion @@ -22,22 +23,38 @@ namespace BizHawk.Client.ApiHawk /// Initialize a new instance of /// /// i.e. what your external tool is for - /// The parameter; either emulator type or game hash depending of what you want to do - public BizHawkExternalToolUsageAttribute(BizHawkExternalToolUsage usage, string parameter) + /// that your external tool is used for + /// The game hash, unique game ID (see in the game database) + public BizHawkExternalToolUsageAttribute(BizHawkExternalToolUsage usage, EmulatedSystem system, string gameHash) { - _ToolUsage = usage; - if(usage != BizHawkExternalToolUsage.Global && parameter.Trim() == string.Empty) + if (usage == BizHawkExternalToolUsage.EmulatorSpecific && system == EmulatedSystem.Null) { - throw new InvalidOperationException("You must specify the parameter. Either emulator type or game hash depending of what you want to do"); + throw new InvalidOperationException("A system must be set"); } - _Parameter = parameter; + if (usage == BizHawkExternalToolUsage.GameSpecific && gameHash.Trim() == string.Empty) + { + throw new InvalidOperationException("A game hash must be set"); + } + + _ToolUsage = usage; + _System = system; + _GameHash = gameHash; } + /// + /// Initialize a new instance of + /// + /// i.e. what your external tool is for + /// that your external tool is used for + public BizHawkExternalToolUsageAttribute(BizHawkExternalToolUsage usage, EmulatedSystem system) + :this(usage, system, string.Empty) + {} + /// /// Initialize a new instance of /// public BizHawkExternalToolUsageAttribute() - :this(BizHawkExternalToolUsage.Global, string.Empty) + :this(BizHawkExternalToolUsage.Global, EmulatedSystem.Null, string.Empty) { } @@ -45,6 +62,28 @@ namespace BizHawk.Client.ApiHawk #region Properties + /// + /// Gets the specific system used by the exetrnal tool + /// + public EmulatedSystem System + { + get + { + return _System; + } + } + + /// + /// Gets the specific game (hash) used by the exetrnal tool + /// + public string GameHash + { + get + { + return _GameHash; + } + } + /// /// Gets the tool usage /// @@ -54,18 +93,7 @@ namespace BizHawk.Client.ApiHawk { return _ToolUsage; } - } - - /// - /// Gets the parameter (Emulator or Game hash) - /// - public string Parameter - { - get - { - return _Parameter; - } - } + } #endregion } diff --git a/BizHawk.Client.ApiHawk/BizHawk.Client.ApiHawk.csproj b/BizHawk.Client.ApiHawk/BizHawk.Client.ApiHawk.csproj index e3cef06e45..1635c2c44a 100644 --- a/BizHawk.Client.ApiHawk/BizHawk.Client.ApiHawk.csproj +++ b/BizHawk.Client.ApiHawk/BizHawk.Client.ApiHawk.csproj @@ -97,10 +97,11 @@ - - + + + diff --git a/BizHawk.Client.ApiHawk/Classes/ClientApi.cs b/BizHawk.Client.ApiHawk/Classes/ClientApi.cs index f8bb767db1..516bfb8cc2 100644 --- a/BizHawk.Client.ApiHawk/Classes/ClientApi.cs +++ b/BizHawk.Client.ApiHawk/Classes/ClientApi.cs @@ -12,7 +12,7 @@ namespace BizHawk.Client.ApiHawk #region Fields private static readonly Assembly clientAssembly; - + public static event EventHandler RomLoaded; #endregion @@ -28,12 +28,21 @@ namespace BizHawk.Client.ApiHawk #region Methods + /*public static void DoframeAdvance() + { + //StepRunLoop_Core + Type emuLuaLib = clientAssembly.GetType("BizHawk.Client.EmuHawk.MainForm"); + //clientAssembly + MethodInfo paddingMethod = emuLuaLib.GetMethod("FrameAdvance"); + paddingMethod.Invoke(paddingMethod, null); + }*/ + /// /// Raise when a rom is successfully Loaded /// public static void OnRomLoaded() { - if(RomLoaded != null) + if (RomLoaded != null) { RomLoaded(null, EventArgs.Empty); } @@ -83,6 +92,187 @@ namespace BizHawk.Client.ApiHawk SetExtraPadding(left, top, right, 0); } + /// + /// Convert a specified into a used in BizHawk internal code + /// + /// to convert + /// Emulated system as used in BizHawk code + internal static string EmulatedSytemEnumToBizhawkString(EmulatedSystem system) + { + switch (system) + { + case EmulatedSystem.AppleII: + return "AppleII"; + + case EmulatedSystem.Atari2600: + return "A26"; + + case EmulatedSystem.Atari7800: + return "A78"; + + case EmulatedSystem.ColecoVision: + return "Coleco"; + + case EmulatedSystem.Commodore64: + return "C64"; + + case EmulatedSystem.DualGameBoy: + return "DGB"; + + case EmulatedSystem.GameBoy: + return "GB"; + + case EmulatedSystem.GameBoyAdvance: + return "GBA"; + + case EmulatedSystem.Genesis: + return "GEN"; + + case EmulatedSystem.Intellivision: + return "INTV"; + + case EmulatedSystem.Libretro: + return "Libretro"; + + case EmulatedSystem.Lynx: + return "Lynx"; + + case EmulatedSystem.MasterSystem: + return "SMS"; + + case EmulatedSystem.NES: + return "NES"; + + case EmulatedSystem.Nintendo64: + return "N64"; + + case EmulatedSystem.Null: + return "NULL"; + + case EmulatedSystem.PCEngine: + return "PCE"; + + case EmulatedSystem.Playstation: + return "PSX"; + + case EmulatedSystem.PSP: + return "PSP"; + + case EmulatedSystem.Saturn: + return "SAT"; + + case EmulatedSystem.SNES: + return "SNES"; + + case EmulatedSystem.TI83: + return "TI83"; + + case EmulatedSystem.WonderSwan: + return "WSWAN"; + + default: + throw new IndexOutOfRangeException(string.Format("{0} is missing in convert list", system.ToString())); + } + } + + /// + /// Convert a BizHawk to + /// + /// BizHawk systemId to convert + /// SytemID as enum + internal static EmulatedSystem BizHawkStringToEmulatedSytemEnum(string system) + { + switch(system) + { + case "AppleII": + return EmulatedSystem.AppleII; + + case "A26": + return EmulatedSystem.Atari2600; + + case "A78": + return EmulatedSystem.Atari2600; + + case "Coleco": + return EmulatedSystem.ColecoVision; + + case "C64": + return EmulatedSystem.Commodore64; + + case "DGB": + return EmulatedSystem.DualGameBoy; + + case "GB": + return EmulatedSystem.GameBoy; + + case "GBA": + return EmulatedSystem.GameBoyAdvance; + + case "GEN": + return EmulatedSystem.Genesis; + + case "INTV": + return EmulatedSystem.Intellivision; + + case "Libretro": + return EmulatedSystem.Libretro; + + case "Lynx": + return EmulatedSystem.Lynx; + + case "SMS": + return EmulatedSystem.MasterSystem; + + case "NES": + return EmulatedSystem.NES; + + case "N64": + return EmulatedSystem.Nintendo64; + + case "NULL": + return EmulatedSystem.Null; + + case "PCE": + return EmulatedSystem.PCEngine; + + case "PSX": + return EmulatedSystem.Playstation; + + case "PSP": + return EmulatedSystem.PSP; + + case "SAT": + return EmulatedSystem.Saturn; + + case "SNES": + return EmulatedSystem.SNES; + + case "TI83": + return EmulatedSystem.TI83; + + case "WSWAN": + return EmulatedSystem.WonderSwan; + + default: + throw new IndexOutOfRangeException(string.Format("{0} is missing in convert list", system)); + } + } + + #endregion + + #region Properties + + /// + /// Gets current emulated system id as enum + /// + public static EmulatedSystem RunningSystem + { + get + { + return BizHawkStringToEmulatedSytemEnum(Common.Global.Emulator.SystemId); + } + } + #endregion } } diff --git a/BizHawk.Client.ApiHawk/Classes/ExternalToolManager.cs b/BizHawk.Client.ApiHawk/Classes/ExternalToolManager.cs index 169fa47a6a..33388a5518 100644 --- a/BizHawk.Client.ApiHawk/Classes/ExternalToolManager.cs +++ b/BizHawk.Client.ApiHawk/Classes/ExternalToolManager.cs @@ -116,12 +116,12 @@ namespace BizHawk.Client.ApiHawk item.ToolTipText = "This tool doesn't work if nothing is loaded"; item.Enabled = false; } - else if(attribute2.ToolUsage == BizHawkExternalToolUsage.EmulatorSpecific && Global.Emulator.SystemId != attribute2.Parameter) + else if(attribute2.ToolUsage == BizHawkExternalToolUsage.EmulatorSpecific && Global.Emulator.SystemId != ClientApi.EmulatedSytemEnumToBizhawkString(attribute2.System)) { item.ToolTipText = "This tool doesn't work for current system"; item.Enabled = false; } - else if (attribute2.ToolUsage == BizHawkExternalToolUsage.GameSpecific && Global.Game.Hash != attribute2.Parameter) + else if (attribute2.ToolUsage == BizHawkExternalToolUsage.GameSpecific && Global.Game.Hash != attribute2.GameHash) { item.ToolTipText = "This tool doesn't work for current game"; item.Enabled = false; diff --git a/BizHawk.Client.ApiHawk/Classes/BizHawkExternalToolUsage.cs b/BizHawk.Client.ApiHawk/Enums/BizHawkExternalToolUsage.cs similarity index 100% rename from BizHawk.Client.ApiHawk/Classes/BizHawkExternalToolUsage.cs rename to BizHawk.Client.ApiHawk/Enums/BizHawkExternalToolUsage.cs diff --git a/BizHawk.Client.ApiHawk/Enums/EmulatedSystem.cs b/BizHawk.Client.ApiHawk/Enums/EmulatedSystem.cs new file mode 100644 index 0000000000..89c27d3dba --- /dev/null +++ b/BizHawk.Client.ApiHawk/Enums/EmulatedSystem.cs @@ -0,0 +1,32 @@ +namespace BizHawk.Client.ApiHawk +{ + /// + /// Enumeration of each system emulated by BizHawk + /// + public enum EmulatedSystem + { + Null = 0, + TI83, + AppleII, + Commodore64, + Atari2600, + Atari7800, + Lynx, + ColecoVision, + Intellivision, + GameBoy, + DualGameBoy, + GameBoyAdvance, + Nintendo64, + NES, + SNES, + PCEngine, + Genesis, + Saturn, + MasterSystem, + PSP, + Playstation, + WonderSwan, + Libretro + } +} diff --git a/BizHawk.Client.ApiHawk/Resources/ApiClassDiagram.cd b/BizHawk.Client.ApiHawk/Resources/ApiClassDiagram.cd index 636d153226..a0bce9afc1 100644 --- a/BizHawk.Client.ApiHawk/Resources/ApiClassDiagram.cd +++ b/BizHawk.Client.ApiHawk/Resources/ApiClassDiagram.cd @@ -47,20 +47,20 @@ AAAAAAAAAAAgAAAAIAAAIAQAAAAAACAEAAAAAAAAAAA= - Attributes\ExternalToolAttribute.cs + Attributes\BizHawkExternalToolAttribute.cs - AAEAAAAAAAAAAAAAAAAAQAIAAAAAACAAAAAAAAAAAAA= + AAEAAAAAAAAAAAAAAAAAQAIAAAAAACAAAAAAAAACAAA= Classes\ClientApi.cs - AIAAAAAAEAAAAAAAAAAAAAAAAAAQAACAAAAAAAAAAAA= + AIAAAAAAEIAAAQAAAAAABABAAAAAAAAAAAAAAAAAAAA= Attributes\BizHawkExternalToolUsageAttribute.cs @@ -95,7 +95,14 @@ AAAAAAAAAAAAAAAAAIAAAAAAAAAAAAAAAAgAAAABAAA= - Classes\BizHawkExternalToolUsage.cs + Enums\BizHawkExternalToolUsage.cs + + + + + + SAACIAABQAAQCAAmAAAAAAAIAhAAAIAADAIAAIAgGAA= + Enums\EmulatedSystem.cs