Grid finally working and understood

This commit is contained in:
Aaron Wuthenow
2025-12-25 22:51:23 +01:00
parent 6e1a9eff35
commit f9ecb49658
21 changed files with 354 additions and 32 deletions

View File

@@ -17,23 +17,19 @@ signal moved(new_cell)
## Coordinates of the current cell the cursor is hovering.
var cell := Vector2.ZERO:
set(value):
print("Setting cell to: ", value)
# We first clamp the cell coordinates and ensure that we aren't
# trying to move outside the grid boundaries
var new_cell: Vector2 = grid.clamp(value)
print("New cell: ", new_cell)
if new_cell.is_equal_approx(cell):
return
cell = new_cell
print("Cell is ", cell)
# If we move to a new cell, we update the cursor's position, emit
# a signal, and start the cooldown timer that will limit the rate
# at which the cursor moves when we keep the direction key held
# down
# global_position = grid.calculateMapPosition(cell)
global_position = GroundLayer.map_to_local(cell)
print("Position is ", position)
emit_signal("moved", cell)
_timer.start()
@@ -54,7 +50,7 @@ func _ready() -> void:
func _unhandled_input(event: InputEvent) -> void:
# Navigating cells with the mouse.
if event is InputEventMouseMotion:
cell = grid.calculateGridCoordinates(event.position)
cell = GroundLayer.local_to_map(event.position)
# Trying to select something in a cell.
elif event.is_action_pressed("Select") or event.is_action_pressed("ui_accept"):
emit_signal("accept_pressed", cell)