整理代码

规范更多全局变量名
语音包/音效包列表声明放到main开头
This commit is contained in:
MrZ626
2021-10-20 01:21:01 +08:00
parent 14df29ce21
commit 2fbd183322
14 changed files with 84 additions and 84 deletions

View File

@@ -258,7 +258,8 @@ function love.keypressed(key,_,isRep)
devMode=1
MES.new('info',"DEBUG ON",.2)
elseif key=="f11"then
switchFullscreen()
SETTING.fullscreen=not SETTING.fullscreen
applyFullscreen()
saveSettings()
elseif not SCN.swapping then
if SCN.keyDown then
@@ -702,7 +703,7 @@ local Z={}
function Z.setIfPowerInfo(func)showPowerInfo=func end
--Warning: color and line width is uncertain value, set it in the function.
--[Warning] Color and line width is uncertain value, set it in the function.
function Z.setCursor(func)drawCursor=func end
--Change F1~F7 events of devmode (F8 mode)

View File

@@ -151,7 +151,7 @@ local readThread=coroutine.wrap(function()
if op==8 then--8=close
CHN_push(readCHN,8)--close
if type(res)=='string'then
CHN_push(readCHN,res:sub(3))--Warning: 2 bytes close code at start so :sub(3)
CHN_push(readCHN,res:sub(3))--[Warning] 2 bytes close code at start so :sub(3)
else
CHN_push(readCHN,"WS closed")
end

View File

@@ -28,6 +28,8 @@ MOBILE=SYSTEM=='Android'or SYSTEM=='iOS'
SAVEDIR=fs.getSaveDirectory()
--Global Vars & Settings
SFXPACKS={'chiptune'}
VOCPACKS={'miya','mono','xiaoya','miku'}
FIRSTLAUNCH=false
DAILYLAUNCH=false
@@ -93,7 +95,7 @@ VK= require'parts.virtualKey'
BOT= require'parts.bot'
RSlist= require'parts.RSlist'DSCP=RSlist.TRS.centerPos
PLY= require'parts.player'
netPLY= require'parts.netPlayer'
NETPLY= require'parts.netPlayer'
MODES= require'parts.modes'
--Init Zframework
@@ -282,7 +284,7 @@ SKIN.init{
}
--Initialize sound libs
SFX.init((function()
SFX.init((function()--[Warning] Not loading files here, just get the list of sound needed
local L={}
for _,v in next,fs.getDirectoryItems('media/effect/chiptune/')do
if isSafeFile('media/effect/chiptune/'..v,"Dangerous file : %SAVE%/media/effect/chiptune/"..v)then
@@ -503,7 +505,7 @@ if FIRSTLAUNCH and MOBILE then
end
--Apply system setting
applySettings()
applyAllSettings()
--Load replays
for _,fileName in next,fs.getDirectoryItems('replay')do

View File

@@ -180,7 +180,7 @@ do
SFX.play('rotatekick',nil,P:getCenterX()*.15)
end
--[Warning] field spinSeq is a dirty data, TRS put this var into the block.
--[Warning] Field spinSeq is a dirty data, TRS put this var into the block.
C.spinSeq=(C.spinSeq or 0)%100*10+d
if C.spinSeq<100 then
return end

View File

@@ -13,6 +13,13 @@ local PLAYERS=PLAYERS
--System
function isSafeFile(file,mes)
if love.filesystem.getRealDirectory(file)~=SAVEDIR then
return true
elseif mes then
MES.new('warn',mes)
end
end
function saveStats()
return FILE.save(STAT,'conf/data')
end
@@ -31,28 +38,15 @@ function applyLanguage()
end
end
end
function applySettings()
love.window.setFullscreen(SETTING.fullscreen)
love.audio.setVolume(SETTING.mainVol)
love.mouse.setVisible(SETTING.sysCursor)
VK.setShape(SETTING.VKSkin)
BGM.setVol(SETTING.bgm)
SFX.setVol(SETTING.sfx)
VOC.setVol(SETTING.voc)
applyBlockSatur(SETTING.blockSatur)
applyFieldSatur(SETTING.fieldSatur)
applyLanguage()
end
function switchCursor()
SETTING.sysCursor=not SETTING.sysCursor
function applyCursor()
love.mouse.setVisible(SETTING.sysCursor)
end
function switchFullscreen()
function applyFullscreen()
SETTING.fullscreen=not SETTING.fullscreen
love.window.setFullscreen(SETTING.fullscreen)
love.resize(gc.getWidth(),gc.getHeight())
end
do--function applyXxxSatur(mode)
do--function applyBlockSatur,applyFieldSatur(mode)
local saturateValues={
normal={0,1},
soft={.2,.7},
@@ -71,12 +65,17 @@ do--function applyXxxSatur(mode)
SHADER.fieldSatur:send('k',m[2])
end
end
function isSafeFile(file,mes)
if love.filesystem.getRealDirectory(file)~=SAVEDIR then
return true
elseif mes then
MES.new('warn',mes)
end
function applyAllSettings()
love.window.setFullscreen(SETTING.fullscreen)
love.audio.setVolume(SETTING.mainVol)
VK.setShape(SETTING.VKSkin)
BGM.setVol(SETTING.bgm)
SFX.setVol(SETTING.sfx)
VOC.setVol(SETTING.voc)
applyBlockSatur(SETTING.blockSatur)
applyFieldSatur(SETTING.fieldSatur)
applyLanguage()
applyCursor()
end
--Royale mode

View File

@@ -1,6 +1,4 @@
--Static data tables
SFXPACKS={'chiptune'}
VOCPACKS={'miya','mono','xiaoya','miku'}
BLOCK_NAMES={
'Z','S','J','L','T','O','I',
'Z5','S5','P','Q','F','E',
@@ -503,7 +501,7 @@ do--Mod data
M.color=COLOR[M.color]
end
end
do--Game tables
do--Game data tables
PLAYERS={}--Players data
PLY_ALIVE={}
FIELD={}--Field(s) for custom game

View File

@@ -19,13 +19,13 @@ return{
GAME.modeEnv.allowMod=false
GAME.modeEnv.task=marginTask
local L=TABLE.copy(netPLY.list)
local L=TABLE.copy(NETPLY.list)
local N=1
for i,p in next,L do
if p.uid==USER.uid then
if p.connected then
PLY.newPlayer(1)
PLAYERS[1].sid=netPLY.getSID(USER.uid)
PLAYERS[1].sid=NETPLY.getSID(USER.uid)
N=2
end
table.remove(L,i)

View File

@@ -280,7 +280,7 @@ function NET.loadSavedData(sections)
TABLE.cover(NET.cloudData.SETTING,SETTING)
success=success and saveSettings()
applySettings()
applyAllSettings()
TABLE.cover(NET.cloudData.keyMap,KEY_MAP)
success=success and FILE.save(KEY_MAP,'conf/key')
@@ -524,10 +524,10 @@ function NET.updateWS_play()
elseif res.action==2 then--Player join
if res.type=='Self'then
--Enter new room
netPLY.clear()
NETPLY.clear()
if d.players then
for _,p in next,d.players do
netPLY.add{
NETPLY.add{
uid=p.uid,
username=p.username,
sid=p.sid,
@@ -555,7 +555,7 @@ function NET.updateWS_play()
loadGame('netBattle',true,true)
else
--Load other players
netPLY.add{
NETPLY.add{
uid=d.uid,
username=d.username,
sid=d.sid,
@@ -578,7 +578,7 @@ function NET.updateWS_play()
end
SCN.back()
else
netPLY.remove(d.sid)
NETPLY.remove(d.sid)
_removePlayer(PLAYERS,d.sid)
_removePlayer(PLY_ALIVE,d.sid)
if SCN.cur=='net_game'then
@@ -590,9 +590,9 @@ function NET.updateWS_play()
SCN.socketRead('talk',d)
end
elseif res.action==5 then--Player change settings
netPLY.setConf(d.uid,d.config)
NETPLY.setConf(d.uid,d.config)
elseif res.action==6 then--Player change join mode
netPLY.setJoinMode(d.uid,d.mode)
NETPLY.setJoinMode(d.uid,d.mode)
elseif res.action==7 then--All Ready
SFX.play('reach',.6)
NET.roomReadyState='allReady'
@@ -608,15 +608,15 @@ function NET.updateWS_play()
for _,p in next,d.result do
for _,P in next,PLAYERS do
if P.uid==p.uid then
netPLY.setStat(p.uid,P.stat)
netPLY.setPlace(p.uid,p.place)
NETPLY.setStat(p.uid,P.stat)
NETPLY.setPlace(p.uid,p.place)
break
end
end
end
netPLY.resetState()
netPLY.freshPos()
NETPLY.resetState()
NETPLY.freshPos()
NET.roomState.start=false
if NET.spectate then
NET.signal_setMode(2)
@@ -657,10 +657,10 @@ function NET.updateWS_stream()
if res.type=='Self'then
NET.seed=d.seed
NET.spectate=d.spectate
netPLY.setConnect(d.uid)
NETPLY.setConnect(d.uid)
for _,p in next,d.connected do
if not p.spectate then
netPLY.setConnect(p.uid)
NETPLY.setConnect(p.uid)
end
end
if d.spectate then
@@ -677,9 +677,9 @@ function NET.updateWS_stream()
end
else
if d.spectate then
netPLY.setJoinMode(d.uid,2)
NETPLY.setJoinMode(d.uid,2)
else
netPLY.setConnect(d.uid)
NETPLY.setConnect(d.uid)
end
end
elseif res.action==3 then--Player leave

View File

@@ -65,13 +65,13 @@ local posLists={
local posList
local function _placeSort(a,b)return a.place<b.place end
local netPLY
local NETPLY
local nullIndex={
__index=function(self,k)
MES.traceback()
MES.new('error',"User not loaded: "..k)
netPLY.add{
NETPLY.add{
uid=k,
username="Stacker",
sid=-1,
@@ -96,17 +96,17 @@ local function _freshPos()
posList=posLists[5]
end
end
netPLY={
NETPLY={
list=PLYlist,
map=PLYmap,
freshPos=_freshPos,
}
function netPLY.clear()
function NETPLY.clear()
TABLE.cut(PLYlist)
TABLE.clear(PLYmap)
end
function netPLY.add(d)
function NETPLY.add(d)
local p={
uid=d.uid,
username=d.username,
@@ -124,7 +124,7 @@ function netPLY.add(d)
PLYmap[p.uid]=p
_freshPos()
end
function netPLY.remove(sid)
function NETPLY.remove(sid)
for i=1,#PLYlist do
if PLYlist[i].sid==sid then
PLYmap[PLYlist[i].uid]=nil
@@ -135,14 +135,14 @@ function netPLY.remove(sid)
end
end
function netPLY.getCount()return #PLYlist end
function netPLY.getSID(uid)return PLYmap[uid].sid end
function netPLY.getSelfJoinMode()return PLYmap[USER.uid].mode end
function netPLY.getSelfReady()return PLYmap[USER.uid].mode>0 end
function NETPLY.getCount()return #PLYlist end
function NETPLY.getSID(uid)return PLYmap[uid].sid end
function NETPLY.getSelfJoinMode()return PLYmap[USER.uid].mode end
function NETPLY.getSelfReady()return PLYmap[USER.uid].mode>0 end
function netPLY.setPlayerObj(ply,p)ply.p=p end
function netPLY.setConf(uid,config)PLYmap[uid].config=config end
function netPLY.setJoinMode(uid,ready)
function NETPLY.setPlayerObj(ply,p)ply.p=p end
function NETPLY.setConf(uid,config)PLYmap[uid].config=config end
function NETPLY.setJoinMode(uid,ready)
for _,p in next,PLYlist do
if p.uid==uid then
if p.mode~=ready then
@@ -164,16 +164,16 @@ function netPLY.setJoinMode(uid,ready)
end
end
end
function netPLY.setConnect(uid)PLYmap[uid].connected=true end
function netPLY.setPlace(uid,place)PLYmap[uid].place=place end
function netPLY.setStat(uid,S)
function NETPLY.setConnect(uid)PLYmap[uid].connected=true end
function NETPLY.setPlace(uid,place)PLYmap[uid].place=place end
function NETPLY.setStat(uid,S)
PLYmap[uid].stat={
lpm=("%.1f %s"):format(S.row/S.time*60,text.radarData[5]),
apm=("%.1f %s"):format(S.atk/S.time*60,text.radarData[3]),
adpm=("%.1f %s"):format((S.atk+S.dig)/S.time*60,text.radarData[2]),
}
end
function netPLY.resetState()
function NETPLY.resetState()
for i=1,#PLYlist do
PLYlist[i].mode=0
PLYlist[i].connected=false
@@ -181,7 +181,7 @@ function netPLY.resetState()
end
local selP,mouseX,mouseY
function netPLY.mouseMove(x,y)
function NETPLY.mouseMove(x,y)
selP=nil
for i=1,#PLYlist do
local p=PLYlist[i]
@@ -193,7 +193,7 @@ function netPLY.mouseMove(x,y)
end
end
function netPLY.update()
function NETPLY.update()
for i=1,#PLYlist do
local p=PLYlist[i]
local t=posList[i]
@@ -208,7 +208,7 @@ local stencilW,stencilH
local function _playerFrameStencil()
gc_rectangle('fill',0,0,stencilW,stencilH)
end
function netPLY.draw()
function NETPLY.draw()
for i=1,#PLYlist do
local p=PLYlist[i]
gc_translate(p.x,p.y)
@@ -290,4 +290,4 @@ function netPLY.draw()
end
end
return netPLY
return NETPLY

View File

@@ -461,7 +461,7 @@ function PLY.newRemotePlayer(id,mini,ply)
P.draw=ply_draw.norm
P:startStreaming()
netPLY.setPlayerObj(ply,P)
NETPLY.setPlayerObj(ply,P)
P.uid=ply.uid
P.username=ply.username
P.sid=ply.sid

View File

@@ -7,7 +7,7 @@ local setFont,mStr=FONT.set,GC.mStr
local ins=table.insert
local SCR,VK,NET,netPLY=SCR,VK,NET,netPLY
local SCR,VK,NET,NETPLY=SCR,VK,NET,NETPLY
local PLAYERS,GAME=PLAYERS,GAME
local textBox=WIDGET.newTextBox{name="texts",x=340,y=80,w=600,h=560}
@@ -89,9 +89,9 @@ function scene.sceneBack()
end
scene.mouseDown=NULL
function scene.mouseMove(x,y)netPLY.mouseMove(x,y)end
function scene.mouseMove(x,y)NETPLY.mouseMove(x,y)end
function scene.touchDown(x,y)
if not playing then netPLY.mouseMove(x,y)return end
if not playing then NETPLY.mouseMove(x,y)return end
if noTouch then return end
local t=VK.on(x,y)
@@ -158,7 +158,7 @@ function scene.keyDown(key,isRep)
end
elseif not _hideReadyUI()then
if key=="space"then
if netPLY.getSelfJoinMode()==0 then
if NETPLY.getSelfJoinMode()==0 then
(kb.isDown("lctrl","rctrl","lalt","ralt")and _setSpectate or _setReady)()
else
_setCancel()
@@ -224,7 +224,7 @@ function scene.socketRead(cmd,d)
lastUpstreamTime=0
upstreamProgress=1
resetGameData('n',NET.seed)
netPLY.mouseMove(0,0)
NETPLY.mouseMove(0,0)
else
MES.new('warn',"Redundant [Go]")
end
@@ -269,7 +269,7 @@ function scene.update(dt)
lastUpstreamTime=PLAYERS[1].alive and P1.frameRun or 1e99
end
else
netPLY.update()
NETPLY.update()
end
if newMessageTimer>0 then
newMessageTimer=newMessageTimer-1
@@ -296,7 +296,7 @@ function scene.draw()
end
else
--Users
netPLY.draw()
NETPLY.draw()
--Ready & Set mark
setFont(50)
@@ -316,7 +316,7 @@ function scene.draw()
setFont(25)
gc_printf(NET.roomState.roomInfo.name,0,685,1270,'right')
setFont(40)
gc_print(netPLY.getCount().."/"..NET.roomState.capacity,70,655)
gc_print(NETPLY.getCount().."/"..NET.roomState.capacity,70,655)
if NET.roomState.private then
gc_draw(IMG.lock,30,668)
end
@@ -338,8 +338,8 @@ function scene.draw()
gc_print("M",430,10)
end
end
local function _hideF_ingame()return _hideReadyUI()or netPLY.getSelfReady()end
local function _hideF_ingame2()return _hideReadyUI()or not netPLY.getSelfReady()end
local function _hideF_ingame()return _hideReadyUI()or NETPLY.getSelfReady()end
local function _hideF_ingame2()return _hideReadyUI()or not NETPLY.getSelfReady()end
scene.widgetList={
textBox,
inputBox,

View File

@@ -59,7 +59,7 @@ scene.widgetList={
local D=_parseCB()
if D then
TABLE.update(D,SETTING)
applySettings()
applyAllSettings()
saveSettings()
MES.new('check',text.importSuccess)
else

View File

@@ -45,7 +45,7 @@ scene.widgetList={
WIDGET.newSlider{name="reTime", x=330, y=320, w=300,lim=180,unit=10,disp=SETval('reTime'), code=SETsto('reTime'),show=function(S)return(.5+S.disp()*.25).."s"end},
WIDGET.newSelector{name="RS", x=300, y=420, w=300,color='S', disp=SETval('RS'), code=SETsto('RS'),list={'TRS','SRS','SRS_plus','SRS_X','BiRS','ARS_Z','ASC','ASC_plus','C2','C2_sym','Classic','Classic_plus','None','None_plus'}},
WIDGET.newSelector{name="menuPos", x=980, y=320, w=300,color='O', disp=SETval('menuPos'), code=SETsto('menuPos'),list={'left','middle','right'}},
WIDGET.newSwitch{name="sysCursor" ,x=1060, y=390, lim=580, disp=SETval('sysCursor'),code=switchCursor},
WIDGET.newSwitch{name="sysCursor" ,x=1060, y=390, lim=580, disp=SETval('sysCursor'),code=function()SETTING.sysCursor=not SETTING.sysCursor applyCursor()end},
WIDGET.newSwitch{name="autoPause", x=1060, y=450, lim=580, disp=SETval('autoPause'),code=SETrev('autoPause')},
WIDGET.newSwitch{name="autoSave", x=1060, y=500, lim=580, disp=SETval('autoSave'), code=SETrev('autoSave')},
WIDGET.newSwitch{name="autoLogin", x=960, y=580, lim=480, disp=SETval('autoLogin'),code=SETrev('autoLogin')},

View File

@@ -71,7 +71,7 @@ scene.widgetList={
WIDGET.newSwitch{name="clickFX", x=950,y=980,lim=360,disp=SETval('clickFX'), code=SETrev('clickFX')},
WIDGET.newSwitch{name="power", x=950,y=1070,lim=360,disp=SETval('powerInfo'), code=SETrev('powerInfo')},
WIDGET.newSwitch{name="clean", x=950,y=1160,lim=360,disp=SETval('cleanCanvas'), code=SETrev('cleanCanvas')},
WIDGET.newSwitch{name="fullscreen", x=950,y=1250,lim=360,disp=SETval('fullscreen'), code=switchFullscreen},
WIDGET.newSwitch{name="fullscreen", x=950,y=1250,lim=360,disp=SETval('fullscreen'), code=function()SETTING.fullscreen=not SETTING.fullscreen applyFullscreen()end},
WIDGET.newSwitch{name="bg", x=950,y=1340,lim=360,disp=SETval('bg'),
code=function()
BG.set('none')