From 2fbd1833229a8043eb12a0fba073b1d2d30b1d29 Mon Sep 17 00:00:00 2001 From: MrZ626 <1046101471@qq.com> Date: Wed, 20 Oct 2021 01:21:01 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B4=E7=90=86=E4=BB=A3=E7=A0=81=20?= =?UTF-8?q?=E8=A7=84=E8=8C=83=E6=9B=B4=E5=A4=9A=E5=85=A8=E5=B1=80=E5=8F=98?= =?UTF-8?q?=E9=87=8F=E5=90=8D=20=E8=AF=AD=E9=9F=B3=E5=8C=85/=E9=9F=B3?= =?UTF-8?q?=E6=95=88=E5=8C=85=E5=88=97=E8=A1=A8=E5=A3=B0=E6=98=8E=E6=94=BE?= =?UTF-8?q?=E5=88=B0main=E5=BC=80=E5=A4=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Zframework/init.lua | 5 ++-- Zframework/websocket_thread.lua | 2 +- main.lua | 8 +++--- parts/RSlist.lua | 2 +- parts/gameFuncs.lua | 43 ++++++++++++++++----------------- parts/gameTables.lua | 4 +-- parts/modes/netBattle.lua | 4 +-- parts/net.lua | 30 +++++++++++------------ parts/netPlayer.lua | 42 ++++++++++++++++---------------- parts/player/init.lua | 2 +- parts/scenes/net_game.lua | 20 +++++++-------- parts/scenes/savedata.lua | 2 +- parts/scenes/setting_game.lua | 2 +- parts/scenes/setting_video.lua | 2 +- 14 files changed, 84 insertions(+), 84 deletions(-) diff --git a/Zframework/init.lua b/Zframework/init.lua index 168bb3dc..26fbe105 100644 --- a/Zframework/init.lua +++ b/Zframework/init.lua @@ -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) diff --git a/Zframework/websocket_thread.lua b/Zframework/websocket_thread.lua index e5bc154d..db4dc548 100644 --- a/Zframework/websocket_thread.lua +++ b/Zframework/websocket_thread.lua @@ -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 diff --git a/main.lua b/main.lua index c492589c..2b07bc77 100644 --- a/main.lua +++ b/main.lua @@ -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 diff --git a/parts/RSlist.lua b/parts/RSlist.lua index 89c7c24e..86ec16ae 100644 --- a/parts/RSlist.lua +++ b/parts/RSlist.lua @@ -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 diff --git a/parts/gameFuncs.lua b/parts/gameFuncs.lua index cd00be91..82bc8e12 100644 --- a/parts/gameFuncs.lua +++ b/parts/gameFuncs.lua @@ -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 diff --git a/parts/gameTables.lua b/parts/gameTables.lua index 57f60a64..d64025ea 100644 --- a/parts/gameTables.lua +++ b/parts/gameTables.lua @@ -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 diff --git a/parts/modes/netBattle.lua b/parts/modes/netBattle.lua index d39be421..6b8688c3 100644 --- a/parts/modes/netBattle.lua +++ b/parts/modes/netBattle.lua @@ -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) diff --git a/parts/net.lua b/parts/net.lua index 9e5aac88..a0b63439 100644 --- a/parts/net.lua +++ b/parts/net.lua @@ -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 diff --git a/parts/netPlayer.lua b/parts/netPlayer.lua index 1d55ac01..f14774bd 100644 --- a/parts/netPlayer.lua +++ b/parts/netPlayer.lua @@ -65,13 +65,13 @@ local posLists={ local posList local function _placeSort(a,b)return a.place0 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 diff --git a/parts/player/init.lua b/parts/player/init.lua index 4dc24789..94449c1f 100644 --- a/parts/player/init.lua +++ b/parts/player/init.lua @@ -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 diff --git a/parts/scenes/net_game.lua b/parts/scenes/net_game.lua index cc3fa7df..5cf8ec70 100644 --- a/parts/scenes/net_game.lua +++ b/parts/scenes/net_game.lua @@ -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, diff --git a/parts/scenes/savedata.lua b/parts/scenes/savedata.lua index 5b3eb858..8de48925 100644 --- a/parts/scenes/savedata.lua +++ b/parts/scenes/savedata.lua @@ -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 diff --git a/parts/scenes/setting_game.lua b/parts/scenes/setting_game.lua index 18e9c823..6d4e3bda 100644 --- a/parts/scenes/setting_game.lua +++ b/parts/scenes/setting_game.lua @@ -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')}, diff --git a/parts/scenes/setting_video.lua b/parts/scenes/setting_video.lua index 9794e75b..0f8248b3 100644 --- a/parts/scenes/setting_video.lua +++ b/parts/scenes/setting_video.lua @@ -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')