Files
Corupture/scripts/autoloads/grid.gd
Eric f87b1cfa9a Changed resource spawning
added interact functionality
temp added zoom with scroll wheel
2024-02-27 10:22:28 -06:00

40 lines
1.4 KiB
GDScript

extends Node
const GRID_SIZE := 64
var world_grid: TileMap
var world_data: Dictionary = {}
func init(grid: TileMap) -> void:
world_grid = grid
func world_to_grid(world_loc: Vector2) -> Vector2i:
return Vector2i(floor(world_loc.x / GRID_SIZE), floor(world_loc.y / GRID_SIZE))
func grid_to_world_center(grid_loc: Vector2i) -> Vector2:
return Vector2((grid_loc.x + 0.5) * GRID_SIZE, (grid_loc.y + 0.5) * GRID_SIZE)
func set_selected_tile(tile: Vector2i) -> void:
world_grid.clear_layer(Constants.TilemapLayers.CURSOR)
world_grid.set_cell(Constants.TilemapLayers.CURSOR, tile,0,Vector2i(0,7))
func corrupt_location(loc: Vector2i) -> bool:
return world_data[loc].change_layer(Constants.TilemapLayers.CORRUPTION, true)
func get_corrupted_cells() -> Array[Vector2i]:
return world_data.values().filter(func(cell: CellData): return cell.is_corrupted()).map(func(cell: CellData) -> Vector2i: return cell._pos)
func change_location_data(pos: Vector2i, layer: int, data: Vector2i) -> void:
if not world_data.has(pos):
world_data[pos] = CellData.new(pos)
world_data[pos].change_layer(layer, data)
world_grid.set_cell(layer, pos, 0, data)
func get_location_data(pos: Vector2i) -> CellData:
if world_data.has(pos):
return world_data[pos]
return null
func change_location_resource(pos: Vector2i, data: GameResource) -> void:
world_data[pos].change_resource(data)
world_grid.set_cell(Constants.TilemapLayers.ENVIRONMENT, pos, 0, data.atlas_location)