This commit is contained in:
2025-11-05 03:00:23 -07:00
parent 4696a99095
commit 12e0518948
3 changed files with 62 additions and 9 deletions

View File

@@ -12,7 +12,7 @@ local scale_fix_translation_adjustment = 300 -- this is wrong, and the wrong way
local nodes, edges, minimums, maximums, scale, translation
local nodes, edges, areas, minimums, maximums, scale, translation
local function load_map(map_file_name)
local file, text
if type(map_file_name) == "string" then
@@ -20,6 +20,7 @@ local function load_map(map_file_name)
if not file then
nodes = {}
edges = {}
areas = {}
minimums = {0, 0}
maximums = {100, 100}
scale = 1
@@ -34,8 +35,9 @@ local function load_map(map_file_name)
end
local map = json.decode(text)
nodes = map.nodes
nodes = map.nodes or {}
edges = map.edges or {}
areas = map.areas or {}
-- find map size
minimums = {math.huge, math.huge} -- x, z
@@ -99,6 +101,40 @@ function love.draw()
end
end
for name, area in pairs(areas) do
local color = area[5] and area[5].color or {1, 1, 1, 0.25}
love.graphics.setColor(color)
if not (area[4] == false) then
local radius = area[5] and area[5].radius or node_radius
love.graphics.circle("fill", area[1], area[3], radius)
end
if area[4] then
if type(area[4]) == "string" then
name = area[4]
end
local text_x, text_z = area[1] + node_radius / scale, area[3] + node_radius / scale
local difference = area[1] + font:getWidth(name) - maximums[1]
if difference > 0 then
text_x = area[1] - (node_radius + difference) / scale
end
local difference = area[3] + font:getHeight() - maximums[2]
if difference > 0 then
text_z = area[3] - (node_radius + difference) / scale
end
if area[5] and area[5].offset then
text_x = text_x + area[5].offset[1] / scale
text_z = text_z + area[5].offset[2] / scale
end
love.graphics.setColor(1, 1, 1, 1)
love.graphics.print(name, text_x, text_z, 0, 1 / scale, 1 / scale)
end
end
-- draw nodes and label them
for name, node in pairs(nodes) do
local color = node[5] and node[5].color or {1, 1, 1, 1}