images, boxes, ellipses, lines
This commit is contained in:
@@ -23,7 +23,12 @@ labels. An array called `color` will set the color via 0 to 1 RGBA values.
|
||||
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
|
||||
- `box` can be an array of width/height to draw a rectangular shape instead
|
||||
- `radius` can be an array of x/z radii to draw an ellipse instead of a circle
|
||||
- `mode` can be "line" to draw an outline instead of filling
|
||||
- `image` can be a file path, in which case `size` must be an array of desired
|
||||
width/height
|
||||
- (path relative to the JSON file? or relative to the executable?)
|
||||
|
||||
## Example JSON
|
||||
|
||||
|
||||
5
map.json
5
map.json
@@ -81,6 +81,9 @@
|
||||
"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]}],
|
||||
"Mount Sharpe": [735, 110, 685, "mountainous region", {"radius": 165, "color": [1, 1, 1, 0.1], "offset": [-54, 4]}],
|
||||
"extreme mountains": [-150, 100, 450, true, {"radius": 310, "color": [1, 1, 1, 0.15], "offset": [-60, 0]}]
|
||||
"extreme mountains": [-150, 100, 450, true, {"radius": 310, "color": [1, 1, 1, 0.15], "offset": [-60, 0]}],
|
||||
"test box": [300, 0, 300, false, {"box": [50, 100], "mode": "line"}],
|
||||
"test ellipse": [600, 0, 600, false, {"radius": [150, 40]}],
|
||||
"test image": [0, 0, 0, true, {"image": "test image.png", "size": [1000, 1000]}]
|
||||
}
|
||||
}
|
||||
|
||||
34
src/main.lua
34
src/main.lua
@@ -38,6 +38,16 @@ local function load_map(map_file_name)
|
||||
nodes = map.nodes or {}
|
||||
edges = map.edges or {}
|
||||
areas = map.areas or {}
|
||||
for _, area in pairs(map.areas) do
|
||||
local image_file_name = area[5] and area[5].image
|
||||
if image_file_name then
|
||||
local file = io.open(image_file_name, "rb")
|
||||
local data = file:read("*all")
|
||||
file:close()
|
||||
local byte_data = love.data.newByteData(data)
|
||||
area[5].image_object = love.graphics.newImage(byte_data)
|
||||
end
|
||||
end
|
||||
|
||||
-- find map size
|
||||
minimums = {math.huge, math.huge} -- x, z
|
||||
@@ -62,6 +72,9 @@ local function load_map(map_file_name)
|
||||
local distance_z = maximums[2] - minimums[2]
|
||||
scale = math.min((screen_width - safe_zone * 2) / distance_x, (screen_height - safe_zone * 2) / distance_z)
|
||||
translation = {-minimums[1] + safe_zone / scale, -minimums[2] + safe_zone / scale}
|
||||
|
||||
-- TEMP displaying scale to debug
|
||||
-- scale = 1
|
||||
end
|
||||
load_map("map.json")
|
||||
|
||||
@@ -103,12 +116,29 @@ function love.draw()
|
||||
end
|
||||
end
|
||||
|
||||
-- areas sit between edges and nodes
|
||||
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)
|
||||
local mode = area[5] and area[5].mode or "fill"
|
||||
local box = area[5] and area[5].box
|
||||
local image = area[5] and area[5].image_object
|
||||
|
||||
if image then
|
||||
local size = area[5].size
|
||||
local image_width, image_height = image:getWidth(), image:getHeight()
|
||||
love.graphics.draw(image, area[1], area[3], 0, size[1] / image_width, size[2] / image_height, image_width / 2, image_height / 2)
|
||||
elseif box then
|
||||
love.graphics.rectangle(mode, area[1] - box[1] / 2, area[3] - box[2] / 2, box[1], box[2])
|
||||
else
|
||||
local radius = area[5] and area[5].radius or node_radius
|
||||
if type(radius) == "number" then
|
||||
love.graphics.circle(mode, area[1], area[3], radius)
|
||||
else
|
||||
love.graphics.ellipse(mode, area[1], area[3], radius[1], radius[2])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if area[4] then
|
||||
|
||||
BIN
test image.png
Normal file
BIN
test image.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 131 KiB |
Reference in New Issue
Block a user