Changed drawing order and updated line connecting

This commit is contained in:
Alexey 2025-05-22 17:15:32 +03:00
commit 178043bac3
2 changed files with 23 additions and 4 deletions

View file

@ -22,20 +22,26 @@ end
-- Draw lines and the whole grid
function Grid:draw()
-- Draw lines
-- Draw grid
for x = 1, self.size.x do-- Draw lines
for _, line in ipairs( self.lines ) do
line:draw()
end
-- Draw grid
for x = 1, self.size.x do
for y = 1, self.size.y do
local px, py = x * Config.cellSize, y * Config.cellSize
love.graphics.circle( "fill", px - Config.cellSize / 2, py - Config.cellSize / 2, Config.pointRadius)
end
end
-- Draw lines
for _, line in ipairs( self.lines ) do
line:draw()
end
end
-- Check all lines and return one, which contains point (if any)
-- TODO: rewrite this function to extract clear/reverse behavior
function Grid:matchesLine( point, ignoreEnd )
local line = self.lines[tableFind( self.lines, point,
function( value, innervalue )
@ -71,6 +77,13 @@ function Grid:matchesLine( point, ignoreEnd )
return line
end
function Grid:isOtherEndpoint( line, point )
return tableHas( self.lines, { line=line, point=point }, function( value, innervalue )
return innervalue ~= value.line and innervalue.endpoint:equals( value.point )
end
)
end
function Grid:inBounds( point )
return point.x <= self.size.x and point.y <= self.size.y
end