Started refactoring for easier use

This commit is contained in:
awu
2025-12-26 04:10:39 +01:00
parent 6f667506c4
commit 62185f522d

View File

@@ -13,10 +13,7 @@ func _ready() -> void:
%GridDisplay.grid = astarGrid
func generateSimpleGrid() -> AStarGrid2D:
var grid = AStarGrid2D.new()
grid.cell_size = Vector2(GroundLayer.tile_set.tile_size)
grid.region = GroundLayer.get_used_rect()
grid.update()
var grid = newGrid()
for id in GroundLayer.get_used_cells():
var data: TileData = GroundLayer.get_cell_tile_data(id)
@@ -26,20 +23,31 @@ func generateSimpleGrid() -> AStarGrid2D:
return grid
func generateObstacleGrid() -> AStarGrid2D:
astarGrid = AStarGrid2D.new()
astarGrid.cell_size = Vector2(GroundLayer.tile_set.tile_size)
astarGrid.region = GroundLayer.get_used_rect()
astarGrid.update()
var grid = newGrid()
var layers = ObstacleLayer.get_children()
for layer in layers:
for id in layer.get_used_cells():
var data: TileData = layer.get_cell_tile_data(id)
if data and data.get_custom_data('obstacle'):
astarGrid.set_point_solid(id)
grid.set_point_solid(id)
return astarGrid
return grid
func newGrid() -> AStarGrid2D:
var _astarGrid = AStarGrid2D.new()
_astarGrid.default_compute_heuristic = AStarGrid2D.HEURISTIC_MANHATTAN
_astarGrid.default_estimate_heuristic = AStarGrid2D.HEURISTIC_MANHATTAN
_astarGrid.diagonal_mode = AStarGrid2D.DIAGONAL_MODE_ONLY_IF_NO_OBSTACLES
_astarGrid.cell_size = Vector2(GroundLayer.tile_set.tile_size)
_astarGrid.region = GroundLayer.get_used_rect()
_astarGrid.update()
return _astarGrid
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
pass
func getGrid():
return astarGrid