feat: Implement cycle timer toggle, refactor continuous input, and improve movement synchronization.

This commit is contained in:
2026-01-07 05:41:38 +08:00
parent 251b677a2e
commit 6aede0a382
11 changed files with 210 additions and 58 deletions
+33 -2
View File
@@ -20,8 +20,12 @@ func initialize(p_player: Node3D, p_gridmap: Node):
if "use_diagonal_movement" in player:
use_diagonal_movement = player.use_diagonal_movement
signal movement_finished
var buffered_direction: Vector2i = Vector2i.ZERO
var current_move_direction: Vector2i = Vector2i.ZERO
func _process(delta):
if player and not is_moving:
if player:
_handle_rotation(delta)
func _handle_rotation(delta):
@@ -37,7 +41,20 @@ func rotate_towards_target(target_pos: Vector2i):
player.rpc("sync_rotation", target_rotation)
func simple_move_to(grid_position: Vector2i) -> bool:
if not player.is_multiplayer_authority() or is_moving:
if is_moving:
# Calculate direction for buffering
var direction = grid_position - player.current_position
# FIX: Only buffer if direction is DIFFERENT from current move (prevents overshoot)
# We need to know current move direction. We can infer it or store it.
# For now, let's assume if we are moving, we don't buffer same direction.
# But we need to know what the current direction is.
# Let's add a variable `current_move_direction` to the class first.
if direction != current_move_direction:
buffer_move_input(direction)
return false
if not player.is_multiplayer_authority():
return false
# Check if player is frozen
@@ -80,12 +97,26 @@ func simple_move_to(grid_position: Vector2i) -> bool:
var path = [Vector2(player.current_position.x, player.current_position.y), Vector2(grid_position.x, grid_position.y)]
path.pop_front()
current_move_direction = grid_position - player.current_position
# Use the existing RPC to move (assuming player still has this RPC or we move it here)
# For now, we'll call the player's RPC method
player.rpc("start_movement_along_path", path, not (player.is_bot or player.is_in_group("Bots")))
return true
func buffer_move_input(direction: Vector2i):
buffered_direction = direction
func _on_movement_finished():
if buffered_direction != Vector2i.ZERO:
var target = player.current_position + buffered_direction
buffered_direction = Vector2i.ZERO
simple_move_to(target)
else:
current_move_direction = Vector2i.ZERO
emit_signal("movement_finished")
func move_to_clicked_position(grid_position: Vector2i) -> bool:
if not player.is_multiplayer_authority() or is_moving or player.action_points <= 0:
return false