From 930d9e6d8e9d54d1d981d79e8bcef9db56075e97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Melvin=20Wei=C3=9F?= Date: Wed, 22 Oct 2025 02:04:12 +0200 Subject: [PATCH] Removed initial load time --- buildings/building.gd | 24 +----------------------- world/grid.gd | 24 +++++++++++++++++++++++- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/buildings/building.gd b/buildings/building.gd index e985b19..74f472b 100644 --- a/buildings/building.gd +++ b/buildings/building.gd @@ -15,31 +15,9 @@ func _ready() -> void: if blocks_area: Grid.buildings.append(self) - #await get_tree().create_timer(0.2).timeout if get_node_or_null("ObjectList") != null: var obj_list = $ObjectList - obj_list.call_deferred("reparent", get_tree().get_root().get_node("main"), false) - 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") + Grid.call_deferred("place_object_list", obj_list, self) func overlaps(other : Building): # heights don't overlap diff --git a/world/grid.gd b/world/grid.gd index dcf1abb..afb702f 100644 --- a/world/grid.gd +++ b/world/grid.gd @@ -42,10 +42,25 @@ func add_building_to_collumn(building : Building, collumn : int): building.free() return false - add_child(building) 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: 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 @@ -86,6 +101,13 @@ func add_vine_to(vine, location) -> void: location = Global.vec_mod(location, num_collumns, true) 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 #func _ready() -> void: #