Added lua-language-server annotations
This commit is contained in:
parent
178043bac3
commit
c7d8fa4f8b
7 changed files with 151 additions and 87 deletions
28
grid.lua
28
grid.lua
|
@ -1,9 +1,17 @@
|
|||
require "config"
|
||||
|
||||
-- Game grid table, acts as "global level" of some sort
|
||||
Grid = {}
|
||||
---@class Grid
|
||||
---@field lines Line[]
|
||||
---@field size Point
|
||||
Grid = {
|
||||
lines = {},
|
||||
size = Point:new( Point:coords() )
|
||||
}
|
||||
|
||||
-- Factory function
|
||||
---@param size Point
|
||||
---@returns Grid
|
||||
function Grid:new( size )
|
||||
local grid = {
|
||||
lines = {},
|
||||
|
@ -16,6 +24,7 @@ function Grid:new( size )
|
|||
end
|
||||
|
||||
-- Add new line to grid
|
||||
---@param line Line
|
||||
function Grid:push( line )
|
||||
table.insert( self.lines, line )
|
||||
end
|
||||
|
@ -42,13 +51,15 @@ end
|
|||
|
||||
-- Check all lines and return one, which contains point (if any)
|
||||
-- TODO: rewrite this function to extract clear/reverse behavior
|
||||
---@param point Point
|
||||
---@param ignoreEnd boolean
|
||||
function Grid:matchesLine( point, ignoreEnd )
|
||||
local line = self.lines[tableFind( self.lines, point,
|
||||
local line = self.lines[TableFind( self.lines, point,
|
||||
function( value, innervalue )
|
||||
return innervalue:has( value )
|
||||
end
|
||||
)]
|
||||
|
||||
|
||||
if line ~= nil and not ignoreEnd then
|
||||
if line.startpoint:equals( point ) then
|
||||
line:clear()
|
||||
|
@ -63,7 +74,7 @@ function Grid:matchesLine( point, ignoreEnd )
|
|||
|
||||
-- Try to check endpoint
|
||||
if line == nil and not ignoreEnd then
|
||||
line = self.lines[tableFind( self.lines, point,
|
||||
line = self.lines[TableFind( self.lines, point,
|
||||
function( value, innervalue )
|
||||
if innervalue.endpoint:equals( value ) then
|
||||
innervalue:clear()
|
||||
|
@ -77,13 +88,20 @@ function Grid:matchesLine( point, ignoreEnd )
|
|||
return line
|
||||
end
|
||||
|
||||
-- Checks if specified point does belong to any line endpoint but not specified line
|
||||
---@param line Line
|
||||
---@param point GridPoint
|
||||
---@return boolean
|
||||
function Grid:isOtherEndpoint( line, point )
|
||||
return tableHas( self.lines, { line=line, point=point }, function( value, innervalue )
|
||||
return TableHas( self.lines, { line=line, point=point }, function( value, innervalue )
|
||||
return innervalue ~= value.line and innervalue.endpoint:equals( value.point )
|
||||
end
|
||||
)
|
||||
end
|
||||
|
||||
-- Checks if point is in grid bounds
|
||||
---@param point GridPoint
|
||||
---@return boolean
|
||||
function Grid:inBounds( point )
|
||||
return point.x <= self.size.x and point.y <= self.size.y
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue