Added lua-language-server annotations

This commit is contained in:
Alexey 2025-06-25 13:05:41 +03:00
commit c7d8fa4f8b
7 changed files with 151 additions and 87 deletions

View file

@ -1,18 +1,32 @@
require "gridpoint"
-- Line table, interactive game object
-- NOTE: uses GridPoint
Line = {}
-- Interactive game object
---@class Line
---@field startpoint GridPoint
---@field endpoint GridPoint
---@field points GridPoint[]
---@field color Color
Line = {
startpoint = GridPoint:new( GridPoint:coords() ),
endpoint = GridPoint:new( GridPoint:coords() ),
points = { },
color = Color.red
}
-- Factory function
---@param startpoint GridPoint
---@param endpoint GridPoint
---@param color Color
---@return Line
function Line:new( startpoint, endpoint, color )
local line = {
startpoint = startpoint,
endpoint = endpoint,
startpoint = startpoint or self.startpoint,
endpoint = endpoint or self.endpoint,
points = {
startpoint
startpoint or self.startpoint
},
color = color
color = color or self.color
}
setmetatable( line, { __index = self } )
@ -21,11 +35,13 @@ function Line:new( startpoint, endpoint, color )
end
-- Push point to the end of points stack
---@param point GridPoint
function Line:push( point )
table.insert( self.points, point )
end
-- Pop point from points stack
---@return GridPoint
function Line:pop()
return table.remove( self.points )
end
@ -64,13 +80,15 @@ end
function Line:reverse()
local swap = self.startpoint
self.startpoint = self.endpoint
self.endpoint = swap
self.endpoint = swap
self:push( self.startpoint )
end
-- Check if line has the exact point
---@param point GridPoint
---@return boolean
function Line:has( point )
return tableHas( self.points, point,
return TableHas( self.points, point,
function( value, innervalue )
return innervalue:equals( value )
end