From d2e1e9274c6f6ab57195fb7f14308f7b4baecc56 Mon Sep 17 00:00:00 2001 From: Nyeogmi Date: Sun, 18 Dec 2022 16:07:15 -0800 Subject: [PATCH] Fix misc other rope bugs --- chameleonic.p8 | 148 ++++++++++++++++++++++++++++--------------------- 1 file changed, 86 insertions(+), 62 deletions(-) diff --git a/chameleonic.p8 b/chameleonic.p8 index 784047f..7952dc6 100644 --- a/chameleonic.p8 +++ b/chameleonic.p8 @@ -800,7 +800,25 @@ function rope:update() self.latch_frame=10 end - if (not is_busy) self:_make_consistent() + if (self.latch==nil) self:destroy() return + + if + self.latch!=nil and + self.latch.rec!=nil + then + self:drag_src( + self.latch.rec.px+self.latch.px_offset, + self.latch.rec.py+self.latch.py_offset + ) + + if #self.latch.rec.todo==0 then + if self.latch.rec.dead==true then + self:destroy() + end + end + end + + if (not is_busy) self:_tidy_up_gen() elseif self.state.name=="destroy" then -- destroy self.state.frame+=1 if (self.state.frame>=5) self.state={name="done"} @@ -814,34 +832,6 @@ function rope:destroy() self.state={name="destroy",frame=0} end -function rope:_make_consistent() - if (self.latch==nil) self:destroy() return - - if - self.latch!=nil and - self.latch.rec!=nil - then - self:drag_src( - self.latch.rec.px+self.latch.px_offset, - self.latch.rec.py+self.latch.py_offset - ) - - if #self.latch.rec.todo==0 then - if self.latch.rec.dead==true then - self:destroy() - end - end - end - self:_tidy_up_gen() - for i=0,#self.ancs do - local a0=self:_anc(i) - local a1=self:_anc(i+1) - if not self:_can_stretch(a0,a1) then - self:destroy() - end - end -end - function rope:continue_cast() local dx,dy=self.state.dx,self.state.dy local x0=self.src.x @@ -909,11 +899,12 @@ function rope:draw() circfill(x+dx+0.5,y+dy+0.5,1.0,color) end end - for i,p in ipairs(self.ancs) do + for i=0,#self.ancs+1 do + p=self:_anc(i) local c=12 if (p.dirty) c=13 rectfill(p.x-1,p.y-1,p.x+1,p.y+1,c) - print(p.id..":"..p.x..","..p.y..","..#p.todo,0,-8+i*8,9) + print(tostr(p.id)..":"..p.x..","..p.y..","..#p.todo,0,-8+i*8,9) end for _,p in pairs(level._anch) do pset(p.x,p.y,11) @@ -982,6 +973,7 @@ function rope:_tidy_up_gen() end if (invalid) self:make_dirty() + local busy=self:busy() if (not self:latched()) return if (not self.dirty) return @@ -993,7 +985,7 @@ function rope:_tidy_up_gen() local anc=self:_anc(a) if anc.dirty then anc.seen=true - if self[f](self,a) then + if self[f](self,a,busy) then settled=false anc.changed=true end end @@ -1042,6 +1034,16 @@ function rope:_tidy_up_gen() if (settled) break end + if (self:busy()) return + + for i=0,#self.ancs do + local a0=self:_anc(i) + local a1=self:_anc(i+1) + if not self:_can_stretch(a0,a1) then + self:destroy() + end + end + self.dirty=false end @@ -1105,7 +1107,7 @@ function rope:_find_touched_anchors(i) return false end -function rope:_elide_point(i) +function rope:_elide_point(i,busy) if (i<=0) return false if (#self.ancs0 then + ops_to_do=ops_before_trash + corners[i-1]=true + else + ops_to_do=find_all(#ops,1,-1) + corners[i]=true + end + local do_all=#ops==#ops_to_do ops=ops_to_do + if (do_all) corners[i-1]=true corners[i]=true + if #ops>0 then if (hypothetically) return ancs,i-1 @@ -1391,8 +1411,6 @@ function rope:_tug(hypothetically) o.mx,o.my,dmx,dmy ) end - local move_up_to=i - if (do_all) move_up_to=i-1 for node=ancs[i-1].ix,ancs[i].ix do local anc=self:_anc(node) local x0,y0=anc.x,anc.y @@ -1409,7 +1427,7 @@ function rope:_tug(hypothetically) end} end local dmxh,dmyh=dmx,dmy - if (node