100 lines
2.5 KiB
GDScript3
Raw Normal View History

2026-04-13 11:34:00 -05:00
class_name Building extends Node2D
@export var cost: int = 0
@export var player: Player:
set = _set_player
var is_placing: bool = false:
set(value):
is_placing = value
for child in get_children():
if child is Area2D:
child.monitoring = !is_placing
2026-04-13 11:34:00 -05:00
var starting_coord: Vector2i
var tile_rotation: Board.Direction = Board.Direction.UP
@onready var size_node: Control = %Size
2026-04-28 21:14:05 -05:00
@onready var bomb_sprite: Sprite2D = %BombSprite
2026-04-13 11:34:00 -05:00
2026-04-29 13:59:35 -05:00
func can_citizen_enter(_coord: Vector2i, _direction: Board.Direction) -> bool:
print("The extending class has to implement this!")
return false
func get_tile_coords() -> Array[Vector2i]:
print("The extending class has to implement this!")
return []
func get_direction_queue(_citizen: Citizen) -> Array[Board.Direction]:
print("The extending class has to implement this!")
return []
2026-04-13 11:34:00 -05:00
func building_entered(body: Node2D) -> void:
if body is Citizen:
print("Activate building effect!")
2026-04-13 11:34:00 -05:00
func _on_building_area_entered(area: Area2D) -> void:
var tile = area.get_parent()
if tile is Ground and !is_placing:
tile.queue_free()
func get_rotation_count() -> int:
var rotation_count: int = 0
if tile_rotation == Board.Direction.UP:
rotation_count = 0
elif tile_rotation == Board.Direction.RIGHT:
rotation_count = 1
elif tile_rotation == Board.Direction.DOWN:
rotation_count = 2
elif tile_rotation == Board.Direction.LEFT:
rotation_count = 3
return rotation_count
func _set_player(new_player: Player) -> void:
player = new_player
2026-04-28 21:06:45 -05:00
func show_bomb() -> void:
bomb_sprite.show()
func hide_bomb() -> void:
bomb_sprite.hide()
func serialize() -> Dictionary:
var result = {}
result["scene_file_path"] = scene_file_path
result["starting_coord"] = starting_coord
result["tile_rotation"] = tile_rotation
result["cost"] = cost
result["player"] = null
if get("player") != null:
result["player"] = get("player").serialize()
if get("money") != null:
result["money"] = get("money")
if get("required_money") != null:
result["required_money"] = get("required_money")
return result
static func deserialize(data: Dictionary) -> Building:
var building: Building = load(data["scene_file_path"]).instantiate()
building.tile_rotation = data["tile_rotation"]
building.starting_coord = data["starting_coord"]
building.cost = data["cost"]
if data["player"] != null:
building.player = Player.deserialize(data["player"])
if data.get("money") != null:
building.money = data["money"]
if data.get("required_money") != null:
building.required_money = data["required_money"]
return building