updating unit movement
This commit is contained in:
@@ -498,9 +498,9 @@ func _on_tile_action_requested(q: int, r: int, _terrain: String, screen_position
|
||||
if coordinate_label:
|
||||
coordinate_label.text = "Archers can only move to an adjacent tile."
|
||||
return
|
||||
if not grid_view.is_visible_non_rival_tile(q, r):
|
||||
if not grid_view.is_visible_tile(q, r):
|
||||
if coordinate_label:
|
||||
coordinate_label.text = "Archers can only move to visible non-rival tiles."
|
||||
coordinate_label.text = "Archers can only move to visible tiles."
|
||||
return
|
||||
|
||||
pending_move_q = q
|
||||
@@ -1037,8 +1037,8 @@ func _move_selected_archers(to_q: int, to_r: int) -> void:
|
||||
if not grid_view.is_neighbor(selected_archer_q, selected_archer_r, to_q, to_r):
|
||||
coordinate_label.text = "Archers can only move to an adjacent tile."
|
||||
return
|
||||
if not grid_view.is_visible_non_rival_tile(to_q, to_r):
|
||||
coordinate_label.text = "Archers can only move to visible non-rival tiles."
|
||||
if not grid_view.is_visible_tile(to_q, to_r):
|
||||
coordinate_label.text = "Archers can only move to visible tiles."
|
||||
return
|
||||
|
||||
var access_token: String = str(session.get("accessToken", ""))
|
||||
|
||||
@@ -75,7 +75,8 @@ func _gui_input(event: InputEvent) -> void:
|
||||
if event.pressed:
|
||||
drag_distance = 0.0
|
||||
if not event.pressed and drag_distance < 6.0 and hovered_tile.x != 9999:
|
||||
selected_tile = hovered_tile
|
||||
var clicked_unit_tile := _archer_tile_at(event.position)
|
||||
selected_tile = clicked_unit_tile if clicked_unit_tile.x != 9999 else hovered_tile
|
||||
var data: Dictionary = _tile_data(selected_tile.x, selected_tile.y)
|
||||
var key: String = _tile_key(selected_tile.x, selected_tile.y)
|
||||
var label: String = _tile_display_label(key, data) if visible_tiles.has(key) else "Unexplored"
|
||||
@@ -442,7 +443,7 @@ func _draw_building_marker(center: Vector2, height: float) -> void:
|
||||
|
||||
|
||||
func _draw_archer_unit_marker(center: Vector2, height: float, count: int) -> void:
|
||||
var marker_center: Vector2 = center + Vector2(18.0 * zoom, -height * zoom - 14.0 * zoom)
|
||||
var marker_center: Vector2 = _archer_marker_center(center, height)
|
||||
var marker_scale: float = zoom
|
||||
var cloak_color := Color(0.20, 0.38, 0.26)
|
||||
var hood_color := Color(0.12, 0.23, 0.16)
|
||||
@@ -487,6 +488,31 @@ func _draw_archer_unit_marker(center: Vector2, height: float, count: int) -> voi
|
||||
draw_string(font, badge_rect.position + Vector2(3.5, 9.0) * marker_scale, count_text, HORIZONTAL_ALIGNMENT_LEFT, -1, badge_font_size, Color(0.93, 0.86, 0.58))
|
||||
|
||||
|
||||
func _archer_marker_center(center: Vector2, height: float) -> Vector2:
|
||||
return center + Vector2(18.0 * zoom, -height * zoom - 14.0 * zoom)
|
||||
|
||||
|
||||
func _archer_tile_at(mouse_position: Vector2) -> Vector2i:
|
||||
var closest := Vector2i(9999, 9999)
|
||||
var closest_distance := 999999.0
|
||||
for tile in tiles:
|
||||
var q: int = int(tile["q"])
|
||||
var r: int = int(tile["r"])
|
||||
if _archer_count_at(q, r) <= 0:
|
||||
continue
|
||||
|
||||
var center: Vector2 = _tile_center(q, r)
|
||||
var height: float = float(tile["height"])
|
||||
var distance: float = _archer_marker_center(center, height).distance_to(mouse_position)
|
||||
if distance < closest_distance:
|
||||
closest_distance = distance
|
||||
closest = Vector2i(q, r)
|
||||
|
||||
if closest_distance > 26.0 * zoom:
|
||||
return Vector2i(9999, 9999)
|
||||
return closest
|
||||
|
||||
|
||||
func _tile_data(q: int, r: int) -> Dictionary:
|
||||
for tile in tiles:
|
||||
if int(tile["q"]) == q and int(tile["r"]) == r:
|
||||
@@ -583,6 +609,10 @@ func is_visible_non_rival_tile(q: int, r: int) -> bool:
|
||||
return visible_tiles.has(key) and not rival_tiles.has(key)
|
||||
|
||||
|
||||
func is_visible_tile(q: int, r: int) -> bool:
|
||||
return visible_tiles.has(_tile_key(q, r))
|
||||
|
||||
|
||||
func _tile_key(q: int, r: int) -> String:
|
||||
return "%d,%d" % [q, r]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user