commit e0d4ac49931a10695b34daf4ad3d619d279e0e0e
Author: DPS2004 <dpsophinos@gmail.com>
AuthorDate: Tue Mar 1 14:16:16 2022 -0500
Commit: DPS2004 <dpsophinos@gmail.com>
CommitDate: Mon May 2 09:34:18 2022 -0400
settings cart can load setting values
---
source/FakoSettings.h | 16 +++++++++-------
source/host.h | 3 +++
source/hostCommonFunctions.cpp | 19 +++++++++++++++++++
source/picoluaapi.cpp | 27 +++++++++++++++++++++++++++
source/picoluaapi.h | 5 +++++
source/vm.cpp | 12 ++++++++++++
source/vm.h | 3 +++
7 files changed, 78 insertions(+), 7 deletions(-)
diff --git a/source/FakoSettings.h b/source/FakoSettings.h
index fcb4a57..6a5efcd 100644
--- a/source/FakoSettings.h
+++ b/source/FakoSettings.h
@@ -13,14 +13,14 @@ version 33
__lua__
function _init()
- if not __fakogetsetting then
+ if not __getsetting then
printh('not in fake-08 (or unimplemented...), stubbing get and set functions!')
- function __fakogetsetting(sn)
+ function __getsetting(sn)
printh('trying to get setting ' .. sn)
- return 1
+ return 0
end
- function __fakosetsetting(sn,v)
+ function __setsetting(sn,v)
printh('trying to set setting ' .. sn .. ' to '..v)
end
@@ -29,7 +29,7 @@ function _init()
settinglist = {'kbmode','enableresize','stretch','menustyle'}
settings = {}
for i,v in ipairs(settinglist) do
- settings[v] = __fakogetsetting(v)
+ settings[v] = __getsetting(v) + 1
end
list = {
@@ -127,7 +127,7 @@ function updatecursor()
else
if inoption then
settings[cvariable] = cursorpos
- __fakosetsetting(cvariable,cursorpos-1)
+ __setsetting(cvariable,cursorpos-1)
else
add(path,cursorpos)
end
@@ -157,7 +157,9 @@ function drawitem(n,y,x)
end
function drawcursor()
- spr(5,13,18+(menuspace*cursorpos),1,2)
+ if cursorpos then --unknown why this matters?
+ spr(5,13,18+(menuspace*cursorpos),1,2)
+ end
end
function _draw()
diff --git a/source/host.h b/source/host.h
index e1e9c64..bffa937 100644
--- a/source/host.h
+++ b/source/host.h
@@ -107,6 +107,9 @@ class Host {
void saveCartData(std::string cartDataKey, std::string contents);
std::string getCartDirectory();
+
+ //settings
+ int getSetting(std::string sname);
Color* GetPaletteColors();
diff --git a/source/hostCommonFunctions.cpp b/source/hostCommonFunctions.cpp
index 8969617..a677d40 100644
--- a/source/hostCommonFunctions.cpp
+++ b/source/hostCommonFunctions.cpp
@@ -194,4 +194,23 @@ void Host::saveCartData(std::string cartDataKey, std::string contents) {
fclose(file);
}
+}
+
+//settings
+
+int Host::getSetting(std::string sname) {
+
+ if(sname == "kbmode"){ //why cant you use strings in switch statements in c++ :(
+ Logger_Write("Returning KB mode setting\n");
+ return kbmode;
+ }else if(sname == "stretch"){
+ Logger_Write("Returning Stretch setting\n");
+ return stretch;
+ }else{
+ Logger_Write("Setting ");
+ Logger_Write(sname.c_str());
+ Logger_Write(" not found, returning 0!");
+ return 0;
+ }
+
}
\ No newline at end of file
diff --git a/source/picoluaapi.cpp b/source/picoluaapi.cpp
index 7564d81..fcbffa3 100644
--- a/source/picoluaapi.cpp
+++ b/source/picoluaapi.cpp
@@ -1308,3 +1308,30 @@ int resetcart(lua_State *L) {
return 0;
}
+
+
+int getsetting(lua_State *L) {
+ //get setting from host
+
+ const char * str = "";
+ if (lua_isstring(L, 1)){
+ str = lua_tolstring(L, 1, nullptr);
+ }
+ Logger_Write("loading setting ");
+ Logger_Write(str);
+ Logger_Write("\n");
+ //std::string sname = str;
+
+ int val = _vmForLuaApi->getSetting(str);
+
+ lua_pushnumber(L, val);
+
+ return 1;
+}
+
+int setsetting(lua_State *L) {
+ //get setting from host
+
+
+ return 1;
+}
\ No newline at end of file
diff --git a/source/picoluaapi.h b/source/picoluaapi.h
index 94116b9..88056d7 100644
--- a/source/picoluaapi.h
+++ b/source/picoluaapi.h
@@ -100,6 +100,11 @@ int loadsettingscart(lua_State *L);
int togglepausemenu(lua_State *L);
int resetcart(lua_State *L);
+//settings functions
+
+int getsetting(lua_State *L);
+int setsetting(lua_State *L);
+
//system functions
int rnd(lua_State *L);
diff --git a/source/vm.cpp b/source/vm.cpp
index 5d529e9..ebb7b42 100644
--- a/source/vm.cpp
+++ b/source/vm.cpp
@@ -169,6 +169,10 @@ bool Vm::loadCart(Cart* cart) {
lua_register(_luaState, "__togglepausemenu", togglepausemenu);
lua_register(_luaState, "__resetcart", resetcart);
lua_register(_luaState, "load", load);
+
+ //settings
+ lua_register(_luaState, "__getsetting", getsetting);
+ lua_register(_luaState, "__setsetting", setsetting);
//register global functions first, they will get local aliases when
//the rest of the api is registered
@@ -1034,3 +1038,11 @@ std::string Vm::getCartBreadcrumb() {
std::string Vm::getCartParam() {
return _cartParam;
}
+
+
+//settings
+int Vm::getSetting(std::string sname) {
+
+ return _host->getSetting(sname);
+
+}
\ No newline at end of file
diff --git a/source/vm.h b/source/vm.h
index af9e481..d4ed2e4 100644
--- a/source/vm.h
+++ b/source/vm.h
@@ -145,6 +145,9 @@ class Vm {
int getHour();
int getMinute();
int getSecond();
+
+ //settings
+ int getSetting(string sname);
string getCartBreadcrumb();
string getCartParam();