Files
Super-Mario-Bros.-Remastere…/Scripts/Parts/PlayerSprite.gd
KirbyKidJ e7ad269317 Fixed Space Title Stars and PlayerSprite Fallback Check (#619)
* Fixed Space Title Stars

Fixes the position of the title stars in the space theme

* Fixed `PlayerSprite` Fallback Check

PlayerSprites check recursively for fallbacks. However, this does mean that if one fallback links to something that was already checked, it would make an infinite loop.
Also fixes the Pipe Cutscene, and updated Mario's `Big.tres` UIDs
2025-10-18 00:26:34 +01:00

40 lines
1.4 KiB
GDScript

class_name PlayerSprite
extends AnimatedSprite2D
@export var player_id := 0
@export var force_power_state := ""
@export var force_character := ""
var character := ""
@export var resource_setter: ResourceSetterNew
func _ready() -> void:
Global.player_characters_changed.connect(update)
Global.level_theme_changed.connect(update)
animation_changed.connect(on_animation_changed)
update()
func update() -> void:
character = Player.CHARACTERS[int(Global.player_characters[player_id])]
var power_state = Global.player_power_states[player_id]
if force_power_state != "":
power_state = force_power_state
if force_character != "":
character = force_character
if resource_setter != null:
var path = "res://Assets/Sprites/Players/" + character + "/" + Player.POWER_STATES[int(power_state)] + ".json"
if Player.CHARACTERS.find(character) > 3:
path = path.replace("res://Assets/Sprites/Players/", Global.config_path.path_join("custom_characters/"))
var json = resource_setter.get_resource(load(path))
sprite_frames = json
if sprite_frames == null:
return
if sprite_frames.get_frame_texture(animation, frame):
offset.y = -(sprite_frames.get_frame_texture(animation, frame).get_height() / 2.0)
func on_animation_changed() -> void:
var fallback = animation
while not sprite_frames.has_animation(fallback) and Player.ANIMATION_FALLBACKS.has(fallback):
fallback = Player.ANIMATION_FALLBACKS[fallback]
play(fallback)