From 38b9468c7214091c7faeb675d1330593ac172bbc Mon Sep 17 00:00:00 2001 From: Danielv123 Date: Sat, 13 Apr 2024 21:08:14 +0200 Subject: [PATCH] Draw correct entity size based on bounding_box --- module/map/dump_entities.lua | 30 ++++++++++++++++++++---------- web/components/GridVisualizer.jsx | 2 +- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/module/map/dump_entities.lua b/module/map/dump_entities.lua index e8738b1..0c971f4 100644 --- a/module/map/dump_entities.lua +++ b/module/map/dump_entities.lua @@ -16,17 +16,27 @@ local function dump_entities(entities) if map_color ~= nil then local is_resource = entity.prototype.collision_mask["resource-layer"] if is_resource then - if (math.floor(position.x/2) + math.floor(position.y/2)) % 2 == 0 then -- Create checkerboard pattern associated with resources - table.insert(map_data, position.x) - table.insert(map_data, position.y) - table.insert(map_data, string.format("%02x%02x%02x", map_color.r, map_color.g, map_color.b)) + if (math.floor(position.x/2) + math.floor(position.y/2)) % 2 == 0 then + table.insert(map_data, position.x) + table.insert(map_data, position.y) + table.insert(map_data, string.format("%02x%02x%02x", map_color.r, map_color.g, map_color.b)) end else - -- Format as hexadecimal - table.insert(map_data, position.x) - table.insert(map_data, position.y) - table.insert(map_data, string.format("%02x%02x%02x", map_color.r, map_color.g, map_color.b)) + -- Determine size of entity to draw + -- TODO: Does not seem to get the correct shape for trees and cliffs + local size_x = math.ceil((entity.bounding_box.left_top.x - entity.bounding_box.right_bottom.x) * -1) + local size_y = math.ceil((entity.bounding_box.left_top.y - entity.bounding_box.right_bottom.y) * -1) + + -- Add pixels + for x = 0, size_x-1 do + for y = 0, size_y-1 do + -- Format as hexadecimal + table.insert(map_data, position.x + x - (size_x-1)/2) + table.insert(map_data, position.y + y - (size_y-1)/2) + table.insert(map_data, string.format("%02x%02x%02x", map_color.r, map_color.g, map_color.b)) + end + end end end ::continue:: @@ -37,7 +47,7 @@ local function dump_entities(entities) data = table.concat(map_data, ";"), }) end --- dump_entities(game.surfaces[1].find_tiles_filtered{position = game.player.position, radius = 32}) - +-- /c gridworld.map.dump_entities({game.player.selected}) +-- gridworld.map.dump_entities(game.surfaces[1].find_tiles_filtered{position = game.player.position, radius = 32}) return dump_entities diff --git a/web/components/GridVisualizer.jsx b/web/components/GridVisualizer.jsx index c26acdb..078a0f2 100644 --- a/web/components/GridVisualizer.jsx +++ b/web/components/GridVisualizer.jsx @@ -31,7 +31,7 @@ export default function GridVisualizer(props) { setRefreshTiles(Math.floor(Math.random() * 10000).toString()); }, 2500); return () => clearInterval(interval); - }); + }, []); return <>