Okay, I really need some more help.
As far as I can tell, my code is working just fine.
The raycasts are returning the cells that are in line-of-sight of the hero and removing them from the invisibletiles array.
I then call notify_runtime_tile_data_update() which triggers the update and the tile appears.
So far, so good.
However, I have noticed that occasionally a tile will not appear, even though it has been removed from the array.
I have created a helper function to troubleshoot:
func double_check(target : Vector2) -> void:
var cell = self.local_to_map(target)
print(cell)
if cell in invisibletiles:
print ("invisible -> visible")
invisibletiles.erase(cell)
notify_runtime_tile_data_update()
else:
print("visible -> invisible")
invisibletiles.append(cell)
notify_runtime_tile_data_update()
This allows me to trigger the tiles visibility at will, however those tiles will still not become visible.
Unless... I hide another tile somewhere else and then suddenly it will start to work! Although now the tile that I 'turned off' will no longer turn back on...
Now, I don't understand this behaviour at all. If I understand correctly, the function:
func _tile_data_runtime_update(_coords, tile_data):
tile_data.modulate.a = 0
Is making the tiles invisible, so if this function does not run on the tile, it should be visible by default, but it isn't. The tile has been removed from the array and therefore this function is not being called on it.