Removed initial load time
This commit is contained in:
parent
248b1915b6
commit
930d9e6d8e
2 changed files with 24 additions and 24 deletions
|
|
@ -15,31 +15,9 @@ func _ready() -> void:
|
||||||
if blocks_area:
|
if blocks_area:
|
||||||
Grid.buildings.append(self)
|
Grid.buildings.append(self)
|
||||||
|
|
||||||
#await get_tree().create_timer(0.2).timeout
|
|
||||||
if get_node_or_null("ObjectList") != null:
|
if get_node_or_null("ObjectList") != null:
|
||||||
var obj_list = $ObjectList
|
var obj_list = $ObjectList
|
||||||
obj_list.call_deferred("reparent", get_tree().get_root().get_node("main"), false)
|
Grid.call_deferred("place_object_list", obj_list, self)
|
||||||
await get_tree().create_timer(0.2).timeout
|
|
||||||
var objects_to_be_placed = obj_list.get_children()
|
|
||||||
for object in objects_to_be_placed:
|
|
||||||
var offset = object.global_position;
|
|
||||||
object.global_position = Grid.get_world_position(location, offset)
|
|
||||||
|
|
||||||
# The building remembers these objects: If it is destroyed, so are they.
|
|
||||||
if object is Platform or object is Trap or object is Item:
|
|
||||||
objects.append(object)
|
|
||||||
if "building" in object: object.building = self
|
|
||||||
# This scales platforms hoizontally to make sure they still form a floor without gaps.
|
|
||||||
if(object.has_method("init_at_horizontal_distortion")):
|
|
||||||
object.init_at_horizontal_distortion(object.position.length() / Grid.ground_radius)
|
|
||||||
grid_entrance_callback(object)
|
|
||||||
|
|
||||||
func grid_entrance_callback(object : Node):
|
|
||||||
# Objects receive a callback when placed, starting from the deepest children
|
|
||||||
for child in object.get_children():
|
|
||||||
grid_entrance_callback(child)
|
|
||||||
if object.has_method("_enter_grid"):
|
|
||||||
object.call_deferred("_enter_grid")
|
|
||||||
|
|
||||||
func overlaps(other : Building):
|
func overlaps(other : Building):
|
||||||
# heights don't overlap
|
# heights don't overlap
|
||||||
|
|
|
||||||
|
|
@ -42,10 +42,25 @@ func add_building_to_collumn(building : Building, collumn : int):
|
||||||
building.free()
|
building.free()
|
||||||
return false
|
return false
|
||||||
|
|
||||||
|
|
||||||
add_child(building)
|
add_child(building)
|
||||||
return true
|
return true
|
||||||
|
|
||||||
|
func place_object_list(obj_list : Node2D, building):
|
||||||
|
obj_list.reparent(self, false)
|
||||||
|
var objects_to_be_placed = obj_list.get_children()
|
||||||
|
for object in objects_to_be_placed:
|
||||||
|
var offset = object.global_position;
|
||||||
|
object.global_position = Grid.get_world_position(building.location, offset)
|
||||||
|
|
||||||
|
# The building remembers these objects: If it is destroyed, so are they.
|
||||||
|
if object is Platform or object is Trap or object is Item:
|
||||||
|
building.objects.append(object)
|
||||||
|
if "building" in object: object.building = self
|
||||||
|
# This scales platforms hoizontally to make sure they still form a floor without gaps.
|
||||||
|
if(object.has_method("init_at_horizontal_distortion")):
|
||||||
|
object.init_at_horizontal_distortion(object.position.length() / Grid.ground_radius)
|
||||||
|
grid_entrance_callback(object)
|
||||||
|
|
||||||
func get_world_position (location: Vector2, offset: Vector2 = Vector2.ZERO) -> Vector2:
|
func get_world_position (location: Vector2, offset: Vector2 = Vector2.ZERO) -> Vector2:
|
||||||
var height = ground_radius + location.y * cell_height - offset.y # currently assumes anchor is bottom left
|
var height = ground_radius + location.y * cell_height - offset.y # currently assumes anchor is bottom left
|
||||||
var angle = (location.x + offset.x / cell_height) * TAU / num_collumns
|
var angle = (location.x + offset.x / cell_height) * TAU / num_collumns
|
||||||
|
|
@ -86,6 +101,13 @@ func add_vine_to(vine, location) -> void:
|
||||||
location = Global.vec_mod(location, num_collumns, true)
|
location = Global.vec_mod(location, num_collumns, true)
|
||||||
vines_per_node[location.x][location.y].append(vine)
|
vines_per_node[location.x][location.y].append(vine)
|
||||||
|
|
||||||
|
func grid_entrance_callback(object : Node):
|
||||||
|
# Objects receive a callback when placed, starting from the deepest children
|
||||||
|
for child in object.get_children():
|
||||||
|
grid_entrance_callback(child)
|
||||||
|
if object.has_method("_enter_grid"):
|
||||||
|
object.call_deferred("_enter_grid")
|
||||||
|
|
||||||
# for testing
|
# for testing
|
||||||
#func _ready() -> void:
|
#func _ready() -> void:
|
||||||
#
|
#
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue