generated from krampus/template-godot4
All checks were successful
linting & formatting / build (push) Successful in 26s
100 lines
2.5 KiB
GDScript
100 lines
2.5 KiB
GDScript
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
|
|
|
|
var starting_coord: Vector2i
|
|
var tile_rotation: Board.Direction = Board.Direction.UP
|
|
|
|
@onready var size_node: Control = %Size
|
|
@onready var bomb_sprite: Sprite2D = %BombSprite
|
|
|
|
|
|
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 []
|
|
|
|
|
|
func building_entered(body: Node2D) -> void:
|
|
if body is Citizen:
|
|
print("Activate building effect!")
|
|
|
|
|
|
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
|
|
|
|
|
|
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
|