Grid wip
This commit is contained in:
parent
f816a8b886
commit
090de86455
14 changed files with 294 additions and 12 deletions
29
systems/grid_highlighter.gd
Normal file
29
systems/grid_highlighter.gd
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
extends Node2D
|
||||
|
||||
@onready var grid: Grid = get_parent()
|
||||
|
||||
const UNIT_COLOR = Color.CHOCOLATE
|
||||
const EMPTY_COLOR = Color(Color.CORNFLOWER_BLUE,1.0)
|
||||
|
||||
var units: Array[Vector2]
|
||||
var empty: Array[Vector2]
|
||||
|
||||
func _ready() -> void:
|
||||
GameplaySignalBus.highlight_empty.connect(on_highlight_empty)
|
||||
GameplaySignalBus.highlight_units.connect(on_highlight_units)
|
||||
|
||||
func _draw() -> void:
|
||||
for unit in units:
|
||||
draw_rect(Rect2(unit,grid.cell_size),UNIT_COLOR)
|
||||
for empty_cell in empty:
|
||||
draw_rect(Rect2(empty_cell,grid.cell_size),EMPTY_COLOR)
|
||||
|
||||
func on_highlight_units(new_units: Array[Unit]):
|
||||
units.clear()
|
||||
units.assign(new_units.map(func(unit : Unit): return grid.snap_position(unit.global_position)))
|
||||
queue_redraw()
|
||||
|
||||
func on_highlight_empty(new_empty: Array[int]):
|
||||
empty.clear()
|
||||
empty.assign(new_empty.map(func(cell: int): return grid.from_index(cell)))
|
||||
queue_redraw()
|
||||
Loading…
Add table
Add a link
Reference in a new issue