I found a nice video explaining how to instantiate a scene from a TileMap which allowed me to do what I wanted.
Here it is for anyone looking: https://www.youtube.com/watch?v=CDwSTV0y9Rg
Based on that, I wrote this script for my fence tilemap, it will replace the tile of the fence by an actual fence scene I've created (that handle opened/closed state & animation):
extends TileMap
const wooden_gate = preload("res://WoodenGate.tscn")
func _ready():
var gates_pos = get_used_cells_by_id(1)
var tilePos
for gate_pos in gates_pos:
var gate = wooden_gate.instance()
tilePos = map_to_world(gate_pos)
gate.set_position(tilePos)
set_cell(gate_pos.x, gate_pos.y, -1)
self.add_child(gate)
And this small code I've seen multiple times comes very handy as it allows the AutoTile for the fence to match the door (which is not in the fence autotile set). It's a script to attach to the TileSet:
tool
extends TileSet
const WOODEN_FENCE = 0
const WOODEN_GATE = 1
var binds = {
WOODEN_FENCE: [WOODEN_GATE],
WOODEN_GATE: [WOODEN_FENCE]
}
func _is_tile_bound(drawn_id, neighbor_id):
if drawn_id in binds:
return neighbor_id in binds[drawn_id]
return false
Then, I just need to create a tile for the door in the tileset and set the bitmap to match the expected left and right fences.
Here is the result:
