DS - add a DS lua library with a touchScreenStart() method, add a cross hair stylus input display script

This commit is contained in:
adelikat 2020-03-28 15:43:31 -05:00
parent c008b57324
commit d1032f38f8
2 changed files with 87 additions and 0 deletions

View File

@ -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

View File

@ -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<string> 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;
}
}
}