How to get the dimensions of an entity at runtime?

Place to get help with not working mods / modding interface.
Post Reply
Pi-C
Smart Inserter
Smart Inserter
Posts: 1639
Joined: Sun Oct 14, 2018 8:13 am
Contact:

How to get the dimensions of an entity at runtime?

Post by Pi-C »

I'm having a minor problem with a GUI where I want to center the camera on an entity:

Code: Select all

elements = my_gui[preview_frame]
for e, entity in pairs(entities) do
	element = entity.name.."-camera"
	elements.add{
        	  type = "camera",
	          name = element,
        	  zoom = zoom,
	          surface_index = entity.surface.index,
        	  position = {entity.position.x, entity.position.y - OFFSET},
	}
	…
end
The entities are based on different prototypes (basically, all these prototypes are variations of the same vanilla prototype), so they will look differently and their graphics may be of a different size. In order to center them vertically, I need to apply OFFSET. However, as some entities are higher than others, I'd need to adjust the value of OFFSET. That would be easy if there was a way to get at the dimensions of the graphics, but it seems that entity.prototype does not have any relevant information I could use.

I've compared the values of different prototypes, but their respective selection_box, collision_box, and drawing_box had identical values. Height/size of animations is what I'd really need, but that information is only available during the data stage.

The different entities I want to show in my GUI come from different mods, so I'm not really in control of them. Is there a way to get the size of graphics of random entities during the control stage?
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

Post Reply

Return to “Modding help”