整理代码

This commit is contained in:
MrZ_26
2024-11-03 01:51:46 +08:00
parent 59903397a7
commit 35aacc1a3e
4 changed files with 15 additions and 31 deletions

View File

@@ -8,7 +8,7 @@ local sleep=require'love.timer'.sleep
local retrieving=false local retrieving=false
while true do while true do
if trigCHN:getCount()>0 then if trigCHN:getCount()>0 then
local dt = trigCHN:pop() local dt=trigCHN:pop()
if setCHN:getCount()>0 then if setCHN:getCount()>0 then
while setCHN:getCount()>1 do setCHN:pop() end while setCHN:getCount()>1 do setCHN:pop() end
-- Set Clipboard -- Set Clipboard

View File

@@ -4,15 +4,7 @@ NONE={}function NULL() end PAPER=love.graphics.newCanvas(1,1)
EDITING="" EDITING=""
LOADED=false LOADED=false
--[[ ---@type 'Windows'|'Android'|'Linux'|'iOS'|'macOS'|'Web'
Available SYSTEM values:
Android
iOS
Linux
macOS
Web
Windows
]]--
SYSTEM=love.system.getOS() SYSTEM=love.system.getOS()
WEB_COMPAT_MODE=false WEB_COMPAT_MODE=false
if SYSTEM=='OS X' then if SYSTEM=='OS X' then

View File

@@ -1,7 +1,6 @@
local __requestQueue={} local __requestQueue={}
local _requestCount=0 local _requestCount=0
local _Request= local _Request={
{
command="", command="",
currentTime=0, currentTime=0,
timeOut=2, timeOut=2,
@@ -25,12 +24,11 @@ function JS.stringFunc(str,...)
if (#arg>0) then if (#arg>0) then
str=str:format(unpack(arg)) str=str:format(unpack(arg))
end end
str=str:gsub("[\n\t]", "") str=str:gsub("[\n\t]","")
return str return str
end end
--The call will store in the webDB the return value from the function passed --The call will store in the webDB the return value from the function passed it timeouts
--it timeouts
local function retrieveJS(funcToCall,filename) local function retrieveJS(funcToCall,filename)
--Used for retrieveData function --Used for retrieveData function
JS.callJS(("FS.writeFile('%s/%s',%s);"):format(love.filesystem.getSaveDirectory(),filename,funcToCall)) JS.callJS(("FS.writeFile('%s/%s',%s);"):format(love.filesystem.getSaveDirectory(),filename,funcToCall))
@@ -39,11 +37,11 @@ end
--Call JS.newRequest instead --Call JS.newRequest instead
function _Request:new(isPromise,command,onDataLoaded,onError,timeout,id) function _Request:new(isPromise,command,onDataLoaded,onError,timeout,id)
local obj={} local obj={}
setmetatable(obj, self) setmetatable(obj,self)
obj.command=command obj.command=command
obj.onError=onError or __defaultErrorFunction obj.onError=onError or __defaultErrorFunction
if not isPromise then if not isPromise then
retrieveJS(command, self.filename) retrieveJS(command,self.filename)
else else
JS.callJS(command) JS.callJS(command)
end end
@@ -76,7 +74,7 @@ function _Request:new(isPromise,command,onDataLoaded,onError,timeout,id)
end end
self.onDataLoaded(retData) self.onDataLoaded(retData)
else else
self.onError(self.id, retData) self.onError(self.id,retData)
end end
self:purgeData() self:purgeData()
return false return false
@@ -94,21 +92,21 @@ function JS.retrieveData(dt)
for i=1,#__requestQueue do for i=1,#__requestQueue do
local isUpdating=__requestQueue[i]:update(dt) local isUpdating=__requestQueue[i]:update(dt)
if not isUpdating then if not isUpdating then
table.insert(deadRequests, i) table.insert(deadRequests,i)
end end
end end
for i=1,#deadRequests do for i=1,#deadRequests do
if (isDebugActive) then if (isDebugActive) then
print("Request died: "..deadRequests[i]) print("Request died: "..deadRequests[i])
end end
table.remove(__requestQueue, deadRequests[i]) table.remove(__requestQueue,deadRequests[i])
end end
return isRetrieving return isRetrieving
end end
--May only be used for functions that don't return a promise --May only be used for functions that don't return a promise
function JS.newRequest(funcToCall,onDataLoaded,onError,timeout,optionalId) function JS.newRequest(funcToCall,onDataLoaded,onError,timeout,optionalId)
table.insert(__requestQueue, _Request:new(false, funcToCall, onDataLoaded, onError, timeout or 5, optionalId or _requestCount)) table.insert(__requestQueue,_Request:new(false,funcToCall,onDataLoaded,onError,timeout or 5,optionalId or _requestCount))
end end
--This function can be handled manually (in JS code) --This function can be handled manually (in JS code)
@@ -117,8 +115,8 @@ end
-- _$_(yourStringOrFunctionHere) -- _$_(yourStringOrFunctionHere)
function JS.newPromiseRequest(funcToCall,onDataLoaded,onError,timeout,optionalId) function JS.newPromiseRequest(funcToCall,onDataLoaded,onError,timeout,optionalId)
optionalId=optionalId or _requestCount optionalId=optionalId or _requestCount
funcToCall=funcToCall:gsub("_$_%(", "FS.writeFile('"..love.filesystem.getSaveDirectory().."/__temp"..optionalId.."', ") funcToCall=funcToCall:gsub("_$_%(","FS.writeFile('"..love.filesystem.getSaveDirectory().."/__temp"..optionalId.."', ")
table.insert(__requestQueue, _Request:new(true, funcToCall, onDataLoaded, onError, timeout or 5, optionalId)) table.insert(__requestQueue,_Request:new(true,funcToCall,onDataLoaded,onError,timeout or 5,optionalId))
end end
@@ -139,10 +137,6 @@ JS.setDefaultErrorFunction(function(id,error)
end) end)
JS.callJS(JS.stringFunc( JS.callJS(JS.stringFunc("__getWebDB("%s");","__LuaJSDB"))
[[
__getWebDB("%s");
]]
, "__LuaJSDB"))
return JS return JS

View File

@@ -1,7 +1,5 @@
if SYSTEM=='Web' then if SYSTEM=='Web' then
return { return {update=NULL}
update=NULL
}
end end
local appId='1288557386700951554' local appId='1288557386700951554'