Update LuaScriptTest.lua
This commit is contained in:
parent
4f1b1d12e0
commit
4f4619db83
|
@ -4,116 +4,34 @@
|
||||||
--TODO: re-write to make more readable
|
--TODO: re-write to make more readable
|
||||||
|
|
||||||
MelonClear()
|
MelonClear()
|
||||||
|
|
||||||
MelonPrint("This text Should be cleared")
|
MelonPrint("This text Should be cleared")
|
||||||
|
|
||||||
MelonClear()
|
MelonClear()
|
||||||
|
|
||||||
MelonPrint("Running Test...")
|
MelonPrint("Running Test...")
|
||||||
|
|
||||||
u32Data = Readu32(0x00000000)
|
u32Data = Readu32(0x00000000)
|
||||||
|
|
||||||
MelonPrint(string.format("DataZero: %x",u32Data))
|
MelonPrint(string.format("DataZero: %x",u32Data))
|
||||||
|
|
||||||
NDSTapDown(0,0)
|
|
||||||
|
|
||||||
NDSTapUp()
|
|
||||||
|
|
||||||
--StateSave("SaveState_Auto")
|
|
||||||
|
|
||||||
--StateLoad("SaveState_Auto")
|
|
||||||
|
|
||||||
canvas = MakeCanvas(0,0,500,500)
|
canvas = MakeCanvas(0,0,500,500)
|
||||||
|
|
||||||
SetCanvas(canvas)
|
SetCanvas(canvas)
|
||||||
|
|
||||||
ClearOverlay()
|
ClearOverlay()
|
||||||
|
|
||||||
FillRect(0,0,55,11,0xffffffff)
|
FillRect(0,0,55,11,0xffffffff)
|
||||||
|
|
||||||
Text(0,9,"Test Message")
|
Text(0,9,"Test Message")
|
||||||
|
|
||||||
Line(0,10,55,10,0x00ff00ff)
|
Line(0,10,55,10,0x00ff00ff)
|
||||||
|
|
||||||
Rect(0,0,55,11,0xff00ff00)
|
Rect(0,0,55,11,0xff00ff00)
|
||||||
|
|
||||||
DrawImage("Lua-Logo_128x128.png",0,60)
|
DrawImage("Lua-Logo_128x128.png",0,60)
|
||||||
|
|
||||||
Text(0,200,"WASD to move \"lua Stylus\", Q to tap screen.",0xffffff)
|
Text(0,200,"WASD to move \"lua Stylus\", Q to tap screen.",0xffffff)
|
||||||
Text(0,210,"T to create savestate, R to load savestate.",0xffffff)
|
Text(0,210,"T to create savestate, R to load savestate.",0xffffff)
|
||||||
--ClearHash()
|
|
||||||
|
|
||||||
Flip()
|
Flip()
|
||||||
|
|
||||||
|
|
||||||
-------- Main Loop ----------
|
-------- Main Loop ----------
|
||||||
|
|
||||||
typed = ""
|
textFunctions = {} --Declare the Table
|
||||||
keys = {}
|
|
||||||
joys = {}
|
|
||||||
|
|
||||||
--protected ints -> string
|
|
||||||
function pInts2Str(ints)
|
|
||||||
str = ""
|
|
||||||
for _,i in pairs(ints) do
|
|
||||||
if pcall(string.char,i) then
|
|
||||||
str = str..string.char(i)
|
|
||||||
else
|
|
||||||
MelonPrint("NonAscii:"..i)
|
|
||||||
typed = ""
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return str
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
textFunctions = {
|
|
||||||
--MousePosText
|
|
||||||
[1] = function()
|
|
||||||
mouse = GetMouse()
|
|
||||||
return "MousePos:"..mouse.X..","..mouse.Y
|
|
||||||
end,
|
|
||||||
--MouseButtonText
|
|
||||||
[2] = function()
|
|
||||||
mouse = GetMouse()
|
|
||||||
str = ""
|
|
||||||
for k,v in pairs(mouse) do
|
|
||||||
if k~="X" and k~="Y" and v then
|
|
||||||
str = str..k
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return "MouseBtn:"..str
|
|
||||||
end,
|
|
||||||
--KeysText
|
|
||||||
[3] = function()
|
|
||||||
keys = Keys()
|
|
||||||
temp = pInts2Str(keys)
|
|
||||||
typed = typed..temp
|
|
||||||
return "Keys:"..typed
|
|
||||||
end,
|
|
||||||
--JoyText
|
|
||||||
[4] = function()
|
|
||||||
joys = GetJoy()
|
|
||||||
str = ""
|
|
||||||
for k,v in pairs(joys) do
|
|
||||||
if v then
|
|
||||||
str = str..k
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return "Joy:"..str
|
|
||||||
end
|
|
||||||
}
|
|
||||||
|
|
||||||
function TextLoop()
|
|
||||||
SetCanvas(textCanvas)
|
|
||||||
ClearOverlay()
|
|
||||||
local y = 0
|
|
||||||
for _,tfunct in ipairs(textFunctions) do
|
|
||||||
y = y+10
|
|
||||||
Text(0,y,tfunct(),0xffffff)
|
|
||||||
end
|
|
||||||
Flip()
|
|
||||||
end
|
|
||||||
|
|
||||||
Stylus = {
|
Stylus = {
|
||||||
x = 0,
|
x = 0,
|
||||||
|
@ -124,39 +42,42 @@ Btns = {
|
||||||
Tup = true,
|
Tup = true,
|
||||||
Rup = true
|
Rup = true
|
||||||
}
|
}
|
||||||
|
--string -> ASCII Byte (only first char)
|
||||||
|
function BYTE(str)
|
||||||
|
if #str~=1 then
|
||||||
|
error("BYTE expects string of length 1")
|
||||||
|
end
|
||||||
|
return string.byte(str)
|
||||||
|
end
|
||||||
|
|
||||||
|
textCanvas = MakeCanvas(0,12,500,100)
|
||||||
|
vstylusCanvas = MakeCanvas(0,0,256,192,1) -- bottom screen
|
||||||
|
|
||||||
|
--Gets Called once every frame
|
||||||
|
function _Update()
|
||||||
|
|
||||||
|
--Text Functions
|
||||||
|
SetCanvas(textCanvas)
|
||||||
|
ClearOverlay()
|
||||||
|
local y = 0
|
||||||
|
for _,tfunct in ipairs(textFunctions) do
|
||||||
|
y = y+10
|
||||||
|
Text(0,y,tfunct(),0xffffff)
|
||||||
|
end
|
||||||
|
Flip()
|
||||||
|
|
||||||
function StylusLoop()
|
|
||||||
move = {
|
|
||||||
--Key = {dx,dy}
|
|
||||||
["W"] = {0,-1},
|
|
||||||
["A"] = {-1,0},
|
|
||||||
["S"] = {0,1},
|
|
||||||
["D"] = {1,0}
|
|
||||||
}
|
|
||||||
mask = KeyboardMask()
|
mask = KeyboardMask()
|
||||||
for tkey,dir in pairs(move) do
|
|
||||||
if mask[string.byte(tkey)] then
|
|
||||||
Stylus.x=Stylus.x+dir[1]
|
|
||||||
Stylus.y=Stylus.y+dir[2]
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if mask[string.byte("Q")] then
|
|
||||||
NDSTapDown(Stylus.x,Stylus.y)
|
|
||||||
else
|
|
||||||
NDSTapUp()
|
|
||||||
end
|
|
||||||
|
|
||||||
if mask[string.byte("T")] then
|
--Save State
|
||||||
|
if mask[BYTE("T")] then
|
||||||
if Btns.Tup then
|
if Btns.Tup then
|
||||||
StateSave("SaveState_Auto.mln")
|
StateSave("SaveState_Auto.mln")
|
||||||
MelonPrint("Here")
|
|
||||||
Btns.Tup = false
|
Btns.Tup = false
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
Btns.Tup = true
|
Btns.Tup = true
|
||||||
end
|
end
|
||||||
|
if mask[BYTE("R")] then
|
||||||
if mask[string.byte("R")] then
|
|
||||||
if Btns.Rup then
|
if Btns.Rup then
|
||||||
StateLoad("SaveState_Auto.mln")
|
StateLoad("SaveState_Auto.mln")
|
||||||
Btns.Rup = false
|
Btns.Rup = false
|
||||||
|
@ -165,6 +86,85 @@ function StylusLoop()
|
||||||
Btns.Rup = true
|
Btns.Rup = true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--StylusLoop
|
||||||
|
for key,dir in pairs({
|
||||||
|
--Key = {dx,dy}
|
||||||
|
["W"] = { 0,-1},
|
||||||
|
["A"] = {-1, 0},
|
||||||
|
["S"] = { 0, 1},
|
||||||
|
["D"] = { 1, 0}
|
||||||
|
}) do
|
||||||
|
if mask[BYTE(key)] then
|
||||||
|
Stylus.x=Stylus.x+dir[1]
|
||||||
|
Stylus.y=Stylus.y+dir[2]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if mask[BYTE("Q")] then
|
||||||
|
NDSTapDown(Stylus.x,Stylus.y)
|
||||||
|
else
|
||||||
|
NDSTapUp()
|
||||||
|
end
|
||||||
|
DrawStylus(mask)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
--textFunctions
|
||||||
|
|
||||||
|
function MousePosText()
|
||||||
|
mouse = GetMouse()
|
||||||
|
return "MousePos:"..mouse.X..","..mouse.Y
|
||||||
|
end
|
||||||
|
|
||||||
|
function MouseButtonText()
|
||||||
|
mouse = GetMouse()
|
||||||
|
str = ""
|
||||||
|
for k,v in pairs(mouse) do
|
||||||
|
if k~="X" and k~="Y" and v then
|
||||||
|
str = str..k
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return "MouseBtn:"..str
|
||||||
|
end
|
||||||
|
|
||||||
|
typed = ""
|
||||||
|
keys = {}
|
||||||
|
|
||||||
|
function KeysText()
|
||||||
|
keys = Keys()
|
||||||
|
str = ""
|
||||||
|
for _,i in pairs(keys) do
|
||||||
|
if pcall(string.char,i) then
|
||||||
|
str = str..string.char(i)
|
||||||
|
else
|
||||||
|
MelonPrint("NonAscii:"..i)
|
||||||
|
typed = ""
|
||||||
|
end
|
||||||
|
end
|
||||||
|
typed = typed..str
|
||||||
|
return "Keys:"..typed
|
||||||
|
end
|
||||||
|
|
||||||
|
joys = {}
|
||||||
|
|
||||||
|
function JoyText()
|
||||||
|
joys = GetJoy()
|
||||||
|
str = ""
|
||||||
|
for k,v in pairs(joys) do
|
||||||
|
if v then
|
||||||
|
str = str..k
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return "Joy:"..str
|
||||||
|
end
|
||||||
|
|
||||||
|
textFunctions = {MousePosText,MouseButtonText,KeysText,JoyText} --Initalize Table
|
||||||
|
|
||||||
|
--Draw Stylus
|
||||||
|
|
||||||
|
function DrawStylus()
|
||||||
SetCanvas(vstylusCanvas)
|
SetCanvas(vstylusCanvas)
|
||||||
ClearOverlay()
|
ClearOverlay()
|
||||||
Ellipse(Stylus.x-5,Stylus.y-5,10,10,0xffffffff)
|
Ellipse(Stylus.x-5,Stylus.y-5,10,10,0xffffffff)
|
||||||
|
@ -172,9 +172,5 @@ function StylusLoop()
|
||||||
Flip()
|
Flip()
|
||||||
end
|
end
|
||||||
|
|
||||||
textCanvas = MakeCanvas(0,12,500,100)
|
|
||||||
vstylusCanvas = MakeCanvas(0,0,256,192,1) -- bottom screen
|
|
||||||
function _Update()
|
|
||||||
TextLoop()
|
|
||||||
StylusLoop()
|
|
||||||
end
|
|
||||||
|
|
Loading…
Reference in New Issue