Migrate SnesLuaLibrary to ApiHawk delegation

This commit is contained in:
YoshiRulz 2019-12-16 17:14:10 +10:00
parent 60daae50d5
commit 29ac251f34
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
1 changed files with 28 additions and 38 deletions

View File

@ -1,6 +1,5 @@
using System; using System;
using System.ComponentModel; using System.ComponentModel;
using BizHawk.Emulation.Common;
using NLua; using NLua;
using BizHawk.Emulation.Cores.Nintendo.SNES; using BizHawk.Emulation.Cores.Nintendo.SNES;
@ -9,11 +8,8 @@ using BizHawk.Emulation.Cores.Nintendo.SNES;
namespace BizHawk.Client.Common namespace BizHawk.Client.Common
{ {
[Description("Functions specific to SNESHawk (functions may not run when an SNES game is not loaded)")] [Description("Functions specific to SNESHawk (functions may not run when an SNES game is not loaded)")]
public sealed class SnesLuaLibrary : LuaLibraryBase public sealed class SnesLuaLibrary : DelegatingLuaLibrary
{ {
[OptionalService]
private LibsnesCore Snes { get; set; }
public SnesLuaLibrary(Lua lua) public SnesLuaLibrary(Lua lua)
: base(lua) { } : base(lua) { }
@ -22,144 +18,138 @@ namespace BizHawk.Client.Common
public override string Name => "snes"; public override string Name => "snes";
private LibsnesCore.SnesSettings GetSettings() private LibsnesCore.SnesSettings Settings
{ {
return Snes != null get => APIs.Emu.GetSettings() as LibsnesCore.SnesSettings ?? new LibsnesCore.SnesSettings();
? Snes.GetSettings() set => APIs.Emu.PutSettings(value);
: new LibsnesCore.SnesSettings();
}
private void PutSettings(LibsnesCore.SnesSettings settings)
{
Snes?.PutSettings(settings);
} }
[LuaMethodExample("if ( snes.getlayer_bg_1( ) ) then\r\n\tconsole.log( \"Returns whether the bg 1 layer is displayed\" );\r\nend;")] [LuaMethodExample("if ( snes.getlayer_bg_1( ) ) then\r\n\tconsole.log( \"Returns whether the bg 1 layer is displayed\" );\r\nend;")]
[LuaMethod("getlayer_bg_1", "Returns whether the bg 1 layer is displayed")] [LuaMethod("getlayer_bg_1", "Returns whether the bg 1 layer is displayed")]
public bool GetLayerBg1() public bool GetLayerBg1()
{ {
return GetSettings().ShowBG1_1; return Settings.ShowBG1_1;
} }
[LuaMethodExample("if ( snes.getlayer_bg_2( ) ) then\r\n\tconsole.log( \"Returns whether the bg 2 layer is displayed\" );\r\nend;")] [LuaMethodExample("if ( snes.getlayer_bg_2( ) ) then\r\n\tconsole.log( \"Returns whether the bg 2 layer is displayed\" );\r\nend;")]
[LuaMethod("getlayer_bg_2", "Returns whether the bg 2 layer is displayed")] [LuaMethod("getlayer_bg_2", "Returns whether the bg 2 layer is displayed")]
public bool GetLayerBg2() public bool GetLayerBg2()
{ {
return GetSettings().ShowBG2_1; return Settings.ShowBG2_1;
} }
[LuaMethodExample("if ( snes.getlayer_bg_3( ) ) then\r\n\tconsole.log( \"Returns whether the bg 3 layer is displayed\" );\r\nend;")] [LuaMethodExample("if ( snes.getlayer_bg_3( ) ) then\r\n\tconsole.log( \"Returns whether the bg 3 layer is displayed\" );\r\nend;")]
[LuaMethod("getlayer_bg_3", "Returns whether the bg 3 layer is displayed")] [LuaMethod("getlayer_bg_3", "Returns whether the bg 3 layer is displayed")]
public bool GetLayerBg3() public bool GetLayerBg3()
{ {
return GetSettings().ShowBG3_1; return Settings.ShowBG3_1;
} }
[LuaMethodExample("if ( snes.getlayer_bg_4( ) ) then\r\n\tconsole.log( \"Returns whether the bg 4 layer is displayed\" );\r\nend;")] [LuaMethodExample("if ( snes.getlayer_bg_4( ) ) then\r\n\tconsole.log( \"Returns whether the bg 4 layer is displayed\" );\r\nend;")]
[LuaMethod("getlayer_bg_4", "Returns whether the bg 4 layer is displayed")] [LuaMethod("getlayer_bg_4", "Returns whether the bg 4 layer is displayed")]
public bool GetLayerBg4() public bool GetLayerBg4()
{ {
return GetSettings().ShowBG4_1; return Settings.ShowBG4_1;
} }
[LuaMethodExample("if ( snes.getlayer_obj_1( ) ) then\r\n\tconsole.log( \"Returns whether the obj 1 layer is displayed\" );\r\nend;")] [LuaMethodExample("if ( snes.getlayer_obj_1( ) ) then\r\n\tconsole.log( \"Returns whether the obj 1 layer is displayed\" );\r\nend;")]
[LuaMethod("getlayer_obj_1", "Returns whether the obj 1 layer is displayed")] [LuaMethod("getlayer_obj_1", "Returns whether the obj 1 layer is displayed")]
public bool GetLayerObj1() public bool GetLayerObj1()
{ {
return GetSettings().ShowOBJ_0; return Settings.ShowOBJ_0;
} }
[LuaMethodExample("if ( snes.getlayer_obj_2( ) ) then\r\n\tconsole.log( \"Returns whether the obj 2 layer is displayed\" );\r\nend;")] [LuaMethodExample("if ( snes.getlayer_obj_2( ) ) then\r\n\tconsole.log( \"Returns whether the obj 2 layer is displayed\" );\r\nend;")]
[LuaMethod("getlayer_obj_2", "Returns whether the obj 2 layer is displayed")] [LuaMethod("getlayer_obj_2", "Returns whether the obj 2 layer is displayed")]
public bool GetLayerObj2() public bool GetLayerObj2()
{ {
return GetSettings().ShowOBJ_1; return Settings.ShowOBJ_1;
} }
[LuaMethodExample("if ( snes.getlayer_obj_3( ) ) then\r\n\tconsole.log( \"Returns whether the obj 3 layer is displayed\" );\r\nend;")] [LuaMethodExample("if ( snes.getlayer_obj_3( ) ) then\r\n\tconsole.log( \"Returns whether the obj 3 layer is displayed\" );\r\nend;")]
[LuaMethod("getlayer_obj_3", "Returns whether the obj 3 layer is displayed")] [LuaMethod("getlayer_obj_3", "Returns whether the obj 3 layer is displayed")]
public bool GetLayerObj3() public bool GetLayerObj3()
{ {
return GetSettings().ShowOBJ_2; return Settings.ShowOBJ_2;
} }
[LuaMethodExample("if ( snes.getlayer_obj_4( ) ) then\r\n\tconsole.log( \"Returns whether the obj 4 layer is displayed\" );\r\nend;")] [LuaMethodExample("if ( snes.getlayer_obj_4( ) ) then\r\n\tconsole.log( \"Returns whether the obj 4 layer is displayed\" );\r\nend;")]
[LuaMethod("getlayer_obj_4", "Returns whether the obj 4 layer is displayed")] [LuaMethod("getlayer_obj_4", "Returns whether the obj 4 layer is displayed")]
public bool GetLayerObj4() public bool GetLayerObj4()
{ {
return GetSettings().ShowOBJ_3; return Settings.ShowOBJ_3;
} }
[LuaMethodExample("snes.setlayer_bg_1( true );")] [LuaMethodExample("snes.setlayer_bg_1( true );")]
[LuaMethod("setlayer_bg_1", "Sets whether the bg 1 layer is displayed")] [LuaMethod("setlayer_bg_1", "Sets whether the bg 1 layer is displayed")]
public void SetLayerBg1(bool value) public void SetLayerBg1(bool value)
{ {
var s = GetSettings(); var s = Settings;
s.ShowBG1_1 = s.ShowBG1_0 = value; s.ShowBG1_1 = s.ShowBG1_0 = value;
PutSettings(s); Settings = s;
} }
[LuaMethodExample("snes.setlayer_bg_2( true );")] [LuaMethodExample("snes.setlayer_bg_2( true );")]
[LuaMethod("setlayer_bg_2", "Sets whether the bg 2 layer is displayed")] [LuaMethod("setlayer_bg_2", "Sets whether the bg 2 layer is displayed")]
public void SetLayerBg2(bool value) public void SetLayerBg2(bool value)
{ {
var s = GetSettings(); var s = Settings;
s.ShowBG2_1 = s.ShowBG2_0 = value; s.ShowBG2_1 = s.ShowBG2_0 = value;
PutSettings(s); Settings = s;
} }
[LuaMethodExample("snes.setlayer_bg_3( true );")] [LuaMethodExample("snes.setlayer_bg_3( true );")]
[LuaMethod("setlayer_bg_3", "Sets whether the bg 3 layer is displayed")] [LuaMethod("setlayer_bg_3", "Sets whether the bg 3 layer is displayed")]
public void SetLayerBg3(bool value) public void SetLayerBg3(bool value)
{ {
var s = GetSettings(); var s = Settings;
s.ShowBG3_1 = s.ShowBG3_0 = value; s.ShowBG3_1 = s.ShowBG3_0 = value;
PutSettings(s); Settings = s;
} }
[LuaMethodExample("snes.setlayer_bg_4( true );")] [LuaMethodExample("snes.setlayer_bg_4( true );")]
[LuaMethod("setlayer_bg_4", "Sets whether the bg 4 layer is displayed")] [LuaMethod("setlayer_bg_4", "Sets whether the bg 4 layer is displayed")]
public void SetLayerBg4(bool value) public void SetLayerBg4(bool value)
{ {
var s = GetSettings(); var s = Settings;
s.ShowBG4_1 = s.ShowBG4_0 = value; s.ShowBG4_1 = s.ShowBG4_0 = value;
PutSettings(s); Settings = s;
} }
[LuaMethodExample("snes.setlayer_obj_1( true );")] [LuaMethodExample("snes.setlayer_obj_1( true );")]
[LuaMethod("setlayer_obj_1", "Sets whether the obj 1 layer is displayed")] [LuaMethod("setlayer_obj_1", "Sets whether the obj 1 layer is displayed")]
public void SetLayerObj1(bool value) public void SetLayerObj1(bool value)
{ {
var s = GetSettings(); var s = Settings;
s.ShowOBJ_0 = value; s.ShowOBJ_0 = value;
PutSettings(s); Settings = s;
} }
[LuaMethodExample("snes.setlayer_obj_2( true );")] [LuaMethodExample("snes.setlayer_obj_2( true );")]
[LuaMethod("setlayer_obj_2", "Sets whether the obj 2 layer is displayed")] [LuaMethod("setlayer_obj_2", "Sets whether the obj 2 layer is displayed")]
public void SetLayerObj2(bool value) public void SetLayerObj2(bool value)
{ {
var s = GetSettings(); var s = Settings;
s.ShowOBJ_1 = value; s.ShowOBJ_1 = value;
PutSettings(s); Settings = s;
} }
[LuaMethodExample("snes.setlayer_obj_3( true );")] [LuaMethodExample("snes.setlayer_obj_3( true );")]
[LuaMethod("setlayer_obj_3", "Sets whether the obj 3 layer is displayed")] [LuaMethod("setlayer_obj_3", "Sets whether the obj 3 layer is displayed")]
public void SetLayerObj3(bool value) public void SetLayerObj3(bool value)
{ {
var s = GetSettings(); var s = Settings;
s.ShowOBJ_2 = value; s.ShowOBJ_2 = value;
PutSettings(s); Settings = s;
} }
[LuaMethodExample("snes.setlayer_obj_4( true );")] [LuaMethodExample("snes.setlayer_obj_4( true );")]
[LuaMethod("setlayer_obj_4", "Sets whether the obj 4 layer is displayed")] [LuaMethod("setlayer_obj_4", "Sets whether the obj 4 layer is displayed")]
public void SetLayerObj4(bool value) public void SetLayerObj4(bool value)
{ {
var s = GetSettings(); var s = Settings;
s.ShowOBJ_3 = value; s.ShowOBJ_3 = value;
PutSettings(s); Settings = s;
} }
} }
} }