movement and stuff, more data

This commit is contained in:
2025-11-05 01:08:13 -07:00
parent c130185a20
commit 880811262b
4 changed files with 104 additions and 36 deletions

View File

@@ -8,10 +8,11 @@ Each node is an `x`, `y`, and `z` position. The optional 4th item is `true` to
display the node's name, a string to display *that* as the node name, or `false` display the node's name, a string to display *that* as the node name, or `false`
to completely hide a node. `edges` is an array of arrays of two names of nodes. to completely hide a node. `edges` is an array of arrays of two names of nodes.
An optional 3rd item can be set to `false` to hide an edge, or a string for a An optional 3rd item can be set to `false` to hide an edge, or a string for a
custom label. custom label. `edges` can be nonexistent.
- TODO: Make drag and drop loading of a JSON file possible. :D WASD panning and -/+ to zoom.
- TODO: Make it not error with no map file.
You can drag and drop a JSON file to load it.
## Example JSON ## Example JSON

View File

@@ -25,7 +25,9 @@
"Ruined Nether Portal": [853, 79, 805, true], "Ruined Nether Portal": [853, 79, 805, true],
"Trickster Waterfall": [439, 81, 743, true], "Trickster Waterfall": [439, 81, 743, true],
"Trickster Waterfall (bottom)": [441, 62, 730, false], "Trickster Waterfall (bottom)": [441, 62, 730, false],
"village crossroad": [130, 101, 296, false, {"notes": "insignificant"}] "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]
}, },
"edges": [ "edges": [
["tree farm north", "Second Farm"], ["tree farm north", "Second Farm"],
@@ -45,6 +47,9 @@
["Warehouse/Mine", "skeleton spawner (1st mine)", false], ["Warehouse/Mine", "skeleton spawner (1st mine)", false],
["Great Rock Waterfall", "Great Rock Waterfall (bottom)"], ["Great Rock Waterfall", "Great Rock Waterfall (bottom)"],
["waterfall 2 top", "waterfall 2 bottom"], ["waterfall 2 top", "waterfall 2 bottom"],
["Trickster Waterfall", "Trickster Waterfall (bottom)", ""] ["Trickster Waterfall", "Trickster Waterfall (bottom)", ""],
["farm paths diverge point", "Second Farm original route corner"],
["Second Farm original route corner", "Second Farm original route corner 2"],
["Second Farm original route corner 2", "Second Farm"]
] ]
} }

View File

@@ -5,24 +5,42 @@ local screen_width, screen_height = love.graphics.getDimensions()
local node_radius = 2 local node_radius = 2
local safe_zone = 12 local safe_zone = 12
-- panning / scaling control tuning
local scale_adjust_speed = 2
local translation_adjust_speed = 600
local scale_fix_translation_adjustment = 300 -- this is wrong, and the wrong way to do this, but I don't know what the correct version is
local map = (function()
local file = io.open("map.json", "r") local nodes, edges, minimums, maximums, scale, translation
local text = file:read("*all") local function load_map(map_file_name)
local file, text
if type(map_file_name) == "string" then
file = io.open(map_file_name, "r")
if not file then
nodes = {}
edges = {}
minimums = {0, 0}
maximums = {100, 100}
scale = 1
translation = {0, 0}
return
end
text = file:read("*all")
else
file = map_file_name
file:open("r")
text = file:read("string")
end
local map = json.decode(text) local map = json.decode(text)
return map nodes = map.nodes
end)() edges = map.edges or {}
local nodes = map.nodes -- find map size
local edges = map.edges minimums = {math.huge, math.huge} -- x, z
maximums = {-math.huge, -math.huge} -- x, z
for _, node in pairs(nodes) do
-- find map size
local minimums = {math.huge, math.huge} -- x, z
local maximums = {-math.huge, -math.huge} -- x, z
for _, node in pairs(nodes) do
if node[1] > maximums[1] then if node[1] > maximums[1] then
maximums[1] = node[1] maximums[1] = node[1]
end end
@@ -35,13 +53,15 @@ for _, node in pairs(nodes) do
if node[3] < minimums[2] then if node[3] < minimums[2] then
minimums[2] = node[3] minimums[2] = node[3]
end end
end end
-- find scale factor, translate -- find scale factor, translate
local distance_x = maximums[1] - minimums[1] local distance_x = maximums[1] - minimums[1]
local distance_z = maximums[2] - minimums[2] local distance_z = maximums[2] - minimums[2]
local scale = math.min((screen_width - safe_zone * 2) / distance_x, (screen_height - safe_zone * 2) / distance_z) scale = math.min((screen_width - safe_zone * 2) / distance_x, (screen_height - safe_zone * 2) / distance_z)
local translation = {-minimums[1] + safe_zone / scale, -minimums[2] + safe_zone / scale} translation = {-minimums[1] + safe_zone / scale, -minimums[2] + safe_zone / scale}
end
load_map("map.json")
@@ -101,6 +121,39 @@ function love.draw()
love.graphics.print(name, text_x, text_y, 0, 1 / scale, 1 / scale) love.graphics.print(name, text_x, text_y, 0, 1 / scale, 1 / scale)
end end
end end
-- TEMP center of map
-- love.graphics.setColor(1, 1, 1, 1)
-- love.graphics.circle("fill", minimums[1] + (maximums[1] - minimums[1]) / 2, minimums[2] + (maximums[2] - minimums[2]) / 2, node_radius / scale)
end
function love.update(dt)
if love.keyboard.isDown("w") then
translation[2] = translation[2] + translation_adjust_speed / scale * dt
end
if love.keyboard.isDown("s") then
translation[2] = translation[2] - translation_adjust_speed / scale * dt
end
if love.keyboard.isDown("a") then
translation[1] = translation[1] + translation_adjust_speed / scale * dt
end
if love.keyboard.isDown("d") then
translation[1] = translation[1] - translation_adjust_speed / scale * dt
end
if love.keyboard.isDown("=") then
scale = scale + scale * scale_adjust_speed * dt
translation[1] = translation[1] - scale_fix_translation_adjustment * scale_adjust_speed * dt
translation[2] = translation[2] - scale_fix_translation_adjustment * scale_adjust_speed * dt
end
if love.keyboard.isDown("-") then
scale = scale - scale * scale_adjust_speed * dt
translation[1] = translation[1] + scale_fix_translation_adjustment * scale_adjust_speed * dt
translation[2] = translation[2] + scale_fix_translation_adjustment * scale_adjust_speed * dt
end
end
function love.filedropped(file)
load_map(file)
end end
function love.keypressed(key) function love.keypressed(key)

9
test map.json Normal file
View File

@@ -0,0 +1,9 @@
{
"nodes": {
"TopLeft": [0, 0, 0, true],
"TopRight": [1600, 0, 0, true],
"BottomLeft": [0, 0, 900, true],
"BottomRight": [1600, 0, 900, true]
},
"edges": []
}