Shorten latch code

This commit is contained in:
Pyrex 2022-12-30 23:04:27 -08:00
parent 3f7f96a520
commit 95e5b3d0bf

View File

@ -937,6 +937,11 @@ function rope:draw(artificial_px,artificial_py)
local len_cumulative=0
local ia,iz,istep=#points-1,1,-1
if (from_end) ia,iz,istep=1,#points-1,1
local function colorh(ix)
color(8)
if (highlight==ix) color(12)
end
for i=ia,iz,istep do
local src=points[i]
local dst=points[i+1]
@ -958,31 +963,28 @@ function rope:draw(artificial_px,artificial_py)
dx,dy=dx*coef,dy*coef
end
local color=8
if (highlight==i) color=12
colorh(i)
linefill(x,y,x+0.25*dx,y+0.25*dy,1.0,color)
linefill(x+0.25*dx,y+0.25*dy,x+1*dx,y+1*dy,0.5,color)
linefill(x+0.9*dx,y+0.9*dy,x+dx,y+dy,1.0,color)
circfill(x+dx+0.5,y+dy+0.5,1.0,color)
linefill(x,y,x+0.25*dx,y+0.25*dy,1.0)
linefill(x+0.25*dx,y+0.25*dy,x+1*dx,y+1*dy,0.5)
linefill(x+0.9*dx,y+0.9*dy,x+dx,y+dy,1.0)
circfill(x+dx+0.5,y+dy+0.5,1.0)
end
end
-- draw latch
if self.latch!=nil and self.latch.rec and (perc_to_show>=1.0 or from_end) then
local x,y=self.latch.rec.px,self.latch.rec.py
local ldx,ldy=self.latch.dx,self.latch.dy
local color=8
if (highlight==0) color=12
if self.latch.dx==-1 and self.latch.dy==0 then
rectfill(x,y+3,x+2,y+4,color)
elseif self.latch.dx==1 and self.latch.dy==0 then
rectfill(x+5,y+3,x+7,y+4,color)
elseif self.latch.dx==0 and self.latch.dy==-1 then
rectfill(x+3,y,x+4,y+2,color)
elseif self.latch.dx==0 and self.latch.dy==1 then
rectfill(x+3,y+5,x+4,y+7,color)
end
local l=self.latch
if l and l.rec and (perc_to_show>=1.0 or from_end) then
local function rfsplit(x) rectfill(unpack(split(x))) end
local ldx,ldy=l.dx,l.dy
colorh(0)
camera(-l.rec.px,-l.rec.py)
if (ldx==-1) rfsplit"0,3,2,4"
if (ldx==1) rfsplit"5,3,7,4"
if (ldy==-1) rfsplit"3,0,4,2"
if (ldy==1) rfsplit"3,5,4,7"
camera()
color()
end
-- debug