57 lines
1.3 KiB
Lua
57 lines
1.3 KiB
Lua
-- Global config table
|
|
---@class Config
|
|
---@field pointRadius number Radius of each grid point
|
|
---@field linePointRadius number Radius of line start/end point
|
|
---@field cellSize number Size of each grid cell
|
|
---@field lineStyle string love2d line style setting
|
|
---@field lineWidth number love2d line width setting
|
|
---@field dragSensivity number drag sensivity, px
|
|
Config = {
|
|
pointRadius = 7,
|
|
|
|
linePointRadius = 10,
|
|
|
|
cellSize = 30,
|
|
|
|
lineStyle = "smooth",
|
|
lineWidth = 5,
|
|
|
|
dragSensivity = 5
|
|
}
|
|
|
|
-- Colors table
|
|
---@enum Color
|
|
Color = {
|
|
white = { 1, 1, 1 },
|
|
red = { 1, 0, 0 },
|
|
green = { 0, 1, 0 },
|
|
blue = { 0, 0, 1 }
|
|
}
|
|
|
|
-- Find key by value in table by predicate
|
|
---@param table table
|
|
---@param value any
|
|
---@param pred function
|
|
---@return any
|
|
function TableFind( table, value, pred )
|
|
for key, innervalue in pairs( table ) do
|
|
if pred( value, innervalue ) then
|
|
return key
|
|
end
|
|
end
|
|
return nil
|
|
end
|
|
|
|
-- Find if value exists in table by predicate
|
|
---@param table table
|
|
---@param value any
|
|
---@param pred function
|
|
---@return boolean
|
|
function TableHas( table, value, pred )
|
|
for _, innervalue in pairs( table ) do
|
|
if pred( value, innervalue ) then
|
|
return true
|
|
end
|
|
end
|
|
return false
|
|
end
|