hiding option, readme
This commit is contained in:
37
ReadMe.md
Normal file
37
ReadMe.md
Normal file
@@ -0,0 +1,37 @@
|
||||
# World6-travelmap
|
||||
I made a little program for displaying a simplistic graph of nodes and edges to
|
||||
make a travel network with calculated distances... specifically for my Minecraft
|
||||
World.
|
||||
|
||||
Data must be in a map.json file. `nodes` is an object with named arrays of info.
|
||||
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`
|
||||
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.
|
||||
|
||||
- TODO: Make drag and drop loading of a JSON file possible. :D
|
||||
- TODO: Make it not error with no map file.
|
||||
|
||||
## Example JSON
|
||||
|
||||
```json
|
||||
{
|
||||
"nodes": {
|
||||
"TestA": [100, 0, 100],
|
||||
"TestB": [150, 0, 200],
|
||||
"TestC": [300, 0, -200, true],
|
||||
"TestE": [1200, 0, 200, "Displayed Name"],
|
||||
"TestFarLeft": [-200, 5000, 50],
|
||||
"TestFarBottomRight": [1200, 0, 2000, true],
|
||||
"Hidden Node": [0, 0, 0, false]
|
||||
},
|
||||
"edges": [
|
||||
["TestA", "TestB"],
|
||||
["TestA", "TestC"],
|
||||
["TestB", "TestC"],
|
||||
["TestC", "TestE"],
|
||||
["TestE", "TestFarLeft"],
|
||||
["Hidden Node", "TestC", false]
|
||||
]
|
||||
}
|
||||
```
|
||||
6
map.json
6
map.json
@@ -5,13 +5,15 @@
|
||||
"TestC": [300, 0, -200, true],
|
||||
"TestE": [1200, 0, 200, "Displayed Name"],
|
||||
"TestFarLeft": [-200, 5000, 50],
|
||||
"TestFarBottomRight": [1200, 0, 2000, true]
|
||||
"TestFarBottomRight": [1200, 0, 2000, true],
|
||||
"Hidden Node": [0, 0, 0, false]
|
||||
},
|
||||
"edges": [
|
||||
["TestA", "TestB"],
|
||||
["TestA", "TestC"],
|
||||
["TestB", "TestC"],
|
||||
["TestC", "TestE"],
|
||||
["TestE", "TestFarLeft"]
|
||||
["TestE", "TestFarLeft"],
|
||||
["Hidden Node", "TestC", false]
|
||||
]
|
||||
}
|
||||
|
||||
20
src/main.lua
20
src/main.lua
@@ -57,21 +57,25 @@ function love.draw()
|
||||
error("Edge " .. index .. " names nonexistent node(s): " .. edge[1] .. "->" .. node_a .. ", " .. edge[2] .. "->" .. node_b)
|
||||
end
|
||||
|
||||
love.graphics.setColor(0.33, 0.33, 0.33, 1)
|
||||
love.graphics.line(node_a[1], node_a[3], node_b[1], node_b[3])
|
||||
if not (edge[3] == false) then
|
||||
love.graphics.setColor(0.33, 0.33, 0.33, 1)
|
||||
love.graphics.line(node_a[1], node_a[3], node_b[1], node_b[3])
|
||||
|
||||
local center_x = node_a[1] + (node_b[1] - node_a[1]) / 2
|
||||
local center_z = node_a[3] + (node_b[3] - node_a[3]) / 2
|
||||
local distance = math.floor(math.sqrt((node_b[3] - node_a[3])^2 + (node_b[2] - node_a[2])^2 + (node_b[1] - node_a[1])^2))
|
||||
local center_x = node_a[1] + (node_b[1] - node_a[1]) / 2
|
||||
local center_z = node_a[3] + (node_b[3] - node_a[3]) / 2
|
||||
local distance = math.floor(math.sqrt((node_b[3] - node_a[3])^2 + (node_b[2] - node_a[2])^2 + (node_b[1] - node_a[1])^2))
|
||||
|
||||
love.graphics.setColor(0.67, 0.67, 0.67, 1)
|
||||
love.graphics.print(distance .. "m", center_x, center_z - font:getHeight() / 2, 0, 1 / scale, 1 / scale)
|
||||
love.graphics.setColor(0.67, 0.67, 0.67, 1)
|
||||
love.graphics.print(distance .. "m", center_x, center_z - font:getHeight() / 2, 0, 1 / scale, 1 / scale)
|
||||
end
|
||||
end
|
||||
|
||||
-- draw nodes and label them
|
||||
love.graphics.setColor(1, 1, 1, 1)
|
||||
for name, node in pairs(nodes) do
|
||||
love.graphics.circle("fill", node[1], node[3], node_radius / scale)
|
||||
if not (node[4] == false) then
|
||||
love.graphics.circle("fill", node[1], node[3], node_radius / scale)
|
||||
end
|
||||
|
||||
if node[4] then
|
||||
if type(node[4]) == "string" then
|
||||
|
||||
Reference in New Issue
Block a user