From 12e0518948b873c638dba72f220db2436519a219 Mon Sep 17 00:00:00 2001 From: Tangent Date: Wed, 5 Nov 2025 03:00:23 -0700 Subject: [PATCH] areas --- ReadMe.md | 5 +++++ map.json | 26 +++++++++++++++++++------- src/main.lua | 40 ++++++++++++++++++++++++++++++++++++++-- 3 files changed, 62 insertions(+), 9 deletions(-) diff --git a/ReadMe.md b/ReadMe.md index cb63525..d599c53 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -21,6 +21,11 @@ used by this program. An array called `offset` will adjust the positioning of labels. An array called `color` will set the color via 0 to 1 RGBA values (node only). +Added `areas` which are exactly like nodes except that they always draw a white +label and can have a custom radius specified. Drawn between edges and nodes. +Use transparency. 25% works well. +- TODO Options: box instead of circle, line instead of fill, ovals + ## Example JSON ```json diff --git a/map.json b/map.json index fb2e462..b6671f1 100644 --- a/map.json +++ b/map.json @@ -28,13 +28,17 @@ "village crossroad": [130, 101, 296, false, {"notes": "insignificant"}], "Second Farm original route corner": [-180, 69, -30, false], "Second Farm original route corner 2": [-202, 79, -169, false], - "cherry blossum divergence point": [-332, 104, -423], - "original farm worldborder deadend": [-346, 109, -456], + "cherry blossum divergence point": [-332, 104, -423, false], + "original farm worldborder deadend": [-346, 109, -456, false], "Cherry Point": [-480, 104, -404, true, {"color": [1, 0.67, 0.67, 1]}], - "unnamed beach point": [-376, 63, -313], - "unnamed summit curve point": [-387, 119, -229], + "unnamed beach point": [-376, 63, -313, false], + "unnamed summit curve point": [-387, 119, -229, false], "unnamed summit": [-408, 130, -251], - "Sugarcane Point": [-161, 62, -365, true, {"color": [0.75, 1, 0.25, 1]}] + "Sugarcane Point": [-161, 62, -365, true, {"color": [0.75, 1, 0.25, 1]}], + "original border 1": [-500, 0, -500, false], + "original border 2": [-500, 0, 500, false], + "original border 3": [500, 0, 500, false], + "original border 4": [500, 0, -500, false] }, "edges": [ ["tree farm north", "Second Farm", null, {"offset": [0, -12]}], @@ -63,6 +67,14 @@ ["Cherry Point", "cherry blossum divergence point"], ["unnamed summit curve point", "unnamed beach point"], ["unnamed summit curve point", "unnamed summit", null, {"offset": [-14, 10]}], - ["Sugarcane Point", "Second Farm"] - ] + ["Sugarcane Point", "Second Farm"], + ["original border 2", "original border 1", "original border (west)"], + ["original border 1", "original border 4", "original border (north)"], + ["original border 4", "original border 3", "original border (east)"], + ["original border 3", "original border 2", "original border (south)"] + ], + "areas": { + "unnamed ocean": [600, 64, -150, true, {"radius": 300, "color": [0, 0, 1, 0.25]}], + "Farm Region": [-230, 80, -100, true, {"radius": 230, "color": [0, 0.5, 0, 0.15], "offset": [-60, 0]}] + } } diff --git a/src/main.lua b/src/main.lua index b563a59..72b9115 100644 --- a/src/main.lua +++ b/src/main.lua @@ -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}