Skip to content

Commit a4a4992

Browse files
authored
Do not assume class of first node in group player (#2369)
So cinematics can assign "player" group to the mock player sprite. This makes the dialogue balloon to appear at the top of the screen when the sprite is at the bottom. ### Do not assume class of first node in group player Certain scripts could treat player as a CharacterBody2D for physics, as a Node2D for its position, or as a CanvasItem for visual stuff, etc. Input HUD: It considers the player a CharacterBody2D and checks for its components using `Object.get(COMPONENT_NAME) as COMPONENT_CLASS`. Previously it was assuming that the output of `get_first_node_in_group()` was a CharacterBody2D. The assignment would fail if the first node in group "player" is of another type. This doesn't allow mock players, for example an AnimatedSprite2D in a cinematic. Throwing enemy: All this enemy needs is the global_position of player for throwing. This makes it closer to the ThrowProjectileBehavior which has `@export var target: Node2D`. Also get the player node from group "player" only once. player_follower.gd: All this script needs is the global_position of player for calculating the offset. ---- Fix #2306
1 parent 05c160f commit a4a4992

28 files changed

Lines changed: 33 additions & 34 deletions

File tree

scenes/game_elements/characters/enemies/throwing_enemy/components/throwing_enemy.gd

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ var allowed_labels: Array[String] = ["???"]
129129
## color-matching game.
130130
var color_per_label: Dictionary[String, Color]
131131

132+
var _player: Node2D
132133
var _initial_position: Vector2
133134
var _target_position: Vector2
134135
var _is_attacking: bool
@@ -171,10 +172,10 @@ func _ready() -> void:
171172
_set_sprite_frames(sprite_frames)
172173
if Engine.is_editor_hint():
173174
return
174-
var player: Player = get_tree().get_first_node_in_group("player")
175-
if is_instance_valid(player):
175+
_player = get_tree().get_first_node_in_group("player") as Node2D
176+
if is_instance_valid(_player):
176177
var direction: Vector2 = projectile_marker.global_position.direction_to(
177-
player.global_position
178+
_player.global_position
178179
)
179180
scale.x = 1 if direction.x < 0 else -1
180181
if autostart:
@@ -261,21 +262,19 @@ func _set_target_position() -> void:
261262

262263

263264
func _on_timeout() -> void:
264-
var player: Player = get_tree().get_first_node_in_group("player")
265-
if not is_instance_valid(player):
265+
if not is_instance_valid(_player):
266266
return
267267
_is_attacking = true
268268
animation_player.play(&"attack")
269269
animation_player.queue(&"idle")
270270

271271

272272
func shoot_projectile() -> void:
273-
var player: Player = get_tree().get_first_node_in_group("player")
274273
if not allowed_labels:
275274
_is_attacking = false
276275
return
277276

278-
if shoot_projectile_at(player):
277+
if shoot_projectile_at(_player):
279278
_set_target_position()
280279
_is_attacking = false
281280

scenes/game_elements/props/player_follower/player_follower.gd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# SPDX-License-Identifier: MPL-2.0
33
extends PathFollow2D
44

5-
@onready var player: Player = get_tree().get_first_node_in_group("player")
5+
@onready var player := get_tree().get_first_node_in_group("player") as Node2D
66

77

88
func _process(_delta: float) -> void:

scenes/game_elements/props/spawn_point/components/spawn_point.gd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func _ready() -> void:
2626

2727

2828
func move_player_to_self_position(smooth_camera: bool = false) -> void:
29-
var player: Node2D = get_tree().get_first_node_in_group("player")
29+
var player := get_tree().get_first_node_in_group("player") as Node2D
3030

3131
if is_instance_valid(player):
3232
player.teleport_to(self.global_position, smooth_camera, look_at_side_on_spawn)

scenes/globals/pause/pause_overlay.gd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func _on_abandon_quest_pressed() -> void:
7272
)
7373
await Transitions.finished
7474

