Reorganized input
This commit is contained in:
@@ -1,11 +1,8 @@
|
||||
extends ColorRect
|
||||
|
||||
signal tile_hovered(coords: Vector2i)
|
||||
|
||||
@export var tile_size: float = 48.0
|
||||
|
||||
var _time: float = 0.0
|
||||
var _previous_coords := Vector2i(INF, INF)
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
@@ -17,13 +14,10 @@ func _ready() -> void:
|
||||
func _process(delta: float) -> void:
|
||||
_time += delta
|
||||
color.a = 0.25 + 0.1 * sin(_time * 4.0)
|
||||
var mouse_pos := get_global_mouse_position()
|
||||
var snapped_pos := _snap_to_grid(mouse_pos)
|
||||
global_position = snapped_pos
|
||||
var coords := Vector2i(snapped_pos / tile_size)
|
||||
if coords != _previous_coords:
|
||||
_previous_coords = coords
|
||||
tile_hovered.emit(coords)
|
||||
|
||||
|
||||
func set_grid_coords(coords: Vector2i) -> void:
|
||||
global_position = Vector2(coords) * tile_size
|
||||
|
||||
|
||||
func _notification(what: int) -> void:
|
||||
@@ -31,7 +25,3 @@ func _notification(what: int) -> void:
|
||||
hide()
|
||||
elif what == NOTIFICATION_WM_MOUSE_ENTER:
|
||||
show()
|
||||
|
||||
|
||||
func _snap_to_grid(pos: Vector2) -> Vector2:
|
||||
return Vector2(floorf(pos.x / tile_size), floorf(pos.y / tile_size)) * tile_size
|
||||
|
||||
Reference in New Issue
Block a user