fixed LuaSaveState

This commit is contained in:
NPO 2024-10-17 09:09:08 -04:00
parent 7283efcb03
commit 4f1b1d12e0
2 changed files with 39 additions and 12 deletions

View File

@ -1685,8 +1685,8 @@ void MainWindow::onOpenLuaScript()
return; return;
this->luaDialog = new LuaConsoleDialog(this); this->luaDialog = new LuaConsoleDialog(this);
this->luaDialog->show(); this->luaDialog->show();
//connect(emuThread,&EmuThread::signalLuaSaveState,mainWindow,&MainWindow::onLuaSaveState); connect(emuThread,&EmuThread::signalLuaSaveState,this,&MainWindow::onLuaSaveState);
//connect(emuThread,&EmuThread::signalLuaLoadState,mainWindow,&MainWindow::onLuaLoadState); connect(emuThread,&EmuThread::signalLuaLoadState,this,&MainWindow::onLuaLoadState);
} }
void MainWindow::onEnableCheats(bool checked) void MainWindow::onEnableCheats(bool checked)

View File

@ -1,6 +1,8 @@
-- Simple Script to test most of the different Lua Functions for MelonDS -- Simple Script to test most of the different Lua Functions for MelonDS
-- Written by NPO197 -- Written by NPO197
--TODO: re-write to make more readable
MelonClear() MelonClear()
MelonPrint("This text Should be cleared") MelonPrint("This text Should be cleared")
@ -37,8 +39,8 @@ 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)
--ClearHash() --ClearHash()
Flip() Flip()
@ -105,7 +107,7 @@ textFunctions = {
function TextLoop() function TextLoop()
SetCanvas(textCanvas) SetCanvas(textCanvas)
ClearOverlay() ClearOverlay()
y = 0 local y = 0
for _,tfunct in ipairs(textFunctions) do for _,tfunct in ipairs(textFunctions) do
y = y+10 y = y+10
Text(0,y,tfunct(),0xffffff) Text(0,y,tfunct(),0xffffff)
@ -118,7 +120,12 @@ Stylus = {
y = 0, y = 0,
} }
function Stylus:Loop() Btns = {
Tup = true,
Rup = true
}
function StylusLoop()
move = { move = {
--Key = {dx,dy} --Key = {dx,dy}
["W"] = {0,-1}, ["W"] = {0,-1},
@ -129,19 +136,39 @@ function Stylus:Loop()
mask = KeyboardMask() mask = KeyboardMask()
for tkey,dir in pairs(move) do for tkey,dir in pairs(move) do
if mask[string.byte(tkey)] then if mask[string.byte(tkey)] then
self.x=self.x+dir[1] Stylus.x=Stylus.x+dir[1]
self.y=self.y+dir[2] Stylus.y=Stylus.y+dir[2]
end end
end end
if mask[string.byte("Q")] then if mask[string.byte("Q")] then
NDSTapDown(self.x,self.y) NDSTapDown(Stylus.x,Stylus.y)
else else
NDSTapUp() NDSTapUp()
end end
if mask[string.byte("T")] then
if Btns.Tup then
StateSave("SaveState_Auto.mln")
MelonPrint("Here")
Btns.Tup = false
end
else
Btns.Tup = true
end
if mask[string.byte("R")] then
if Btns.Rup then
StateLoad("SaveState_Auto.mln")
Btns.Rup = false
end
else
Btns.Rup = true
end
SetCanvas(vstylusCanvas) SetCanvas(vstylusCanvas)
ClearOverlay() ClearOverlay()
Ellipse(self.x-5,self.y-5,10,10,0xffffffff) Ellipse(Stylus.x-5,Stylus.y-5,10,10,0xffffffff)
Ellipse(self.x-2,self.y-2,4,4,0x00000000) Ellipse(Stylus.x-2,Stylus.y-2,4,4,0x00000000)
Flip() Flip()
end end
@ -149,5 +176,5 @@ textCanvas = MakeCanvas(0,12,500,100)
vstylusCanvas = MakeCanvas(0,0,256,192,1) -- bottom screen vstylusCanvas = MakeCanvas(0,0,256,192,1) -- bottom screen
function _Update() function _Update()
TextLoop() TextLoop()
Stylus:Loop() StylusLoop()
end end