75-
var player: Node2D = get_tree().get_first_node_in_group("player")
75+
var player := get_tree().get_first_node_in_group("player") as Node2D
7676
var replaying := quest in GameState.global.completed_quests
7777
var title := "abandoned_replay" if replaying else "abandoned"
7878
DialogueManager.show_dialogue_balloon(abandon_dialogue, title, [player])

scenes/quests/story_quests/champ/0_intro/champ_intro.tscn

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ editor_draw_limits = true
218218
[node name="OnTheGround" type="Node2D" parent="." unique_id=1029059295]
219219
y_sort_enabled = true
220220

221-
[node name="Character" type="AnimatedSprite2D" parent="OnTheGround" unique_id=1995106097]
221+
[node name="Character" type="AnimatedSprite2D" parent="OnTheGround" unique_id=1995106097 groups=["player"]]
222222
position = Vector2(400, 349)
223223
sprite_frames = ExtResource("3_ufx21")
224224
animation = &"idle"

scenes/quests/story_quests/champ/4_outro/champ_outro.tscn

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ editor_draw_limits = true
5252
[node name="OnTheGround" type="Node2D" parent="." unique_id=484328888]
5353
y_sort_enabled = true
5454

55-
[node name="Character" type="AnimatedSprite2D" parent="OnTheGround" unique_id=34892077]
55+
[node name="Character" type="AnimatedSprite2D" parent="OnTheGround" unique_id=34892077 groups=["player"]]
5656
position = Vector2(400, 349)
5757
sprite_frames = ExtResource("3_276wt")
5858
animation = &"idle"

scenes/quests/story_quests/el_abrigo/0_el_abrigo_intro/el_abrigo_intro.tscn

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ editor_draw_limits = true
178178
[node name="OnTheGround" type="Node2D" parent="." unique_id=117602598]
179179
y_sort_enabled = true
180180

181-
[node name="Character" type="AnimatedSprite2D" parent="OnTheGround" unique_id=577377136]
181+
[node name="Character" type="AnimatedSprite2D" parent="OnTheGround" unique_id=577377136 groups=["player"]]
182182
position = Vector2(400, 349)
183183
sprite_frames = ExtResource("3_p845x")
184184
animation = &"idle"

scenes/quests/story_quests/el_abrigo/4_el_abrigo_outro/el_abrigo_outro.tscn

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ editor_draw_limits = true
8888
[node name="OnTheGround" type="Node2D" parent="." unique_id=120484108]
8989
y_sort_enabled = true
9090

91-
[node name="Character" type="AnimatedSprite2D" parent="OnTheGround" unique_id=735842756]
91+
[node name="Character" type="AnimatedSprite2D" parent="OnTheGround" unique_id=735842756 groups=["player"]]
9292
position = Vector2(400, 349)
9393
sprite_frames = ExtResource("3_7j76p")
9494
animation = &"idle"

scenes/quests/story_quests/el_juguete_perdido/0_intro/intro.tscn

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ editor_draw_limits = true
182182
[node name="OnTheGround" type="Node2D" parent="." unique_id=101635259]
183183
y_sort_enabled = true
184184

185-
[node name="Character" type="AnimatedSprite2D" parent="OnTheGround" unique_id=190991224]
185+
[node name="Character" type="AnimatedSprite2D" parent="OnTheGround" unique_id=190991224 groups=["player"]]
186186
position = Vector2(400, 349)
187187
sprite_frames = ExtResource("10_nf7lg")
188188
animation = &"idle"

scenes/quests/story_quests/el_juguete_perdido/4_outro/outro.tscn

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ editor_draw_limits = true
130130
[node name="OnTheGround" type="Node2D" parent="." unique_id=1697789778]
131131
y_sort_enabled = true
132132

133-
[node name="Character" type="AnimatedSprite2D" parent="OnTheGround" unique_id=1591226122]
133+
[node name="Character" type="AnimatedSprite2D" parent="OnTheGround" unique_id=1591226122 groups=["player"]]
134134
position = Vector2(400, 349)
135135
sprite_frames = ExtResource("12_ij0xq")
136136
animation = &"idle"

0 commit comments

Comments
 (0)