删除tick模块,内容移至gametoolfunc
This commit is contained in:
1
main.lua
1
main.lua
@@ -109,7 +109,6 @@ SKIN= require"parts/skin"
|
|||||||
PLY= require"parts/player"
|
PLY= require"parts/player"
|
||||||
AIFUNC= require"parts/ai"
|
AIFUNC= require"parts/ai"
|
||||||
MODES= require"parts/modes"
|
MODES= require"parts/modes"
|
||||||
TICK= require"parts/tick"
|
|
||||||
|
|
||||||
--First start for phones
|
--First start for phones
|
||||||
if not fs.getInfo("conf/settings")and MOBILE then
|
if not fs.getInfo("conf/settings")and MOBILE then
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ local sub=string.sub
|
|||||||
local char,byte=string.char,string.byte
|
local char,byte=string.char,string.byte
|
||||||
local ins,rem=table.insert,table.remove
|
local ins,rem=table.insert,table.remove
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
--Encoding Functions
|
--Encoding Functions
|
||||||
--Sep symbol: 33 (!)
|
--Sep symbol: 33 (!)
|
||||||
--Safe char: 34~126
|
--Safe char: 34~126
|
||||||
@@ -252,6 +254,7 @@ function pasteQuestArgs(str)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
--Royale mode
|
--Royale mode
|
||||||
function randomTarget(P)--Return a random opponent for P
|
function randomTarget(P)--Return a random opponent for P
|
||||||
if #PLAYERS.alive>1 then
|
if #PLAYERS.alive>1 then
|
||||||
@@ -344,6 +347,8 @@ function royaleLevelup()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
--Game
|
--Game
|
||||||
function freshDate()
|
function freshDate()
|
||||||
local date=os.date("%Y/%m/%d")
|
local date=os.date("%Y/%m/%d")
|
||||||
@@ -790,4 +795,69 @@ do--lnk_CUS/SETXXX(k)
|
|||||||
function lnk_SETrev(k)return function()s[k]=not s[k]end end
|
function lnk_SETrev(k)return function()s[k]=not s[k]end end
|
||||||
function lnk_CUSsto(k)return function(i)c[k]=i end end
|
function lnk_CUSsto(k)return function(i)c[k]=i end end
|
||||||
function lnk_SETsto(k)return function(i)s[k]=i end end
|
function lnk_SETsto(k)return function(i)s[k]=i end end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
--Network tick function
|
||||||
|
function TICK_httpREQ_getAccessToken(task)
|
||||||
|
local time=0
|
||||||
|
while true do
|
||||||
|
coroutine.yield()
|
||||||
|
local response,request_error=client.poll(task)
|
||||||
|
if response then
|
||||||
|
if response.code==200 then
|
||||||
|
local res=json.decode(response.body)
|
||||||
|
if res then
|
||||||
|
LOG.print(text.accessSuccessed)
|
||||||
|
USER.access_token=res.access_token
|
||||||
|
FILE.save(USER,"conf/user")
|
||||||
|
SCN.swapTo("net_menu")
|
||||||
|
else
|
||||||
|
LOG.print(text.netErrorCode..response.code..": "..res.message,"warn")
|
||||||
|
end
|
||||||
|
else
|
||||||
|
LOGIN=false
|
||||||
|
USER.access_token=false
|
||||||
|
USER.auth_token=false
|
||||||
|
local err=json.decode(response.body)
|
||||||
|
if err then
|
||||||
|
LOG.print(text.loginFailed..": "..text.netErrorCode..response.code.."-"..err.message,"warn")
|
||||||
|
else
|
||||||
|
LOG.print(text.loginFailed..": "..text.netErrorCode,"warn")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return
|
||||||
|
elseif request_error then
|
||||||
|
LOG.print(text.loginFailed..": "..request_error,"warn")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
time=time+1
|
||||||
|
if time>360 then
|
||||||
|
LOG.print(text.loginFailed..": "..text.httpTimeout,"message")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
function TICK_wsRead()
|
||||||
|
while true do
|
||||||
|
coroutine.yield()
|
||||||
|
if not WSCONN then return end
|
||||||
|
local messages,readErr=client.read(WSCONN)
|
||||||
|
if messages then
|
||||||
|
if SCN.socketRead then
|
||||||
|
for i=1,#messages do
|
||||||
|
SCN.socketRead(messages[i])
|
||||||
|
end
|
||||||
|
else
|
||||||
|
return
|
||||||
|
end
|
||||||
|
elseif readErr then
|
||||||
|
wsWrite("/quit")
|
||||||
|
WSCONN=false
|
||||||
|
LOG.print(text.wsError..tostring(readErr),"warn")
|
||||||
|
SCN.back()
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
@@ -14,7 +14,7 @@ local function tick_httpREQ_newLogin(task)
|
|||||||
FILE.save(USER,"conf/user","q")
|
FILE.save(USER,"conf/user","q")
|
||||||
|
|
||||||
httpRequest(
|
httpRequest(
|
||||||
TICK.httpREQ_getAccessToken,
|
TICK_httpREQ_getAccessToken,
|
||||||
PATH.api..PATH.access,
|
PATH.api..PATH.access,
|
||||||
"POST",
|
"POST",
|
||||||
{["Content-Type"]="application/json"},
|
{["Content-Type"]="application/json"},
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ local function tick_httpREQ_checkAccessToken(task)
|
|||||||
SCN.go("net_menu")
|
SCN.go("net_menu")
|
||||||
elseif response.code==403 or response.code==401 then
|
elseif response.code==403 or response.code==401 then
|
||||||
httpRequest(
|
httpRequest(
|
||||||
TICK.httpREQ_getAccessToken,
|
TICK_httpREQ_getAccessToken,
|
||||||
PATH.api..PATH.access,
|
PATH.api..PATH.access,
|
||||||
"POST",
|
"POST",
|
||||||
{["Content-Type"]="application/json"},
|
{["Content-Type"]="application/json"},
|
||||||
@@ -94,7 +94,7 @@ scene.widgetList={
|
|||||||
)
|
)
|
||||||
else
|
else
|
||||||
httpRequest(
|
httpRequest(
|
||||||
TICK.httpREQ_getAccessToken,
|
TICK_httpREQ_getAccessToken,
|
||||||
PATH.api..PATH.access,
|
PATH.api..PATH.access,
|
||||||
"POST",
|
"POST",
|
||||||
{["Content-Type"]="application/json"},
|
{["Content-Type"]="application/json"},
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ function scene.sceneInit()
|
|||||||
end
|
end
|
||||||
scrollPos=#texts
|
scrollPos=#texts
|
||||||
TASK.new(focusAtTextbox)--Widgets are not initialized, so active after 1 frame
|
TASK.new(focusAtTextbox)--Widgets are not initialized, so active after 1 frame
|
||||||
TASK.new(TICK.ws_read)
|
TASK.new(TICK_wsRead)
|
||||||
BG.set("none")
|
BG.set("none")
|
||||||
end
|
end
|
||||||
function scene.sceneBack()
|
function scene.sceneBack()
|
||||||
|
|||||||
@@ -1,63 +0,0 @@
|
|||||||
local Tick={}
|
|
||||||
function Tick.httpREQ_getAccessToken(task)
|
|
||||||
local time=0
|
|
||||||
while true do
|
|
||||||
coroutine.yield()
|
|
||||||
local response,request_error=client.poll(task)
|
|
||||||
if response then
|
|
||||||
if response.code==200 then
|
|
||||||
local res=json.decode(response.body)
|
|
||||||
if res then
|
|
||||||
LOG.print(text.accessSuccessed)
|
|
||||||
USER.access_token=res.access_token
|
|
||||||
FILE.save(USER,"conf/user")
|
|
||||||
SCN.swapTo("net_menu")
|
|
||||||
else
|
|
||||||
LOG.print(text.netErrorCode..response.code..": "..res.message,"warn")
|
|
||||||
end
|
|
||||||
else
|
|
||||||
LOGIN=false
|
|
||||||
USER.access_token=false
|
|
||||||
USER.auth_token=false
|
|
||||||
local err=json.decode(response.body)
|
|
||||||
if err then
|
|
||||||
LOG.print(text.loginFailed..": "..text.netErrorCode..response.code.."-"..err.message,"warn")
|
|
||||||
else
|
|
||||||
LOG.print(text.loginFailed..": "..text.netErrorCode,"warn")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return
|
|
||||||
elseif request_error then
|
|
||||||
LOG.print(text.loginFailed..": "..request_error,"warn")
|
|
||||||
return
|
|
||||||
end
|
|
||||||
time=time+1
|
|
||||||
if time>360 then
|
|
||||||
LOG.print(text.loginFailed..": "..text.httpTimeout,"message")
|
|
||||||
return
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function Tick.ws_read()
|
|
||||||
while true do
|
|
||||||
coroutine.yield()
|
|
||||||
if not WSCONN then return end
|
|
||||||
local messages,readErr=client.read(WSCONN)
|
|
||||||
if messages then
|
|
||||||
if SCN.socketRead then
|
|
||||||
for i=1,#messages do
|
|
||||||
SCN.socketRead(messages[i])
|
|
||||||
end
|
|
||||||
else
|
|
||||||
return
|
|
||||||
end
|
|
||||||
elseif readErr then
|
|
||||||
wsWrite("/quit")
|
|
||||||
WSCONN=false
|
|
||||||
LOG.print(text.wsDisconnected,"warn")
|
|
||||||
return
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return Tick
|
|
||||||
Reference in New Issue
Block a user