From d1032f38f890dd48ec1cba1748926c876141de32 Mon Sep 17 00:00:00 2001 From: adelikat Date: Sat, 28 Mar 2020 15:43:31 -0500 Subject: [PATCH] DS - add a DS lua library with a touchScreenStart() method, add a cross hair stylus input display script --- Assets/Lua/DS/StyleusInputDisplay.lua | 50 +++++++++++++++++++ BizHawk.Client.Common/lua/EmuLuaLibrary.DS.cs | 37 ++++++++++++++ 2 files changed, 87 insertions(+) create mode 100644 Assets/Lua/DS/StyleusInputDisplay.lua create mode 100644 BizHawk.Client.Common/lua/EmuLuaLibrary.DS.cs diff --git a/Assets/Lua/DS/StyleusInputDisplay.lua b/Assets/Lua/DS/StyleusInputDisplay.lua new file mode 100644 index 0000000000..ab62595667 --- /dev/null +++ b/Assets/Lua/DS/StyleusInputDisplay.lua @@ -0,0 +1,50 @@ +-- Gives a cross hair UI for the stylus for DS games + +local upColor = 'white' +local downColor = 'green' +local dotColor = 'red' + +function Draw(x, y, maxX, maxY, isDown) + color = upColor + if isDown then + color = downColor + end + + gui.drawLine(0, y, maxX, y, color) + gui.drawLine(x, 0, x, maxY, color) + + if isDown then + gui.drawPixel(x, y, dotColor) + end +end + +while true do + if emu.getsystemid() ~= "NDS" then + console.log('This script is for Nintendo DS only') + break + end + + local touchStart = ds.touchScreenStart() + if touchStart then + local bufferX = client.bufferwidth() + local bufferY = client.bufferheight() + + local btns = joypad.get() + local x = btns['TouchX'] + local y = btns['TouchY'] + local isDown = btns['Touch'] + + -- A bit of a hack to ensure it is not drawing while mouse moving + -- on the top screen + if y == 0 then + x = 0 + end + + x = x + touchStart.X + y = y + touchStart.Y + + Draw(x, y, bufferX, bufferY, isDown) + end + + emu.frameadvance() +end \ No newline at end of file diff --git a/BizHawk.Client.Common/lua/EmuLuaLibrary.DS.cs b/BizHawk.Client.Common/lua/EmuLuaLibrary.DS.cs new file mode 100644 index 0000000000..9dc0f45999 --- /dev/null +++ b/BizHawk.Client.Common/lua/EmuLuaLibrary.DS.cs @@ -0,0 +1,37 @@ +using System; +using System.ComponentModel; +using System.Drawing; +using BizHawk.Emulation.Common; +using BizHawk.Emulation.Cores.Consoles.Nintendo.NDS; +using NLua; + +// ReSharper disable UnusedMember.Global +namespace BizHawk.Client.Common.lua +{ + [Description("Functions specific to DSHawk (functions may not run when an Genesis game is not loaded)")] + public sealed class DSLuaLibrary : DelegatingLuaLibrary + { + public DSLuaLibrary(Lua lua) + : base(lua) { } + + public DSLuaLibrary(Lua lua, Action logOutputCallback) + : base(lua, logOutputCallback) { } + + public override string Name => "ds"; + + [RequiredService] + public IEmulator Emulator { get; set; } + + [LuaMethodExample("touchStartX = ds.touchScreenStart().X")] + [LuaMethod("touchScreenStart", "Gets the buffer coordinates that represent the start of the touch screen area. If the touch screen is not currently being displayed, nil will be returned.")] + public Point? TouchScreenStart() + { + if (Emulator is MelonDS ds) + { + return ds.TouchScreenStart; + } + + return null; + } + } +}