Skip to content

Commit

Permalink
Draw correct entity size based on bounding_box
Browse files Browse the repository at this point in the history
  • Loading branch information
Danielv123 committed Apr 13, 2024
1 parent 9b026e8 commit 38b9468
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
30 changes: 20 additions & 10 deletions module/map/dump_entities.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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::
Expand All @@ -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
2 changes: 1 addition & 1 deletion web/components/GridVisualizer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export default function GridVisualizer(props) {
setRefreshTiles(Math.floor(Math.random() * 10000).toString());
}, 2500);
return () => clearInterval(interval);
});
}, []);

return <>
<div className="grid-visualizer">
Expand Down

0 comments on commit 38b9468

Please sign in to comment.