brackeys-12/BuildingLevel.gd
2024-09-14 18:01:46 -04:00

45 lines
999 B
GDScript

extends TileMapLayer
@export var building_spots: Array[Vector2i]
var building_data = {}
func _process(delta: float) -> void:
var tile = local_to_map(get_global_mouse_position())
var building_mode = Persister.get_value("building_mode")
if Input.is_action_just_pressed("lclick"):
if building_mode:
place_building()
else:
show_info_building()
for spot in building_spots:
if not building_data.has(spot):
erase_cell(spot)
if not building_mode:
return
if building_spots.has(tile):
set_cell(tile, 1, Vector2i(0,0), 0)
func place_building():
var tile = local_to_map(get_global_mouse_position())
if building_spots.has(tile):
Persister.persist_data("building_mode", false)
building_data[tile] = {
"key": Persister.get_value("building_key"),
}
Persister.persist_data("drag_mode", false)
func show_info_building():
var tile = local_to_map(get_global_mouse_position())
if building_data.has(tile):
Triggerer.trigger("show_info", building_data[tile])