Hi! I've found another one for you, though hopefully I already have a potential (if partial) solution for it.
When cancelling a deconstruction order on some objects (specifically, cliffs, trees, curved rails and possibly rocks), unapproved ghosts placed on them are removed, but there are some leftover placeholder objects:
https://i.imgur.com/pXlnlgR.mp4
In the video I'm testing it with automatic deconstruction cancelling through the deconstruction timeout, but later I found the placeholders also remain when manually cancelling the deconstruction.
Apparently, when the ghosts get removed through cancelling deconstruction on underlying object, on_pre_ghost_deconstructed
doesn't get called, so remove_placeholder_for
doesn't get called either. Placeholders lying within the un-deconstructed object's selection box get removed properly, but for some entities (like cliffs or curved rails) those placeholders will lie outside of those bounding boxes and won't get auto-removed.
https://i.imgur.com/LwSPeVR.png
I've figured out it can be handled by using the on_cancelled_deconstruction
event.
script.on_event(defines.events.on_cancelled_deconstruction, function(event)
local surface = event.entity.surface
local area = event.entity.bounding_box
local placeholders = surface.find_entities_filtered {
area = area,
ghost_name = "unapproved-ghost-placeholder"
}
for _, placeholder in pairs (placeholders) do
placeholder.destroy()
end
end)
Looking for placeholders within the entity's bounding box sometimes works, though not always. I'll do some more testing tomorrow.
Though maybe you can find a more elegant solution. :)