How can I generate tileset borders that account for tiles being destroyed?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Hammo

I am trying to generate borders around a tilemap to make the tiles appear a little less rough around the edges (pun not intended), very similar to how the game Spelunky does it. The below is a good breakdown of how it works in that game.

My question is, how would I go about achieving this in Godot? Are there any features in Godot which would make this a simpler process? Anything in Godot 4 that would help?