From 528e67045dce0a2c95953b520add1fd484d21604 Mon Sep 17 00:00:00 2001 From: Kistaro Windrider Date: Fri, 23 Dec 2022 00:34:00 -0800 Subject: [PATCH] Trimming Trim up redundant nil checks, sequential assignments that could be on a shared line, and repeated references to a deeply nested variable. --- chameleonic.p8 | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/chameleonic.p8 b/chameleonic.p8 index aabe1c0..8688ebf 100644 --- a/chameleonic.p8 +++ b/chameleonic.p8 @@ -626,7 +626,7 @@ function player:update() end if kbd:btn(4) then - if kbd:btnp(4) and self.rope!=nil then + if kbd:btnp(4) and self.rope then self.rope:destroy() kbd:release(4) end @@ -659,7 +659,7 @@ function player:update() self.todo={{ update=function() - return self.rope==nil or self.rope:latched() + return not self.rope or self.rope:latched() end }} elseif kbd:btnp(5) then @@ -764,7 +764,7 @@ function player:draw() if self.rope then local rx_adj,ry_adj=self.rope:affected_src_xy(rx,ry) - if rx_adj!=nil then + if rx_adj then local drx,dry=rx_adj-rx,ry_adj-ry rx,ry=rx+drx,ry+dry px,py=px+drx,py+dry @@ -832,10 +832,7 @@ function rope:update() elseif self.state.name=="latched" then if (self.latch==nil) wrongbleep:bleep(5) self:destroy() return - if - self.latch!=nil and - self.latch.rec!=nil - then + if self.latch and self.latch.rec then self:drag_src( self.latch.rec.mx+0.5+self.latch.ax_offset, self.latch.rec.my+0.5+self.latch.ay_offset @@ -897,11 +894,10 @@ end function rope:draw(artificial_px,artificial_py) local points,highlight=self:_tug(true) - if (self.state.name=="done") return - local perc_to_show=1.0 - local from_end=false - if (self.state.name=="cast") perc_to_show=self.state.frame/2 - if (self.state.name=="destroy") perc_to_show=(1.0-self.state.frame/8)^2 + local n,perc_to_show,from_end = self.state.name,1.0,false + if (n=="done") return + if (n=="cast") perc_to_show=self.state.frame/2 + if (n=="destroy") perc_to_show=(1.0-self.state.frame/8)^2 if (self.state.reelin) from_end=true points[#points]={x=artificial_px,y=artificial_py} @@ -1190,7 +1186,7 @@ function rope:be_pushed_by(anchor,ax_old,ay_old) local ax_new,ay_new=anchor.ax,anchor.ay while true do n1=n0.next - if (n1==nil) return + if (not n1) return local nx0,ny0=n0.ax,n0.ay local nx1,ny1=n1.ax,n1.ay @@ -1317,7 +1313,7 @@ function _stepfrom(x0,x1) local done=false if x0==x1 then return function() - if (done) return nil + if (done) return done=true return x0 end end