@@ -30,14 +30,14 @@ signal direction_changed(new_direction: Directions.Points)
3030@export var animation_scene : PackedScene :
3131 set (value ):
3232 animation_scene = value
33-
33+
3434 if not is_inside_tree ():
3535 await ready
36-
36+
3737 if animation :
3838 animation .queue_free ()
3939 animation = null
40-
40+
4141 if animation_scene :
4242 # Check to make sure that the supplied scene instantiates as a GamepieceAnimation.
4343 var new_scene : = animation_scene .instantiate ()
@@ -48,7 +48,7 @@ signal direction_changed(new_direction: Directions.Points)
4848 new_scene .free ()
4949 animation_scene = null
5050 return
51-
51+
5252 follower .add_child (animation )
5353
5454## The gamepiece will traverse a movement path at [code]move_speed[/code] pixels per second.
@@ -64,14 +64,14 @@ var animation: GamepieceAnimation = null
6464## The [code]direction[/code] is a unit vector that points where the gamepiece is 'looking'.
6565## In the event that the gamepiece is moving along a path, direction is updated automatically as
6666## long as the gamepiece continues to move.
67- var direction : = Directions .Points .S :
67+ var direction : = Directions .Points .SOUTH :
6868 set (value ):
6969 if value != direction :
7070 direction = value
71-
71+
7272 if not is_inside_tree ():
7373 await ready
74-
74+
7575 animation .direction = direction
7676 direction_changed .emit (direction )
7777
@@ -87,33 +87,33 @@ var rest_position: = Vector2.ZERO
8787var destination : Vector2
8888
8989## Node2Ds may want to follow the gamepiece's animation, rather than position (which updates only at
90- ## the end of a path). Nodes may follow a travelling gamepiece by receiving the path follower's
90+ ## the end of a path). Nodes may follow a travelling gamepiece by receiving the path follower's
9191## transform.[/br][/br]
9292## The [member RemoteTransform2D.remote_path] is reserved for the player camera, but other nodes
9393## may access the anchor's position directly.
9494@onready var animation_transform : = $ PathFollow2D/CameraAnchor as RemoteTransform2D
9595
9696# The following objects allow the gamepiece to appear to move smoothly around the gameboard.
9797# Please note that the path is decoupled from the gamepiece's position (scale is set to match
98- # the gamepiece in _ready(), however) in order to simplify path management. All path coordinates may
99- # be provided in game-world coordinates and will remain relative to the origin even as the
98+ # the gamepiece in _ready(), however) in order to simplify path management. All path coordinates may
99+ # be provided in game-world coordinates and will remain relative to the origin even as the
100100# gamepiece's position changes.
101101@onready var follower : = $ PathFollow2D as PathFollow2D
102102
103103
104104func _ready () -> void :
105105 set_process (false )
106-
106+
107107 if not Engine .is_editor_hint () and is_inside_tree ():
108108 # Some gamepieces may be added to the scene before the Gameboard properties are set. In that
109109 # case, wait for Gameboard dimensions to be set before registering the gamepiece.
110110 if Gameboard .properties == null :
111111 await Gameboard .properties_set
112-
112+
113113 # Snap the gamepiece to the cell on which it is standing.
114114 var cell : = Gameboard .get_cell_under_node (self )
115115 position = Gameboard .cell_to_pixel (cell )
116-
116+
117117 # Then register the gamepiece with the registry. Note that if a gamepiece already exists at
118118 # the cell, this one will simply be freed.
119119 if GamepieceRegistry .register (self , cell ) == false :
@@ -123,27 +123,27 @@ func _ready() -> void:
123123func _process (delta : float ) -> void :
124124 # How far will the gamepiece move this frame?
125125 var move_distance : = move_speed * delta
126-
126+
127127 # We need to let others know that the gamepiece will arrive at the end of its path THIS frame.
128128 # A controller may want to extend the path (for example, if a move key is held down or if
129129 # another waypoint should be added to the move path).
130130 # If we do NOT do so and the path is extended post arrival, there will be a single frame where
131- # the gamepiece's velocity is discontinuous (drops, then increases again), causing jittery
131+ # the gamepiece's velocity is discontinuous (drops, then increases again), causing jittery
132132 # movement.
133133 # The excess travel distance allows us to know how much to extend the path by. A VERY fast
134134 # gamepiece may jump a few cells at a time.
135135 var excess_travel_distance : = follower .progress + move_distance - curve .get_baked_length ()
136136 if excess_travel_distance >= 0.0 :
137137 arriving .emit (excess_travel_distance )
138-
138+
139139 # The path may have been extended, so the gamepiece can move along the path now.
140140 follower .progress += move_distance
141-
141+
142142 # Figure out which direction the gamepiece is facing, making sure that the GamepieceAnimation
143143 # scene doesn't rotate.
144144 animation .global_rotation = 0
145145 direction = Directions .angle_to_direction (follower .rotation )
146-
146+
147147 # If the gamepiece has arrived, update it's position and movement details.
148148 if follower .progress >= curve .get_baked_length ():
149149 stop ()
@@ -155,16 +155,16 @@ func _process(delta: float) -> void:
155155## Note that the Gamepiece's position will remain fixed until it has fully traveresed its movement
156156## path. At this point, its position is then updated to its destination.
157157func move_to (target_point : Vector2 ) -> void :
158- # Note that the destination is where the gamepiece will end up in game world coordinates.
158+ # Note that the destination is where the gamepiece will end up in game world coordinates.
159159 destination = target_point
160160 set_process (true )
161-
161+
162162 if curve == null :
163163 curve = Curve2D .new ()
164164 curve .add_point (Vector2 .ZERO )
165-
165+
166166 animation .play ("run" )
167-
167+
168168 # The positions on the path, however, are all relative to the gamepiece's current position. The
169169 # position doesn't update until the Gamepiece reaches its final destination, otherwise the path
170170 # would move along with the gamepiece.
@@ -178,11 +178,11 @@ func stop() -> void:
178178 follower .progress = 0
179179 curve = null
180180 destination = Vector2 .ZERO
181-
181+
182182 # Handle the change to animation.
183183 animation .global_rotation = 0
184184 animation .play ("idle" )
185-
185+
186186 # Stop movement and update logic.
187187 set_process (false )
188188 arrived .emit ()
0 commit comments