fixed item deletion and re-creation
This commit is contained in:
+18
-19
@@ -81,10 +81,10 @@ func initialize_world_center() -> void:
|
||||
for y in range(-1, 2):
|
||||
var current_coord = Vector2i(x, y)
|
||||
|
||||
grid_data[current_coord] = {
|
||||
grid_data[current_coord] = [{
|
||||
"type": "consumer",
|
||||
"is_center": (x == 0 and y == 0) # Only (0,0) is marked as the visual center
|
||||
}
|
||||
}]
|
||||
print("World Core Initialized: 3x3 Consumer registered from (-1,-1) to (1,1)")
|
||||
if producer_scene:
|
||||
print("Placing consumer at (0, 0)")
|
||||
@@ -145,10 +145,10 @@ func process_grid_data_at(coords: Vector2i) -> void:
|
||||
# disabled: }
|
||||
|
||||
|
||||
grid_data[coords] = {
|
||||
grid_data[coords] = [{
|
||||
"type": "producer",
|
||||
"value": producer_value
|
||||
}
|
||||
}]
|
||||
|
||||
if producer_scene:
|
||||
print("Placing producer at " + str(coords.x) + ", " + str(coords.y))
|
||||
@@ -209,37 +209,37 @@ func place_item(item: PackedScene):
|
||||
"type": new_item.name,
|
||||
})
|
||||
|
||||
func delete_item(target_pos: Vector2):
|
||||
print("deleting item")
|
||||
func delete_item(target_pos: Vector2i):
|
||||
var targets = get_tree().get_nodes_in_group("Placed_objects")
|
||||
for item in targets:
|
||||
if item.global_position == target_pos:
|
||||
print("Trying to match delete at: " + str(tile_layer.local_to_map(item.global_position)[0]) + ", " + str(tile_layer.local_to_map(item.global_position)[1]))
|
||||
if tile_layer.local_to_map(item.global_position) == target_pos:
|
||||
print("deleting item")
|
||||
item.queue_free()
|
||||
delete_object_at_coordinate(target_pos)
|
||||
break # Prevents deleting multiple items.
|
||||
|
||||
# Helper function: Check if a coordinate is occupied by a building
|
||||
func get_object_at_coordinate(coords: Vector2i):
|
||||
if grid_data.has(coords):
|
||||
return grid_data[coords]
|
||||
print(grid_data)
|
||||
return grid_data[coords][-1] # Return the last item there
|
||||
return null # Returns null if it's just an empty background tile
|
||||
|
||||
# Helper function: Force place an object into the grid data registry
|
||||
func register_object_at_coordinate(coords: Vector2i, object_data: Dictionary) -> void:
|
||||
grid_data[coords] = object_data
|
||||
if grid_data.has(coords):
|
||||
grid_data[coords].append(object_data)
|
||||
else:
|
||||
grid_data[coords] = [object_data]
|
||||
|
||||
func delete_object_at_coordinate(coords: Vector2i):
|
||||
grid_data[coords].pop_back()
|
||||
|
||||
|
||||
# --- UI Button Signals ---
|
||||
func _on_extractor_button_pressed():
|
||||
set_preview_mode(Mode.PLACE_EXTRACTOR, EXTRACTOR_SCENE)
|
||||
##
|
||||
##func _on_belt_button_pressed():
|
||||
## set_preview_mode(Mode.PLACE_BELT, BELT_SCENE)
|
||||
##
|
||||
##func _on_delete_button_pressed():
|
||||
## clear_preview()
|
||||
## current_mode = Mode.DELETE
|
||||
##
|
||||
|
||||
|
||||
func _on_belt_button_pressed() -> void:
|
||||
set_preview_mode(Mode.PLACE_BELT, BELT_SCENE)
|
||||
@@ -247,6 +247,5 @@ func _on_belt_button_pressed() -> void:
|
||||
func _on_adder_button_pressed() -> void:
|
||||
set_preview_mode(Mode.PLACE_ADDER, ADDER_SCENE)
|
||||
|
||||
|
||||
func _on_delete_button_pressed() -> void:
|
||||
set_preview_mode(Mode.DELETE, DELETE_SCENE)
|
||||
|
||||
Reference in New Issue
Block a user