From 0f30a35ae3cd827ed98bcc79851041d356a13b44 Mon Sep 17 00:00:00 2001 From: MrZ626 <1046101471@qq.com> Date: Thu, 13 May 2021 10:18:02 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B4=E7=90=86=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Zframework/init.lua | 6 +++--- Zframework/sysFX.lua | 32 ++++++++++++++++---------------- Zframework/text.lua | 11 ++++++----- main.lua | 4 ++-- parts/player/player.lua | 4 ++-- 5 files changed, 29 insertions(+), 28 deletions(-) diff --git a/Zframework/init.lua b/Zframework/init.lua index ed703a18..c8b007ed 100644 --- a/Zframework/init.lua +++ b/Zframework/init.lua @@ -49,7 +49,7 @@ local gc_push,gc_pop=gc.push,gc.pop local gc_discard,gc_present=gc.discard,gc.present local gc_setColor,gc_draw,gc_rectangle=gc.setColor,gc.draw,gc.rectangle local gc_print=gc.print -local setFont=setFont +local setFont,mStr=setFont,mStr local int,rnd,abs=math.floor,math.random,math.abs local min,sin=math.min,math.sin @@ -277,7 +277,7 @@ function love.textinput(texts) end function love.joystickadded(JS) - joysticks[#joysticks+1]=JS + ins(joysticks,JS) end function love.joystickremoved(JS) local i=TABLE.find(joysticks,JS) @@ -392,7 +392,7 @@ function love.errorhandler(msg) if LOADED and #ERRDATA<3 then BG.set('none') local scn=SCN and SCN.cur or"NULL" - ERRDATA[#ERRDATA+1]={mes=err,scene=scn} + ins(ERRDATA,{mes=err,scene=scn}) --Write messages to log file love.filesystem.append("conf/error.log", diff --git a/Zframework/sysFX.lua b/Zframework/sysFX.lua index 8da7a9a4..be8f5572 100644 --- a/Zframework/sysFX.lua +++ b/Zframework/sysFX.lua @@ -3,7 +3,7 @@ local setColor,setWidth=gc.setColor,gc.setLineWidth local sin,cos=math.sin,math.cos local max,min=math.max,math.min local rnd=math.random -local rem=table.remove +local ins,rem=table.insert,table.remove local fx={} @@ -126,17 +126,17 @@ function SYSFX.draw() end function SYSFX.newBadge(x1,y1,x2,y2) - fx[#fx+1]={ + ins(fx,{ update=FXupdate.badge, draw=FXdraw.badge, t=0, x=x1,y=y1, x1=x1,y1=y1, x2=x2,y2=y2, - } + }) end function SYSFX.newAttack(rate,x1,y1,x2,y2,wid,r,g,b,a) - fx[#fx+1]={ + ins(fx,{ update=FXupdate.attack, draw=FXdraw.attack, t=0, @@ -145,7 +145,7 @@ function SYSFX.newAttack(rate,x1,y1,x2,y2,wid,r,g,b,a) x2=x2,y2=y2,--End pos wid=wid,--Line width r=r,g=g,b=b,a=a, - } + }) end function SYSFX.newTap(rate,x,y) local T= @@ -162,38 +162,38 @@ function SYSFX.newTap(rate,x,y) local ang=rnd()*6.2832 T.ptc[i]={x,y,x+d*cos(ang),y+d*sin(ang)} end - fx[#fx+1]=T + ins(fx,T) end function SYSFX.newRipple(rate,x,y,r) - fx[#fx+1]={ + ins(fx,{ update=FXupdate.ripple, draw=FXdraw.ripple, t=0, rate=rate, x=x,y=y,r=r, - } + }) end function SYSFX.newRectRipple(rate,x,y,w,h) - fx[#fx+1]={ + ins(fx,{ update=FXupdate.rectRipple, draw=FXdraw.rectRipple, t=0, rate=rate, x=x,y=y,w=w,h=h, - } + }) end function SYSFX.newShade(rate,x,y,w,h,r,g,b) - fx[#fx+1]={ + ins(fx,{ update=FXupdate.shade, draw=FXdraw.shade, t=0, rate=rate, x=x,y=y,w=w,h=h, r=r or 1,g=g or 1,b=b or 1, - } + }) end function SYSFX.newCell(rate,image,size,x,y,vx,vy,ax,ay) - fx[#fx+1]={ + ins(fx,{ update=FXupdate.cell, draw=FXdraw.cell, t=0, @@ -203,10 +203,10 @@ function SYSFX.newCell(rate,image,size,x,y,vx,vy,ax,ay) x=x,y=y, vx=vx,vy=vy, ax=ax,ay=ay, - } + }) end function SYSFX.newLine(rate,x1,y1,x2,y2,r,g,b,a) - fx[#fx+1]={ + ins(fx,{ update=FXupdate.line, draw=FXdraw.line, t=0, @@ -214,6 +214,6 @@ function SYSFX.newLine(rate,x1,y1,x2,y2,r,g,b,a) x1=x1 or 0,y1=y1 or 0, x2=x2 or x1 or 1280,y2=y2 or y1 or 720, r=r or 1,g=g or 1,b=b or 1,a=a or 1, - } + }) end return SYSFX \ No newline at end of file diff --git a/Zframework/text.lua b/Zframework/text.lua index 1e7f57df..a5e43728 100644 --- a/Zframework/text.lua +++ b/Zframework/text.lua @@ -1,8 +1,9 @@ local gc=love.graphics -local gc_getColor,gc_setColor,gc_push,gc_pop,gc_translate,gc_scale,gc_rotate,gc_shear -=gc.getColor,gc.setColor,gc.push,gc.pop,gc.translate,gc.scale,gc.rotate,gc.shear +local gc_getColor,gc_setColor,gc_push,gc_pop=gc.getColor,gc.setColor,gc.push,gc.pop +local gc_translate,gc_scale,gc_rotate,gc_shear=gc.translate,gc.scale,gc.rotate,gc.shear -local int,rnd,rem=math.floor,math.random,table.remove +local int,rnd=math.floor,math.random +local ins,rem=table.insert,table.remove local setFont,mStr=setFont,mStr local texts={} @@ -77,7 +78,7 @@ function TEXT.clear() texts={} end function TEXT.show(text,x,y,font,style,spd,stop) - texts[#texts+1]={ + ins(texts,{ c=0, --Timer text=text, --String x=x or 0, --X @@ -86,7 +87,7 @@ function TEXT.show(text,x,y,font,style,spd,stop) spd=(spd or 1)/60, --Timing speed(1=last 1 sec) stop=stop, --Stop time(sustained text) draw=textFX[style or'appear']or error("unavailable type:"..style), --Draw method - } + }) end function TEXT.getText(text,x,y,font,style,spd,stop)--Another version of TEXT.show(), but only return text object, need manual management return{ diff --git a/main.lua b/main.lua index 2388e4d5..5f146d9c 100644 --- a/main.lua +++ b/main.lua @@ -165,7 +165,7 @@ SFX.init((function() local L={} for _,v in next,fs.getDirectoryItems("media/SFX")do if fs.getRealDirectory("media/SFX/"..v)~=SAVEDIR then - L[#L+1]=v:sub(1,-5) + table.insert(L,v:sub(1,-5)) else LOG.print("Dangerous file : %SAVE%/media/SFX/"..v) end @@ -176,7 +176,7 @@ BGM.init((function() local L={} for _,v in next,fs.getDirectoryItems("media/BGM")do if fs.getRealDirectory("media/BGM/"..v)~=SAVEDIR then - L[#L+1]=v:sub(1,-5) + table.insert(L,v:sub(1,-5)) else LOG.print("Dangerous file : %SAVE%/media/BGM/"..v) end diff --git a/parts/player/player.lua b/parts/player/player.lua index decc6968..3c12fc79 100644 --- a/parts/player/player.lua +++ b/parts/player/player.lua @@ -125,11 +125,11 @@ function Player:newTask(code,...) local thread=coroutine.create(code) resume(thread,self,...) if status(thread)~='dead'then - self.tasks[#self.tasks+1]={ + ins(self.tasks,{ thread=thread, code=code, args={...}, - } + }) end end