From fefa5433fdaff85db2c76a1701544b288738b83e Mon Sep 17 00:00:00 2001 From: MrZ626 <1046101471@qq.com> Date: Mon, 10 May 2021 17:28:26 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B4=E7=90=86=E4=BB=A3=E7=A0=81=EF=BC=8C?= =?UTF-8?q?=E4=BD=BF=E7=94=A8TABLE.find?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Zframework/init.lua | 10 ++++------ Zframework/widget.lua | 18 ++++++++---------- parts/net.lua | 1 + parts/player/player.lua | 16 ++++------------ parts/scenes/app_console.lua | 15 ++++++--------- parts/scenes/custom_mission.lua | 4 +--- parts/scenes/custom_sequence.lua | 4 +--- parts/scenes/mod.lua | 8 ++------ parts/scenes/music.lua | 16 +++------------- parts/updateLog.lua | 4 +++- 10 files changed, 33 insertions(+), 63 deletions(-) diff --git a/Zframework/init.lua b/Zframework/init.lua index a50514ae..3ddce790 100644 --- a/Zframework/init.lua +++ b/Zframework/init.lua @@ -273,12 +273,10 @@ function love.joystickadded(JS) joysticks[#joysticks+1]=JS end function love.joystickremoved(JS) - for i=1,#joysticks do - if joysticks[i]==JS then - rem(joysticks,i) - LOG.print("Joystick removed",COLOR.Y) - return - end + local i=TABLE.find(joysticks,JS) + if i then + rem(joysticks,i) + LOG.print("Joystick removed",COLOR.Y) end end local keyMirror={ diff --git a/Zframework/widget.lua b/Zframework/widget.lua index 842e267a..de97605a 100644 --- a/Zframework/widget.lua +++ b/Zframework/widget.lua @@ -589,17 +589,15 @@ local selector={ } function selector:reset() self.ATV=0 - local V=self.disp() - local L=self.list - for i=1,#L do - if L[i]==V then - self.select=i - self.selText=self.list[i] - return - end + local V,L=self.disp(),self.list + local i=TABLE.find(L,V) + if i then + self.select=i + self.selText=self.list[i] + else + self.hide=true + LOG.print("Selector "..self.name.." dead, disp= "..tostring(V),'warn') end - self.hide=true - LOG.print("Selector "..self.name.." dead, disp= "..tostring(V),'warn') end function selector:isAbove(x,y) return diff --git a/parts/net.lua b/parts/net.lua index 1a468f09..25d26687 100644 --- a/parts/net.lua +++ b/parts/net.lua @@ -399,6 +399,7 @@ function NET.updateWS_play() SCN.back() else netPLY.remove(d.sid) + --TODO for i=1,#PLAYERS do if PLAYERS[i].sid==d.sid then rem(PLAYERS,i) diff --git a/parts/player/player.lua b/parts/player/player.lua index c07211ef..8681ae05 100644 --- a/parts/player/player.lua +++ b/parts/player/player.lua @@ -427,12 +427,8 @@ function Player:changeAtk(R) -- if self.type~='human'then R=PLAYERS[1]end--1vALL mode? if self.atking then local K=self.atking.atker - for i=1,#K do - if K[i]==self then - rem(K,i) - break - end - end + local i=TABLE.find(K,self) + if i then rem(K,i)end end if R then self.atking=R @@ -1717,12 +1713,8 @@ function Player:lose(force) return end self:die() - for i=1,#PLY_ALIVE do - if PLY_ALIVE[i]==self then - rem(PLY_ALIVE,i) - break - end - end + local i=TABLE.find(PLY_ALIVE,self) + if i then rem(PLY_ALIVE,i)end self.result='lose' if GAME.modeEnv.royaleMode then self:changeAtk() diff --git a/parts/scenes/app_console.lua b/parts/scenes/app_console.lua index f362ff9a..bc96a835 100644 --- a/parts/scenes/app_console.lua +++ b/parts/scenes/app_console.lua @@ -585,13 +585,12 @@ do--commands.applet(name) log(appList[i]..": "..appDescription[i]) end elseif name~=""then - for i=1,#appList do - if appList[i]==name then - SCN.go(appScene[i]) - return - end + local i=TABLE.find(appList,name) + if i then + SCN.go(appScene[i]) + else + log{C.aqua,"No this applet"} end - log{C.aqua,"No this applet"} else log{C.aqua,"Usage:"} log{C.aqua,"applet -list"} @@ -766,9 +765,7 @@ function scene.keyDown(k) if #res>1 then log(">Commands start with '"..str.."' :") table.sort(res) - for i=1,#res do - log{COLOR.lH,res[i]} - end + for i=1,#res do log{COLOR.lH,res[i]}end elseif #res==1 then inputBox.value=res[1] end diff --git a/parts/scenes/custom_mission.lua b/parts/scenes/custom_mission.lua index c8c21f0a..569251c4 100644 --- a/parts/scenes/custom_mission.lua +++ b/parts/scenes/custom_mission.lua @@ -61,9 +61,7 @@ function scene.keyDown(key) end elseif key=="delete"then if sure>20 then - for _=1,#MISSION do - rem(MISSION) - end + TABLE.cut(MISSION) cur=0 sure=0 SFX.play('finesseError',.7) diff --git a/parts/scenes/custom_sequence.lua b/parts/scenes/custom_sequence.lua index 0259b3b7..0742246d 100644 --- a/parts/scenes/custom_sequence.lua +++ b/parts/scenes/custom_sequence.lua @@ -65,9 +65,7 @@ function scene.keyDown(key) end elseif key=="delete"then if sure>20 then - for _=1,#BAG do - rem(BAG) - end + TABLE.cut(BAG) cur=0 sure=0 SFX.play('finesseError',.7) diff --git a/parts/scenes/mod.lua b/parts/scenes/mod.lua index 2502534e..e91c9d70 100644 --- a/parts/scenes/mod.lua +++ b/parts/scenes/mod.lua @@ -6,12 +6,8 @@ local function modComp(a,b) return a.no