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.
This commit is contained in:
parent
eca28a566e
commit
9a05512a48
|
@ -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 <see cref="BizHawkExternalToolUsageAttribute"/>
|
||||
/// </summary>
|
||||
/// <param name="usage"><see cref="BizHawkExternalToolUsage"/> i.e. what your external tool is for</param>
|
||||
/// <param name="parameter">The parameter; either emulator type or game hash depending of what you want to do</param>
|
||||
public BizHawkExternalToolUsageAttribute(BizHawkExternalToolUsage usage, string parameter)
|
||||
/// <param name="system"><see cref="EmulatedSystem"/> that your external tool is used for</param>
|
||||
/// <param name="gameHash">The game hash, unique game ID (see in the game database)</param>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initialize a new instance of <see cref="BizHawkExternalToolUsageAttribute"/>
|
||||
/// </summary>
|
||||
/// <param name="usage"><see cref="BizHawkExternalToolUsage"/> i.e. what your external tool is for</param>
|
||||
/// <param name="system"><see cref="EmulatedSystem"/> that your external tool is used for</param>
|
||||
public BizHawkExternalToolUsageAttribute(BizHawkExternalToolUsage usage, EmulatedSystem system)
|
||||
:this(usage, system, string.Empty)
|
||||
{}
|
||||
|
||||
/// <summary>
|
||||
/// Initialize a new instance of <see cref="BizHawkExternalToolUsageAttribute"/>
|
||||
/// </summary>
|
||||
public BizHawkExternalToolUsageAttribute()
|
||||
:this(BizHawkExternalToolUsage.Global, string.Empty)
|
||||
:this(BizHawkExternalToolUsage.Global, EmulatedSystem.Null, string.Empty)
|
||||
{ }
|
||||
|
||||
|
||||
|
@ -45,6 +62,28 @@ namespace BizHawk.Client.ApiHawk
|
|||
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// Gets the specific system used by the exetrnal tool
|
||||
/// </summary>
|
||||
public EmulatedSystem System
|
||||
{
|
||||
get
|
||||
{
|
||||
return _System;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the specific game (hash) used by the exetrnal tool
|
||||
/// </summary>
|
||||
public string GameHash
|
||||
{
|
||||
get
|
||||
{
|
||||
return _GameHash;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the tool usage
|
||||
/// </summary>
|
||||
|
@ -54,18 +93,7 @@ namespace BizHawk.Client.ApiHawk
|
|||
{
|
||||
return _ToolUsage;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the parameter (Emulator or Game hash)
|
||||
/// </summary>
|
||||
public string Parameter
|
||||
{
|
||||
get
|
||||
{
|
||||
return _Parameter;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
|
|
@ -97,10 +97,11 @@
|
|||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Attributes\BizHawkExternalToolUsageAttribute.cs" />
|
||||
<Compile Include="Attributes\ExternalToolAttribute.cs" />
|
||||
<Compile Include="Classes\BizHawkExternalToolUsage.cs" />
|
||||
<Compile Include="Attributes\BizHawkExternalToolAttribute.cs" />
|
||||
<Compile Include="Enums\BizHawkExternalToolUsage.cs" />
|
||||
<Compile Include="Classes\ClientApi.cs" />
|
||||
<Compile Include="Classes\ExternalToolManager.cs" />
|
||||
<Compile Include="Enums\EmulatedSystem.cs" />
|
||||
<Compile Include="Interfaces\IExternalToolForm.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
|
|
|
@ -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);
|
||||
}*/
|
||||
|
||||
/// <summary>
|
||||
/// Raise when a rom is successfully Loaded
|
||||
/// </summary>
|
||||
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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Convert a specified <see cref="EmulatedSystem"/> into a <see cref="string"/> used in BizHawk internal code
|
||||
/// </summary>
|
||||
/// <param name="system"><see cref="EmulatedSystem"/> to convert</param>
|
||||
/// <returns>Emulated system as <see cref="string"/> used in BizHawk code</returns>
|
||||
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()));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Convert a BizHawk <see cref="string"/> to <see cref="EmulatedSystem"/>
|
||||
/// </summary>
|
||||
/// <param name="system">BizHawk systemId to convert</param>
|
||||
/// <returns>SytemID as <see cref="EmulatedSystem"/> enum</returns>
|
||||
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
|
||||
|
||||
/// <summary>
|
||||
/// Gets current emulated system id as <see cref="EmulatedSystem"/> enum
|
||||
/// </summary>
|
||||
public static EmulatedSystem RunningSystem
|
||||
{
|
||||
get
|
||||
{
|
||||
return BizHawkStringToEmulatedSytemEnum(Common.Global.Emulator.SystemId);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
namespace BizHawk.Client.ApiHawk
|
||||
{
|
||||
/// <summary>
|
||||
/// Enumeration of each system emulated by BizHawk
|
||||
/// </summary>
|
||||
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
|
||||
}
|
||||
}
|
|
@ -47,20 +47,20 @@
|
|||
<Position X="11" Y="2.25" Width="5.75" />
|
||||
<TypeIdentifier>
|
||||
<HashCode>AAAAAAAAAAAgAAAAIAAAIAQAAAAAACAEAAAAAAAAAAA=</HashCode>
|
||||
<FileName>Attributes\ExternalToolAttribute.cs</FileName>
|
||||
<FileName>Attributes\BizHawkExternalToolAttribute.cs</FileName>
|
||||
</TypeIdentifier>
|
||||
</Class>
|
||||
<Class Name="BizHawk.Client.ApiHawk.ClientApi">
|
||||
<Position X="4.75" Y="10" Width="4" />
|
||||
<TypeIdentifier>
|
||||
<HashCode>AAEAAAAAAAAAAAAAAAAAQAIAAAAAACAAAAAAAAAAAAA=</HashCode>
|
||||
<HashCode>AAEAAAAAAAAAAAAAAAAAQAIAAAAAACAAAAAAAAACAAA=</HashCode>
|
||||
<FileName>Classes\ClientApi.cs</FileName>
|
||||
</TypeIdentifier>
|
||||
</Class>
|
||||
<Class Name="BizHawk.Client.ApiHawk.BizHawkExternalToolUsageAttribute">
|
||||
<Position X="11" Y="5.75" Width="5.75" />
|
||||
<TypeIdentifier>
|
||||
<HashCode>AIAAAAAAEAAAAAAAAAAAAAAAAAAQAACAAAAAAAAAAAA=</HashCode>
|
||||
<HashCode>AIAAAAAAEIAAAQAAAAAABABAAAAAAAAAAAAAAAAAAAA=</HashCode>
|
||||
<FileName>Attributes\BizHawkExternalToolUsageAttribute.cs</FileName>
|
||||
</TypeIdentifier>
|
||||
</Class>
|
||||
|
@ -95,7 +95,14 @@
|
|||
<Position X="28.25" Y="7.25" Width="2.25" />
|
||||
<TypeIdentifier>
|
||||
<HashCode>AAAAAAAAAAAAAAAAAIAAAAAAAAAAAAAAAAgAAAABAAA=</HashCode>
|
||||
<FileName>Classes\BizHawkExternalToolUsage.cs</FileName>
|
||||
<FileName>Enums\BizHawkExternalToolUsage.cs</FileName>
|
||||
</TypeIdentifier>
|
||||
</Enum>
|
||||
<Enum Name="BizHawk.Client.ApiHawk.EmulatedSystem">
|
||||
<Position X="28.5" Y="8.75" Width="1.5" />
|
||||
<TypeIdentifier>
|
||||
<HashCode>SAACIAABQAAQCAAmAAAAAAAIAhAAAIAADAIAAIAgGAA=</HashCode>
|
||||
<FileName>Enums\EmulatedSystem.cs</FileName>
|
||||
</TypeIdentifier>
|
||||
</Enum>
|
||||
<Font Name="Segoe UI" Size="9" />
|
||||
|
|
Loading…
Reference in New Issue