28 lines
972 B
GDScript
28 lines
972 B
GDScript
extends Node2D
|
|
|
|
class_name EntityHolder
|
|
|
|
const GRID_SIZE : Vector2 = Vector2(16,16)
|
|
|
|
@export var building_zone : BuildZone
|
|
var constructions : Array[Construction]
|
|
|
|
func _ready() -> void:
|
|
constructions.resize(building_zone.get_capacity())
|
|
|
|
func add_construction(construction : Construction) -> bool:
|
|
var construction_dp = construction.get_dimension_points()
|
|
for point in construction_dp:
|
|
if constructions[building_zone.indexify_global_point(construction.global_position + point)]:
|
|
return false
|
|
construction.reparent(self)
|
|
construction.global_position = building_zone.get_placement_position(construction.global_position)
|
|
for point in construction_dp:
|
|
constructions[building_zone.indexify_global_point(construction.global_position + point)] = construction
|
|
return true
|
|
|
|
func get_at(point : Vector2) -> Construction:
|
|
return constructions[building_zone.indexify_global_point(point)]
|
|
|
|
func is_point_occupied(point : Vector2) -> bool:
|
|
return get_at(point) != null
|