2026-04-20 13:03:39 -05:00
|
|
|
class_name Tile extends Node2D
|
2026-04-13 11:34:00 -05:00
|
|
|
|
2026-04-15 10:45:43 -05:00
|
|
|
@warning_ignore("unused_signal")
|
2026-04-13 11:34:00 -05:00
|
|
|
signal tile_selected(tile: Tile)
|
|
|
|
|
|
2026-04-20 13:03:39 -05:00
|
|
|
@export var coords: Vector2i
|
|
|
|
|
@export var cost: int = 0
|
2026-04-24 12:19:34 -05:00
|
|
|
@export var day_placed: int = 0
|
|
|
|
|
@export var player: Player:
|
|
|
|
|
set = _set_player
|
2026-04-20 13:03:39 -05:00
|
|
|
|
2026-04-13 11:34:00 -05:00
|
|
|
var highlighted: bool = false
|
2026-04-20 13:03:39 -05:00
|
|
|
var is_placing: bool = false
|
2026-04-13 11:34:00 -05:00
|
|
|
|
2026-04-15 10:45:43 -05:00
|
|
|
|
2026-04-13 11:34:00 -05:00
|
|
|
func handle_mouse_entered() -> void:
|
|
|
|
|
highlighted = true
|
|
|
|
|
|
2026-04-15 10:45:43 -05:00
|
|
|
|
2026-04-13 11:34:00 -05:00
|
|
|
func handle_mouse_exited() -> void:
|
|
|
|
|
highlighted = false
|
2026-04-20 13:03:39 -05:00
|
|
|
|
|
|
|
|
|
2026-04-24 12:19:34 -05:00
|
|
|
func _set_player(value: Player) -> void:
|
|
|
|
|
player = value
|
|
|
|
|
|
|
|
|
|
|
2026-04-20 13:03:39 -05:00
|
|
|
func serialize() -> Dictionary:
|
|
|
|
|
var result = {}
|
|
|
|
|
result["scene_file_path"] = scene_file_path
|
|
|
|
|
result["coords"] = coords
|
|
|
|
|
result["cost"] = cost
|
2026-04-24 12:19:34 -05:00
|
|
|
result["day_placed"] = day_placed
|
|
|
|
|
if player != null:
|
|
|
|
|
result["player"] = player.serialize()
|
2026-04-20 13:03:39 -05:00
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static func deserialize(data: Dictionary) -> Tile:
|
|
|
|
|
var tile: Tile = load(data["scene_file_path"]).instantiate()
|
|
|
|
|
tile.coords = data["coords"]
|
|
|
|
|
tile.cost = data["cost"]
|
2026-04-24 12:19:34 -05:00
|
|
|
tile.day_placed = data["day_placed"]
|
|
|
|
|
if data.get("player") != null:
|
|
|
|
|
tile.player = Player.deserialize(data["player"])
|
2026-04-20 13:03:39 -05:00
|
|
|
return tile
|