Skip to content

Commit

Permalink
Merge pull request #119 from BenjaTK/invalid-layer-fix
Browse files Browse the repository at this point in the history
Check if a grid has a layer before looking it up
  • Loading branch information
BenjaTK authored Jun 5, 2024
2 parents 653cc86 + 3659eb3 commit d11edbb
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions addons/gaea/grid.gd
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ func get_value(pos, layer: int) -> Variant:

## Returns an [Array] of all values in the grid.
func get_values(layer: int) -> Array[Variant]:
if not has_layer(layer):
push_error("Index layer = %s is out of bounds (get_layer_count() = %s)" % [layer, get_layer_count()])
return []
return _grid[layer].values()


Expand All @@ -58,13 +61,20 @@ func get_grid() -> Dictionary:
### Cells ###




## Returns an [Array] of all cells in the grid.
func get_cells(layer: int) -> Array:
if not has_layer(layer):
push_error("Index layer = %s is out of bounds (get_layer_count() = %s)" % [layer, get_layer_count()])
return []
return _grid[layer].keys()


## Returns [code]true[/code] if the grid has a cell at the given position.
func has_cell(pos, layer: int) -> bool:
if not has_layer(layer):
return false
return _grid[layer].has(pos)


Expand Down

0 comments on commit d11edbb

Please sign in to comment.