整理代码

This commit is contained in:
MrZ626
2021-04-22 14:20:18 +08:00
parent 0007b2ab07
commit 2400325b22
12 changed files with 289 additions and 281 deletions

View File

@@ -14,7 +14,6 @@ ADRAW=require"Zframework.aDraw"
mDraw=ADRAW.draw
JSON=require"Zframework.json"
TABLE=require"Zframework.tableExtend"
STRING=require"Zframework.stringExtend"
@@ -103,7 +102,7 @@ function love.mousepressed(x,y,k,touch)
mouseShow=true
mx,my=xOy:inverseTransformPoint(x,y)
if devMode==1 then
DBP(("(%d,%d)<-%d,%d ~~(%d,%d)<-%d,%d"):format(
print(("(%d,%d)<-%d,%d ~~(%d,%d)<-%d,%d"):format(
mx,my,
mx-lastX,my-lastY,
int(mx/10)*10,int(my/10)*10,
@@ -208,8 +207,8 @@ local function noDevkeyPressed(key)
end
end
elseif key=="f4"then if not kb.isDown("lalt","ralt")then LOG.copy()end
elseif key=="f5"then if WIDGET.sel then DBP(WIDGET.sel)end
elseif key=="f6"then for k,v in next,_G do DBP(k,v)end
elseif key=="f5"then if WIDGET.sel then print(WIDGET.sel)end
elseif key=="f6"then for k,v in next,_G do print(k,v)end
elseif key=="f7"then if love._openConsole then love._openConsole()end
elseif key=="f8"then devMode=nil LOG.print("DEBUG OFF",COLOR.Y)
elseif key=="f9"then devMode=1 LOG.print("DEBUG 1",COLOR.Y)
@@ -372,7 +371,7 @@ function love.errorhandler(msg)
c=3
end
end
DBP(table.concat(err,"\n",1,c-2))
print(table.concat(err,"\n",1,c-2))
--Reset something
love.audio.stop()

View File

@@ -13,7 +13,7 @@
goto REM love=require"love"::REM::--Just tell IDE to load love-api, no actual usage
local fs=love.filesystem
NONE={}function NULL()end
DBP=print--Use this in permanent code
DBP=print--Use this in temporary code, easy to find and remove
TIME=love.timer.getTime
YIELD=coroutine.yield
SYSTEM=love.system.getOS()
@@ -53,24 +53,27 @@ end
--Load modules
require"Zframework"
SCR.setSize(1280,720)--Initialize Screen size
require"parts.list"
require"parts.globalTables"
require"parts.gametoolfunc"
SCR.setSize(1280,720)--Initialize Screen size
FIELD[1]=newBoard()--Initialize field[1]
NET= require"parts.net"
AIBUILDER= require"parts.AITemplate"
FREEROW= require"parts.freeRow"
USERS= require"parts.users"
DATA= require"parts.data"
USERS= require"parts.users"
TEXTURE= require"parts.texture"
SKIN= require"parts.skin"
NET= require"parts.net"
PLY= require"parts.player"
AIFUNC= require"parts.ai"
AIBUILDER= require"parts.AITemplate"
MODES= require"parts.modes"
--Initialize field[1]
FIELD[1]=DATA.newBoard()
--First start for phones
if not fs.getInfo("conf/settings")and MOBILE then
SETTING.VKSwitch=true

255
parts/data.lua Normal file
View File

@@ -0,0 +1,255 @@
local data=love.data
local int=math.floor
local char,byte=string.char,string.byte
local ins=table.insert
local DATA={}
--Sep symbol: 33 (!)
--Safe char: 34~126
--[[
Count: 34~96
Block: 97~125
Encode: A[B] sequence, A = block ID, B = repeat times, no B means do not repeat.
Example: "abcdefg" is [SZJLTOI], "a^aDb)" is [Z*63,Z*37,S*10]
]]
function DATA.copySequence()
local BAG=BAG
local str=""
local count=1
for i=1,#BAG+1 do
if BAG[i+1]~=BAG[i]or count==64 then
str=str..char(96+BAG[i])
if count>1 then
str=str..char(32+count)
count=1
end
else
count=count+1
end
end
return str
end
function DATA.pasteSequence(str)
local b
local bag={}
local reg
for i=1,#str do
b=byte(str,i)
if not reg then
if b>=97 and b<=125 then
reg=b-96
else
return
end
else
if b>=97 and b<=125 then
ins(bag,reg)
reg=b-96
elseif b>=34 and b<=96 then
for _=1,b-32 do
ins(bag,reg)
end
reg=false
end
end
end
if reg then
ins(bag,reg)
end
BAG=bag
return true
end
function DATA.newBoard(f)--Generate a new board
if f then
return TABLE.shift(f)
else
local F={}
for i=1,20 do F[i]={0,0,0,0,0,0,0,0,0,0}end
return F
end
end
function DATA.copyBoard(page)--Copy the [page] board
local F=FIELD[page or 1]
local str=""
local H=0
for y=20,1,-1 do
for x=1,10 do
if F[y][x]~=0 then
H=y
goto BREAK_topFound
end
end
end
::BREAK_topFound::
--Encode field
for y=1,H do
local S=""
local L=F[y]
for x=1,10 do
S=S..char(L[x]+1)
end
str=str..S
end
return data.encode("string","base64",data.compress("string","zlib",str))
end
function DATA.copyBoards()
local out={}
for i=1,#FIELD do
out[i]=DATA.copyBoard(i)
end
return table.concat(out,"!")
end
function DATA.pasteBoard(str,page)--Paste [str] data to [page] board
if not page then page=1 end
if not FIELD[page]then FIELD[page]=DATA.newBoard()end
local F=FIELD[page]
local _,__
--Decode
_,str=pcall(data.decode,"string","base64",str)
if not _ then return end
_,str=pcall(data.decompress,"string","zlib",str)
if not _ then return end
local fX,fY=1,1--*ptr for Field(r*10+(c-1))
local p=1
while true do
_=byte(str,p)--1byte
--Str end
if not _ then
if fX~=1 then
return
else
break
end
end
__=_%32-1--Block id
if __>26 then return end--Illegal blockid
_=int(_/32)--Mode id
F[fY][fX]=__
if fX<10 then
fX=fX+1
else
fY=fY+1
if fY>20 then break end
fX=1
end
p=p+1
end
for y=fY,20 do
for x=1,10 do
F[y][x]=0
end
end
return true
end
--[[
Mission: 34~114
Count: 115~126
Encode: [A] or [AB] sequence, A = mission ID, B = repeat times, no B means do not repeat.
_1=01,_2=02,_3=03,_4=04,
A1=05,A2=06,A3=07,A4=08,
PC=09,
Z1=11,Z2=12,Z3=13,
S1=21,S2=22,S3=23,
J1=31,J2=32,J3=33,
L1=41,L2=42,L3=43,
T1=51,T2=52,T3=53,
O1=61,O2=62,O3=63,O4=64,
I1=71,I2=72,I3=73,I4=74,
]]
function DATA.copyMission()
local _
local MISSION=MISSION
local str=""
local count=1
for i=1,#MISSION+1 do
if MISSION[i+1]~=MISSION[i]or count==13 then
_=33+MISSION[i]
str=str..char(_)
if count>1 then
str=str..char(113+count)
count=1
end
else
count=count+1
end
end
return str
end
function DATA.pasteMission(str)
local b
local mission={}
local reg
for i=1,#str do
b=byte(str,i)
if not reg then
if b>=34 and b<=114 then
reg=b-33
else
return
end
else
if b>=34 and b<=114 then
if missionEnum[reg]then
ins(mission,reg)
reg=b-33
else
return
end
elseif b>=115 and b<=126 then
for _=1,b-113 do
ins(mission,reg)
end
reg=false
end
end
end
if reg then
ins(mission,reg)
end
MISSION=mission
return true
end
function DATA.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
do--function pasteQuestArgs(str)
local sub=string.sub
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)
return true
end
end
return DATA

View File

@@ -19,256 +19,6 @@ end
--Encoding Functions
--Sep symbol: 33 (!)
--Safe char: 34~126
--[[
Count: 34~96
Block: 97~125
Encode: A[B] sequence, A = block ID, B = repeat times, no B means do not repeat.
Example: "abcdefg" is [SZJLTOI], "a^aDb)" is [Z*63,Z*37,S*10]
]]
function copySequence()
local BAG=BAG
local str=""
local count=1
for i=1,#BAG+1 do
if BAG[i+1]~=BAG[i]or count==64 then
str=str..char(96+BAG[i])
if count>1 then
str=str..char(32+count)
count=1
end
else
count=count+1
end
end
return str
end
function pasteSequence(str)
local b
local bag={}
local reg
for i=1,#str do
b=byte(str,i)
if not reg then
if b>=97 and b<=125 then
reg=b-96
else
return
end
else
if b>=97 and b<=125 then
ins(bag,reg)
reg=b-96
elseif b>=34 and b<=96 then
for _=1,b-32 do
ins(bag,reg)
end
reg=false
end
end
end
if reg then
ins(bag,reg)
end
BAG=bag
return true
end
function newBoard(f)--Generate a new board
if f then
return TABLE.shift(f)
else
local F={}
for i=1,20 do F[i]={0,0,0,0,0,0,0,0,0,0}end
return F
end
end
function copyBoard(page)--Copy the [page] board
local F=FIELD[page or 1]
local str=""
local H=0
for y=20,1,-1 do
for x=1,10 do
if F[y][x]~=0 then
H=y
goto BREAK_topFound
end
end
end
::BREAK_topFound::
--Encode field
for y=1,H do
local S=""
local L=F[y]
for x=1,10 do
S=S..char(L[x]+1)
end
str=str..S
end
return data.encode("string","base64",data.compress("string","zlib",str))
end
function copyBoards()
local out={}
for i=1,#FIELD do
out[i]=copyBoard(i)
end
return table.concat(out,"!")
end
function pasteBoard(str,page)--Paste [str] data to [page] board
if not page then page=1 end
if not FIELD[page]then FIELD[page]=newBoard()end
local F=FIELD[page]
local _,__
--Decode
_,str=pcall(data.decode,"string","base64",str)
if not _ then return end
_,str=pcall(data.decompress,"string","zlib",str)
if not _ then return end
local fX,fY=1,1--*ptr for Field(r*10+(c-1))
local p=1
while true do
_=byte(str,p)--1byte
--Str end
if not _ then
if fX~=1 then
return
else
break
end
end
__=_%32-1--Block id
if __>26 then return end--Illegal blockid
_=int(_/32)--Mode id
F[fY][fX]=__
if fX<10 then
fX=fX+1
else
fY=fY+1
if fY>20 then break end
fX=1
end
p=p+1
end
for y=fY,20 do
for x=1,10 do
F[y][x]=0
end
end
return true
end
--[[
Mission: 34~114
Count: 115~126
Encode: [A] or [AB] sequence, A = mission ID, B = repeat times, no B means do not repeat.
_1=01,_2=02,_3=03,_4=04,
A1=05,A2=06,A3=07,A4=08,
PC=09,
Z1=11,Z2=12,Z3=13,
S1=21,S2=22,S3=23,
J1=31,J2=32,J3=33,
L1=41,L2=42,L3=43,
T1=51,T2=52,T3=53,
O1=61,O2=62,O3=63,O4=64,
I1=71,I2=72,I3=73,I4=74,
]]
function copyMission()
local _
local MISSION=MISSION
local str=""
local count=1
for i=1,#MISSION+1 do
if MISSION[i+1]~=MISSION[i]or count==13 then
_=33+MISSION[i]
str=str..char(_)
if count>1 then
str=str..char(113+count)
count=1
end
else
count=count+1
end
end
return str
end
function pasteMission(str)
local b
local mission={}
local reg
for i=1,#str do
b=byte(str,i)
if not reg then
if b>=34 and b<=114 then
reg=b-33
else
return
end
else
if b>=34 and b<=114 then
if missionEnum[reg]then
ins(mission,reg)
reg=b-33
else
return
end
elseif b>=115 and b<=126 then
for _=1,b-113 do
ins(mission,reg)
end
reg=false
end
end
end
if reg then
ins(mission,reg)
end
MISSION=mission
return true
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
do--function pasteQuestArgs(str)
local sub=string.sub
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)
return true
end
end
--Royale mode
function randomTarget(P)--Return a random opponent for P
if #PLY_ALIVE>1 then

View File

@@ -213,15 +213,15 @@ local function loadGameEnv(P)--Load gameEnv
for k,v in next,gameEnv0 do
if GAME.modeEnv[k]~=nil then
v=GAME.modeEnv[k] --Mode setting
-- DBP("mode-"..k..":"..tostring(v))
-- print("mode-"..k..":"..tostring(v))
elseif GAME.setting[k]~=nil then
v=GAME.setting[k] --Game setting
-- DBP("game-"..k..":"..tostring(v))
-- print("game-"..k..":"..tostring(v))
elseif SETTING[k]~=nil then
v=SETTING[k] --Global setting
-- DBP("global-"..k..":"..tostring(v))
-- print("global-"..k..":"..tostring(v))
-- else
-- DBP("default-"..k..":"..tostring(v))
-- print("default-"..k..":"..tostring(v))
end
if type(v)~="table"then--Default setting
ENV[k]=v

View File

@@ -14,6 +14,7 @@ local blind,disappear
local startTime,time
local state,progress
local tapFX,mistake
function scene.sceneInit()
BG.set("space")
BGM.play("way")

View File

@@ -64,11 +64,11 @@ function scene.keyDown(key)
elseif key=="a"then
SCN.go("custom_advance","swipeD")
elseif key=="c"and kb.isDown("lctrl","rctrl")or key=="cC"then
local str="Techmino Quest:"..copyQuestArgs().."!"
if #BAG>0 then str=str..copySequence()end
local str="Techmino Quest:"..DATA.copyQuestArgs().."!"
if #BAG>0 then str=str..DATA.copySequence()end
str=str.."!"
if #MISSION>0 then str=str..copyMission()end
sys.setClipboardText(str.."!"..copyBoards().."!")
if #MISSION>0 then str=str..DATA.copyMission()end
sys.setClipboardText(str.."!"..DATA.copyBoards().."!")
LOG.print(text.exportSuccess,COLOR.G)
elseif key=="v"and kb.isDown("lctrl","rctrl")or key=="cV"then
local str=sys.getClipboardText()
@@ -76,13 +76,13 @@ function scene.keyDown(key)
if #args<4 then goto THROW_fail end
if not(
pasteQuestArgs(args[1])and
pasteSequence(args[2])and
pasteMission(args[3])
DATA.pasteSequence(args[2])and
DATA.pasteMission(args[3])
)then goto THROW_fail end
repeat table.remove(FIELD)until #FIELD==0
FIELD[1]=newBoard()
FIELD[1]=DATA.newBoard()
for i=4,#args do
if not pasteBoard(args[i],i-3)and i<#args then goto THROW_fail end
if not DATA.pasteBoard(args[i],i-3)and i<#args then goto THROW_fail end
end
freshMiniFieldVisible()
LOG.print(text.importSuccess,COLOR.G)

View File

@@ -212,7 +212,7 @@ function scene.keyDown(key)
SFX.play("fall",.8)
end
elseif key=="n"then
ins(FIELD,page+1,newBoard(FIELD[page]))
ins(FIELD,page+1,DATA.newBoard(FIELD[page]))
page=page+1
SFX.play("blip_1",.8)
SYSFX.newShade(3,200,60,300,600,.5,1,.5)
@@ -220,19 +220,19 @@ function scene.keyDown(key)
rem(FIELD,page)
page=max(page-1,1)
if not FIELD[1]then
ins(FIELD,newBoard())
ins(FIELD,DATA.newBoard())
end
SYSFX.newShade(3,200,60,300,600,1,.5,.5)
SFX.play("clear_4",.8)
SFX.play("fall",.8)
elseif key=="c"and kb.isDown("lctrl","rctrl")or key=="cC"then
sys.setClipboardText("Techmino Field:"..copyBoard(page))
sys.setClipboardText("Techmino Field:"..DATA.copyBoard(page))
LOG.print(text.exportSuccess,COLOR.G)
elseif key=="v"and kb.isDown("lctrl","rctrl")or key=="cV"then
local str=sys.getClipboardText()
local p=string.find(str,":")--ptr*
if p then str=sub(str,p+1)end
if pasteBoard(str,page)then
if DATA.pasteBoard(str,page)then
LOG.print(text.importSuccess,COLOR.G)
else
LOG.print(text.dataCorrupted,COLOR.R)

View File

@@ -72,14 +72,14 @@ function scene.keyDown(key)
end
elseif key=="c"and kb.isDown("lctrl","rctrl")or key=="cC"then
if #MISSION>0 then
sys.setClipboardText("Techmino Target:"..copyMission())
sys.setClipboardText("Techmino Target:"..DATA.copyMission())
LOG.print(text.exportSuccess,COLOR.G)
end
elseif key=="v"and kb.isDown("lctrl","rctrl")or key=="cV"then
local str=sys.getClipboardText()
local p=string.find(str,":")--ptr*
if p then str=sub(str,p+1)end
if pasteMission(str)then
if DATA.pasteMission(str)then
LOG.print(text.importSuccess,COLOR.G)
cur=#MISSION
else

View File

@@ -87,14 +87,14 @@ function scene.keyDown(key)
end
elseif key=="c"and kb.isDown("lctrl","rctrl")or key=="cC"then
if #BAG>0 then
sys.setClipboardText("Techmino SEQ:"..copySequence())
sys.setClipboardText("Techmino SEQ:"..DATA.copySequence())
LOG.print(text.exportSuccess,COLOR.G)
end
elseif key=="v"and kb.isDown("lctrl","rctrl")or key=="cV"then
local str=sys.getClipboardText()
local p=string.find(str,":")--ptr*
if p then str=sub(str,p+1)end
if pasteSequence(str)then
if DATA.pasteSequence(str)then
LOG.print(text.importSuccess,COLOR.G)
cur=#BAG
else