Trim up redundant nil checks, sequential assignments that could be on a shared line, and repeated references to a deeply nested variable.
This commit is contained in:
Kistaro Windrider 2022-12-23 00:34:00 -08:00
parent 1995501583
commit 528e67045d
Signed by: kistaro
SSH Key Fingerprint: SHA256:TBE2ynfmJqsAf0CP6gsflA0q5X5wD5fVKWPsZ7eVUg8

View File

@ -626,7 +626,7 @@ function player:update()
end end
if kbd:btn(4) then 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() self.rope:destroy()
kbd:release(4) kbd:release(4)
end end
@ -659,7 +659,7 @@ function player:update()
self.todo={{ self.todo={{
update=function() update=function()
return self.rope==nil or self.rope:latched() return not self.rope or self.rope:latched()
end end
}} }}
elseif kbd:btnp(5) then elseif kbd:btnp(5) then
@ -764,7 +764,7 @@ function player:draw()
if self.rope then if self.rope then
local rx_adj,ry_adj=self.rope:affected_src_xy(rx,ry) 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 local drx,dry=rx_adj-rx,ry_adj-ry
rx,ry=rx+drx,ry+dry rx,ry=rx+drx,ry+dry
px,py=px+drx,py+dry px,py=px+drx,py+dry
@ -832,10 +832,7 @@ function rope:update()
elseif self.state.name=="latched" then elseif self.state.name=="latched" then
if (self.latch==nil) wrongbleep:bleep(5) self:destroy() return if (self.latch==nil) wrongbleep:bleep(5) self:destroy() return
if if self.latch and self.latch.rec then
self.latch!=nil and
self.latch.rec!=nil
then
self:drag_src( self:drag_src(
self.latch.rec.mx+0.5+self.latch.ax_offset, self.latch.rec.mx+0.5+self.latch.ax_offset,
self.latch.rec.my+0.5+self.latch.ay_offset self.latch.rec.my+0.5+self.latch.ay_offset
@ -897,11 +894,10 @@ end
function rope:draw(artificial_px,artificial_py) function rope:draw(artificial_px,artificial_py)
local points,highlight=self:_tug(true) local points,highlight=self:_tug(true)
if (self.state.name=="done") return local n,perc_to_show,from_end = self.state.name,1.0,false
local perc_to_show=1.0 if (n=="done") return
local from_end=false if (n=="cast") perc_to_show=self.state.frame/2
if (self.state.name=="cast") perc_to_show=self.state.frame/2 if (n=="destroy") perc_to_show=(1.0-self.state.frame/8)^2
if (self.state.name=="destroy") perc_to_show=(1.0-self.state.frame/8)^2
if (self.state.reelin) from_end=true if (self.state.reelin) from_end=true
points[#points]={x=artificial_px,y=artificial_py} 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 local ax_new,ay_new=anchor.ax,anchor.ay
while true do while true do
n1=n0.next n1=n0.next
if (n1==nil) return if (not n1) return
local nx0,ny0=n0.ax,n0.ay local nx0,ny0=n0.ax,n0.ay
local nx1,ny1=n1.ax,n1.ay local nx1,ny1=n1.ax,n1.ay
@ -1317,7 +1313,7 @@ function _stepfrom(x0,x1)
local done=false local done=false
if x0==x1 then if x0==x1 then
return function() return function()
if (done) return nil if (done) return
done=true return x0 done=true return x0
end end
end end