Отработано удаление структур

This commit is contained in:
DIvan2000 2024-12-07 14:43:59 +04:00
parent 0e4e854cc1
commit 77973c54c6
3 changed files with 36 additions and 6 deletions

View File

@ -12,7 +12,7 @@ enum StructType {
MEDICAL_ROOM, # 8. Медицинский Модуль
GEOLOGICAL_ROOM, # 9. Геологический Модуль
RESOURCE_EXTRACTION_ROOM, # 10. Модуль Добычи и Переработки Ресурсов
COMMUNICATIONS_ROOM # 11. Модуль Связи и Навигации
COMMUNICATIONS_ROOM # 11. Модуль Связи и Навигации_
}
enum struct_fields {
@ -53,8 +53,22 @@ func get_maxZ(tile_pos: Vector2i) -> int:
return layer.z_index
return -1
func remove_struct(pos: Vector2i):
for layer in layers:
var tiledata: TileData = layer.get_cell_tile_data(pos)
if tiledata != null and tiledata.get_custom_data("is_center"):
var struct_size = tiledata.get_custom_data("struct_size")
var half_size = Vector2i(struct_size.x / 2, struct_size.y / 2)
for x in range(struct_size.x):
for y in range(struct_size.y):
var offset = Vector2i(x, y)
var tile_pos = pos+offset-half_size
layer.erase_cell(tile_pos)
return
func place_struct(pos: Vector2i, type: StructType):
#Is place free check
if not structs.has(type):
return
var struct_size = structs[type][struct_fields.SIZE]
var layer = structs[type][struct_fields.LAYER]
var source_id = structs[type][struct_fields.SOURCE_ID]
@ -62,6 +76,7 @@ func place_struct(pos: Vector2i, type: StructType):
var half_size = Vector2i(struct_size.x / 2, struct_size.y / 2)
#Is place free check
for x in range(struct_size.x):
for y in range(struct_size.y):
var offset = Vector2i(x, y)

View File

@ -4,6 +4,7 @@ extends Node2D
@onready var buildings: TileMapLayer = $TileMap/buildings/buildings0
@onready var roads: TileMapLayer = $TileMap/roads
@onready var ground: TileMapLayer = $TileMap/ground
@onready var tileMap: Node2D = $TileMap
var is_drawing_road: bool = false # Флаг для отслеживания зажатия кнопки мыши
var is_drawing_mountian: bool = false # Флаг для отслеживания зажатия кнопки мыши
@ -15,9 +16,9 @@ func _input(event):
if event is InputEventMouseButton:
# Проверяем нажатие или отпускание левой кнопки мыши
if event.button_index == MOUSE_BUTTON_LEFT:
is_drawing_road = event.pressed # Устанавливаем флаг, если кнопка нажата
tileMap.place_struct(ground.local_to_map(get_global_mouse_position()-tileMap.global_position), tileMap.StructType.EMPTY_ROOM)
elif event.button_index == MOUSE_BUTTON_RIGHT:
$TileMap.place_struct(ground.local_to_map(get_global_mouse_position()-$TileMap.global_position), $TileMap.StructType.EMPTY_ROOM)
tileMap.remove_struct(ground.local_to_map(get_global_mouse_position()-tileMap.global_position))
if event is InputEventMouseMotion and is_drawing_road:
# Получаем позицию мыши в мировых координатах

File diff suppressed because one or more lines are too long