mirror of
https://github.com/ctruLua/uCompat.git
synced 2025-10-27 16:49:31 +00:00
Added Controls layer, Fixed something
This commit is contained in:
parent
7844e5a117
commit
703418a419
2 changed files with 65 additions and 2 deletions
61
Controls.lua
Normal file
61
Controls.lua
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
--[[
|
||||
Controls related µLua compatibility layer/lib for ctrµLua
|
||||
|
||||
Warning: this HID library will give you headaches. Really.
|
||||
]]
|
||||
|
||||
-- Local
|
||||
|
||||
local ctr = require("ctr")
|
||||
local hid = require("ctr.hid")
|
||||
|
||||
local dsKeys = {["A"] = "a", ["B"] = "b", ["X"] = "x", ["Y"] = "y",
|
||||
["L"] = "l", ["R"] = "r", ["Start"] = "start", ["Select"] = "select",
|
||||
["Up"] = "up", ["Down"] = "down", ["Left"] = "left", ["Right"] = "right"}
|
||||
|
||||
dblcFreq = 30 -- Stylus double click timer, in frames
|
||||
stylusX = 0 -- \ Both for Stylus.deltaX
|
||||
stylusY = 0 -- /
|
||||
stylusTime = 0
|
||||
|
||||
-- Module
|
||||
|
||||
Keys = {}
|
||||
Keys.held = {}
|
||||
Keys.released = {}
|
||||
Keys.newPress = {}
|
||||
Stylus = {}
|
||||
|
||||
Controls = {}
|
||||
|
||||
function Controls.read()
|
||||
hid.read()
|
||||
local k = hid.keys()
|
||||
|
||||
for n,v in pairs(dsKeys) do
|
||||
Keys.held[n] = k.held[v]
|
||||
Keys.released[n] = k.up[v]
|
||||
Keys.newPress[n] = k.down[v]
|
||||
end
|
||||
|
||||
Stylus.X, Stylus.Y = hid.touch()
|
||||
Stylus.deltaX = (stylusX-Stylus.X)
|
||||
Stylus.deltaY = (stylusY-Stylus.Y)
|
||||
stylusX, stylusY = Stylus.X, Stylus.Y
|
||||
|
||||
Stylus.held = k.held.touch
|
||||
Stylus.released = k.up.touch
|
||||
Stylus.newPress = k.down.touch
|
||||
|
||||
if k.down.touch and (ctr.time()-stylusTime)*(1000/(NB_FPS or 30)) > (dblcFreq/30) then
|
||||
Stylus.doubleClick = true
|
||||
stylusTime = ctr.time()
|
||||
elseif k.down.touch then
|
||||
stylusTime = ctr.time()
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
function Controls.setStylusDblcFreq(freq)
|
||||
dblcFreq = freq
|
||||
end
|
||||
|
|
@ -13,4 +13,6 @@ ULUA_BOOT_FILE = "main.lua"
|
|||
ULUA_BOOT_FULLPATH = (ULUA_DIR..ULUA_BOOT_FILE)
|
||||
|
||||
-- Other libs
|
||||
screen = require("uCompat.screen")
|
||||
require("uCompat.screen")
|
||||
require("uCompat.Color")
|
||||
require("uCompat.Controls")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue