Little refactoring

This commit is contained in:
Alexey 2025-06-25 14:01:04 +03:00
commit 8a8db93ac1
7 changed files with 67 additions and 53 deletions

View file

@ -1,5 +1,5 @@
require "point"
require "config"
require 'point'
require 'config'
-- Point table with grid-based coordinates
---@class GridPoint: Point
@ -17,5 +17,15 @@ end
-- Same as coords, but converted to global coords
---@return number, number
function GridPoint:globalCoords()
return self.x * Config.cellSize - Config.cellSize / 2, self.y * Config.cellSize - Config.cellSize / 2
return self.x * Config.cellSize - Config.cellSize / 2,
self.y * Config.cellSize - Config.cellSize / 2
end
-- Returns local coords from global
---@param point Point
---@return GridPoint
function GridPoint.snapCoords( point )
local x = math.ceil( point.x / Config.cellSize )
local y = math.ceil( point.y / Config.cellSize )
return GridPoint:new( x, y )
end