整理gametoolfunc,添加注释
This commit is contained in:
@@ -7,88 +7,6 @@ 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
|
||||||
|
|
||||||
local gameSetting={
|
|
||||||
--Tuning
|
|
||||||
"das","arr","dascut","sddas","sdarr",
|
|
||||||
"ihs","irs","ims","RS","swap",
|
|
||||||
|
|
||||||
--System
|
|
||||||
"skin","face",
|
|
||||||
|
|
||||||
--Graphic
|
|
||||||
"block","ghost","center","smooth","grid","bagLine",
|
|
||||||
"lockFX","dropFX","moveFX","clearFX","splashFX","shakeFX","atkFX",
|
|
||||||
"text","score","warn","highCam","nextPos",
|
|
||||||
}
|
|
||||||
local function copyGameSetting()
|
|
||||||
local S={}
|
|
||||||
for _,key in next,gameSetting do
|
|
||||||
if type(SETTING[key])=="table"then
|
|
||||||
S[key]=copyList(SETTING[key])
|
|
||||||
else
|
|
||||||
S[key]=SETTING[key]
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return S
|
|
||||||
end
|
|
||||||
|
|
||||||
function destroyPlayers()
|
|
||||||
for i=#PLAYERS,1,-1 do
|
|
||||||
local P=PLAYERS[i]
|
|
||||||
if P.canvas then P.canvas:release()end
|
|
||||||
while P.field[1]do
|
|
||||||
FREEROW.discard(rem(P.field))
|
|
||||||
FREEROW.discard(rem(P.visTime))
|
|
||||||
end
|
|
||||||
if P.AI_mode=="CC"then
|
|
||||||
CC.free(P.bot_opt)
|
|
||||||
CC.free(P.bot_wei)
|
|
||||||
CC.destroy(P.AI_bot)
|
|
||||||
P.AI_mode=false
|
|
||||||
end
|
|
||||||
PLAYERS[i]=nil
|
|
||||||
end
|
|
||||||
for i=#PLAYERS.alive,1,-1 do
|
|
||||||
PLAYERS.alive[i]=nil
|
|
||||||
end
|
|
||||||
collectgarbage()
|
|
||||||
end
|
|
||||||
|
|
||||||
function restoreVirtualKey()
|
|
||||||
for i=1,#VK_org do
|
|
||||||
local B,O=virtualkey[i],VK_org[i]
|
|
||||||
B.ava=O.ava
|
|
||||||
B.x=O.x
|
|
||||||
B.y=O.y
|
|
||||||
B.r=O.r
|
|
||||||
B.isDown=false
|
|
||||||
B.pressTime=0
|
|
||||||
end
|
|
||||||
for k,v in next,PLAYERS[1].keyAvailable do
|
|
||||||
if not v then
|
|
||||||
virtualkey[k].ava=false
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function copyQuestArgs()
|
|
||||||
local ENV=CUSTOMENV
|
|
||||||
local str=""..
|
|
||||||
ENV.holdCount..
|
|
||||||
(ENV.ospin and"O"or"Z")..
|
|
||||||
(ENV.missionKill and"M"or"Z")..
|
|
||||||
ENV.sequence
|
|
||||||
return str
|
|
||||||
end
|
|
||||||
function pasteQuestArgs(str)
|
|
||||||
if #str<4 then return end
|
|
||||||
local ENV=CUSTOMENV
|
|
||||||
ENV.holdCount= byte(str,1)-48
|
|
||||||
ENV.ospin= byte(str,2)~=90
|
|
||||||
ENV.missionKill= byte(str,3)~=90
|
|
||||||
ENV.sequence= sub(str,4)
|
|
||||||
end
|
|
||||||
|
|
||||||
--Encoding Functions
|
--Encoding Functions
|
||||||
--Sep symbol: 33 (!)
|
--Sep symbol: 33 (!)
|
||||||
--Safe char: 34~126
|
--Safe char: 34~126
|
||||||
@@ -315,47 +233,26 @@ function pasteMission(str)
|
|||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
function freshDate()
|
function copyQuestArgs()
|
||||||
local date=os.date("%Y/%m/%d")
|
local ENV=CUSTOMENV
|
||||||
if STAT.date~=date then
|
local str=""..
|
||||||
STAT.date=date
|
ENV.holdCount..
|
||||||
STAT.todayTime=0
|
(ENV.ospin and"O"or"Z")..
|
||||||
LOG.print(text.newDay,"message")
|
(ENV.missionKill and"M"or"Z")..
|
||||||
end
|
ENV.sequence
|
||||||
|
return str
|
||||||
end
|
end
|
||||||
function legalGameTime()
|
function pasteQuestArgs(str)
|
||||||
if
|
if #str<4 then return end
|
||||||
(SETTING.lang==1 or SETTING.lang==2 or SETTING.lang==7)and
|
local ENV=CUSTOMENV
|
||||||
RANKS.sprint_10<4 and
|
ENV.holdCount= byte(str,1)-48
|
||||||
(not RANKS.sprint_40 or RANKS.sprint_40<3)
|
ENV.ospin= byte(str,2)~=90
|
||||||
then
|
ENV.missionKill= byte(str,3)~=90
|
||||||
if STAT.todayTime<14400 then
|
ENV.sequence= sub(str,4)
|
||||||
return true
|
|
||||||
elseif STAT.todayTime<21600 then
|
|
||||||
LOG.print(text.playedLong,"warning")
|
|
||||||
return true
|
|
||||||
else
|
|
||||||
LOG.print(text.playedTooMuch,"warning")
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
function mergeStat(stat,delta)
|
|
||||||
for k,v in next,delta do
|
|
||||||
if type(v)=="table"then
|
|
||||||
if type(stat[k])=="table"then
|
|
||||||
mergeStat(stat[k],v)
|
|
||||||
end
|
|
||||||
else
|
|
||||||
if stat[k]then
|
|
||||||
stat[k]=stat[k]+v
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--Functions for 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
|
||||||
local R
|
local R
|
||||||
@@ -447,6 +344,91 @@ function royaleLevelup()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--Game
|
||||||
|
function freshDate()
|
||||||
|
local date=os.date("%Y/%m/%d")
|
||||||
|
if STAT.date~=date then
|
||||||
|
STAT.date=date
|
||||||
|
STAT.todayTime=0
|
||||||
|
LOG.print(text.newDay,"message")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
function legalGameTime()--Check if today's playtime is legal
|
||||||
|
if
|
||||||
|
(SETTING.lang==1 or SETTING.lang==2 or SETTING.lang==7)and
|
||||||
|
RANKS.sprint_10<4 and
|
||||||
|
(not RANKS.sprint_40 or RANKS.sprint_40<3)
|
||||||
|
then
|
||||||
|
if STAT.todayTime<14400 then
|
||||||
|
return true
|
||||||
|
elseif STAT.todayTime<21600 then
|
||||||
|
LOG.print(text.playedLong,"warning")
|
||||||
|
return true
|
||||||
|
else
|
||||||
|
LOG.print(text.playedTooMuch,"warning")
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
function mergeStat(stat,delta)--Merge delta stat. to global stat.
|
||||||
|
for k,v in next,delta do
|
||||||
|
if type(v)=="table"then
|
||||||
|
if type(stat[k])=="table"then
|
||||||
|
mergeStat(stat[k],v)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
if stat[k]then
|
||||||
|
stat[k]=stat[k]+v
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
function scoreValid()--Check if any unranked mods are activated
|
||||||
|
for _,M in next,GAME.mod do
|
||||||
|
if M.unranked then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
function destroyPlayers()--Destroy all player objects, restore freerows and free CCs
|
||||||
|
for i=#PLAYERS,1,-1 do
|
||||||
|
local P=PLAYERS[i]
|
||||||
|
if P.canvas then P.canvas:release()end
|
||||||
|
while P.field[1]do
|
||||||
|
FREEROW.discard(rem(P.field))
|
||||||
|
FREEROW.discard(rem(P.visTime))
|
||||||
|
end
|
||||||
|
if P.AI_mode=="CC"then
|
||||||
|
CC.free(P.bot_opt)
|
||||||
|
CC.free(P.bot_wei)
|
||||||
|
CC.destroy(P.AI_bot)
|
||||||
|
P.AI_mode=false
|
||||||
|
end
|
||||||
|
PLAYERS[i]=nil
|
||||||
|
end
|
||||||
|
for i=#PLAYERS.alive,1,-1 do
|
||||||
|
PLAYERS.alive[i]=nil
|
||||||
|
end
|
||||||
|
collectgarbage()
|
||||||
|
end
|
||||||
|
function restoreVirtualKey()
|
||||||
|
for i=1,#VK_org do
|
||||||
|
local B,O=virtualkey[i],VK_org[i]
|
||||||
|
B.ava=O.ava
|
||||||
|
B.x=O.x
|
||||||
|
B.y=O.y
|
||||||
|
B.r=O.r
|
||||||
|
B.isDown=false
|
||||||
|
B.pressTime=0
|
||||||
|
end
|
||||||
|
for k,v in next,PLAYERS[1].keyAvailable do
|
||||||
|
if not v then
|
||||||
|
virtualkey[k].ava=false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
function pauseGame()
|
function pauseGame()
|
||||||
if not SCN.swapping then
|
if not SCN.swapping then
|
||||||
GAME.restartCount=0--Avoid strange darkness
|
GAME.restartCount=0--Avoid strange darkness
|
||||||
@@ -466,7 +448,7 @@ end
|
|||||||
function resumeGame()
|
function resumeGame()
|
||||||
SCN.swapTo("play","none")
|
SCN.swapTo("play","none")
|
||||||
end
|
end
|
||||||
function applyCustomGame()
|
function applyCustomGame()--Apply CUSTOMENV, BAG, MISSION
|
||||||
for k,v in next,CUSTOMENV do
|
for k,v in next,CUSTOMENV do
|
||||||
GAME.modeEnv[k]=v
|
GAME.modeEnv[k]=v
|
||||||
end
|
end
|
||||||
@@ -532,7 +514,8 @@ function initPlayerPosition(sudden)--Set initial position for every player
|
|||||||
end end
|
end end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
local function tick_showMods()
|
do--function resetGameData(args)
|
||||||
|
local function tick_showMods()
|
||||||
local time=0
|
local time=0
|
||||||
while true do
|
while true do
|
||||||
coroutine.yield()
|
coroutine.yield()
|
||||||
@@ -546,8 +529,32 @@ local function tick_showMods()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
function resetGameData(args)
|
local gameSetting={
|
||||||
|
--Tuning
|
||||||
|
"das","arr","dascut","sddas","sdarr",
|
||||||
|
"ihs","irs","ims","RS","swap",
|
||||||
|
|
||||||
|
--System
|
||||||
|
"skin","face",
|
||||||
|
|
||||||
|
--Graphic
|
||||||
|
"block","ghost","center","smooth","grid","bagLine",
|
||||||
|
"lockFX","dropFX","moveFX","clearFX","splashFX","shakeFX","atkFX",
|
||||||
|
"text","score","warn","highCam","nextPos",
|
||||||
|
}
|
||||||
|
local function copyGameSetting()
|
||||||
|
local S={}
|
||||||
|
for _,key in next,gameSetting do
|
||||||
|
if type(SETTING[key])=="table"then
|
||||||
|
S[key]=copyList(SETTING[key])
|
||||||
|
else
|
||||||
|
S[key]=SETTING[key]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return S
|
||||||
|
end
|
||||||
|
function resetGameData(args)
|
||||||
if not args then args=""end
|
if not args then args=""end
|
||||||
if PLAYERS[1]and not GAME.replaying and(GAME.frame>400 or GAME.result)then
|
if PLAYERS[1]and not GAME.replaying and(GAME.frame>400 or GAME.result)then
|
||||||
mergeStat(STAT,PLAYERS[1].stat)
|
mergeStat(STAT,PLAYERS[1].stat)
|
||||||
@@ -605,8 +612,9 @@ function resetGameData(args)
|
|||||||
TASK.new(tick_showMods)
|
TASK.new(tick_showMods)
|
||||||
SFX.play("ready")
|
SFX.play("ready")
|
||||||
collectgarbage()
|
collectgarbage()
|
||||||
|
end
|
||||||
end
|
end
|
||||||
function gameStart()
|
function gameStart()--Call when countdown finish (GAME.frame==180)
|
||||||
SFX.play("start")
|
SFX.play("start")
|
||||||
for P=1,#PLAYERS do
|
for P=1,#PLAYERS do
|
||||||
P=PLAYERS[P]
|
P=PLAYERS[P]
|
||||||
@@ -615,14 +623,7 @@ function gameStart()
|
|||||||
P:popNext()
|
P:popNext()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
function scoreValid()--Check if any unranked mods are activated
|
|
||||||
for _,M in next,GAME.mod do
|
|
||||||
if M.unranked then
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
--[[
|
--[[
|
||||||
Byte data format: (1 byte each period)
|
Byte data format: (1 byte each period)
|
||||||
KeyID, dt, KeyID, dt, ......
|
KeyID, dt, KeyID, dt, ......
|
||||||
@@ -705,7 +706,6 @@ function pumpRecording(str,L)
|
|||||||
end
|
end
|
||||||
return list
|
return list
|
||||||
end
|
end
|
||||||
|
|
||||||
do--function saveRecording()
|
do--function saveRecording()
|
||||||
local noRecList={"custom","solo","round","techmino"}
|
local noRecList={"custom","solo","round","techmino"}
|
||||||
local function getModList()
|
local function getModList()
|
||||||
@@ -751,6 +751,9 @@ do--function saveRecording()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
--Widget function shortcuts
|
||||||
function backScene()SCN.back()end
|
function backScene()SCN.back()end
|
||||||
do--function goScene(name,style)
|
do--function goScene(name,style)
|
||||||
local cache={}
|
local cache={}
|
||||||
|
|||||||
Reference in New Issue
Block a user