Restructure tile size usage
This commit is contained in:
@@ -45,7 +45,7 @@ func _process(_delta: float) -> void:
|
||||
if input_disabled:
|
||||
return
|
||||
var mouse_pos := get_viewport().get_canvas_transform().affine_inverse() * get_viewport().get_mouse_position()
|
||||
var coords := dl_map.world_to_coords(mouse_pos)
|
||||
var coords := BattleMapHelper.world_to_coords(mouse_pos)
|
||||
if coords != _current_grid_coords:
|
||||
_current_grid_coords = coords
|
||||
mouse_grid_changed.emit(coords)
|
||||
@@ -116,9 +116,9 @@ func _physics_process(delta: float) -> void:
|
||||
else:
|
||||
dir = Vector2(0, signf(diff.y))
|
||||
|
||||
var next_pos := _selected_unit.position + dir * dl_map.TILE_SIZE
|
||||
var grid_coords := dl_map.world_to_coords(next_pos)
|
||||
var current_coords := dl_map.world_to_coords(_selected_unit.position)
|
||||
var next_pos := _selected_unit.position + dir * BattleMapHelper.TILE_SIZE
|
||||
var grid_coords := BattleMapHelper.world_to_coords(next_pos)
|
||||
var current_coords := BattleMapHelper.world_to_coords(_selected_unit.position)
|
||||
if not dl_map.is_tile_passable(current_coords, grid_coords):
|
||||
_goal_pos = _selected_unit.position
|
||||
return
|
||||
@@ -138,8 +138,8 @@ func _handle_left_click(screen_pos: Vector2) -> void:
|
||||
_select_unit(clicked_unit)
|
||||
get_viewport().set_input_as_handled()
|
||||
elif _selected_unit:
|
||||
var snapped_pos := dl_map.snap_to_grid(world_pos)
|
||||
var grid_coords := dl_map.world_to_coords(world_pos)
|
||||
var snapped_pos := BattleMapHelper.snap_to_grid(world_pos)
|
||||
var grid_coords := BattleMapHelper.world_to_coords(world_pos)
|
||||
if not dl_map.is_tile_valid(grid_coords):
|
||||
return
|
||||
_goal_pos = snapped_pos
|
||||
@@ -157,11 +157,11 @@ func _select_unit(deployed: DeployedUnit) -> void:
|
||||
|
||||
|
||||
func _get_unit_at(world_pos: Vector2) -> DeployedUnit:
|
||||
var snapped_coords := dl_map.snap_to_grid(world_pos)
|
||||
var snapped_coords := BattleMapHelper.snap_to_grid(world_pos)
|
||||
for deployed: DeployedUnit in get_tree().get_nodes_in_group("deployed_units"):
|
||||
if not deployed.is_alive():
|
||||
continue
|
||||
var unit_snapped := dl_map.snap_to_grid(deployed.global_position)
|
||||
var unit_snapped := BattleMapHelper.snap_to_grid(deployed.global_position)
|
||||
if unit_snapped == snapped_coords:
|
||||
return deployed
|
||||
return null
|
||||
|
||||
Reference in New Issue
Block a user