From 2fb55ba3edf4e84a46dc6e451922af0a2ca63326 Mon Sep 17 00:00:00 2001 From: gamerbross <55158797+gamerbross@users.noreply.github.com> Date: Thu, 11 Jul 2024 06:59:22 +0200 Subject: [PATCH] Fix default health icon not used --- source/funkin/play/components/HealthIcon.hx | 29 +++++++-------------- 1 file changed, 9 insertions(+), 20 deletions(-) diff --git a/source/funkin/play/components/HealthIcon.hx b/source/funkin/play/components/HealthIcon.hx index 2442b0dc5..682334db3 100644 --- a/source/funkin/play/components/HealthIcon.hx +++ b/source/funkin/play/components/HealthIcon.hx @@ -33,7 +33,7 @@ class HealthIcon extends FunkinSprite * The character this icon is representing. * Setting this variable will automatically update the graphic. */ - public var characterId(default, set):Null; + public var characterId(default, set):String = Constants.DEFAULT_HEALTH_ICON; /** * Whether this health icon should automatically update its state based on the character's health. @@ -116,7 +116,7 @@ class HealthIcon extends FunkinSprite */ static final POSITION_OFFSET:Int = 26; - public function new(char:String = 'bf', playerId:Int = 0) + public function new(char:Null, playerId:Int = 0) { super(0, 0); this.playerId = playerId; @@ -127,7 +127,7 @@ class HealthIcon extends FunkinSprite initTargetSize(); } - function set_characterId(value:Null):Null + function set_characterId(value:Null):String { if (value == characterId) return value; @@ -380,20 +380,9 @@ class HealthIcon extends FunkinSprite } } - function correctCharacterId(charId:Null):String + function iconExists(charId:String):Bool { - if (charId == null) - { - return Constants.DEFAULT_HEALTH_ICON; - } - - if (!Assets.exists(Paths.image('icons/icon-$charId'))) - { - FlxG.log.warn('No icon for character: $charId : using default placeholder face instead!'); - return Constants.DEFAULT_HEALTH_ICON; - } - - return charId; + return Assets.exists(Paths.image('icons/icon-$charId')); } function isNewSpritesheet(charId:String):Bool @@ -403,11 +392,11 @@ class HealthIcon extends FunkinSprite function loadCharacter(charId:Null):Void { - if (charId == null || correctCharacterId(charId) != charId) + if (charId == null || !iconExists(charId)) { - // This will recursively trigger loadCharacter to be called again. - characterId = correctCharacterId(charId); - return; + FlxG.log.warn('No icon for character: $charId : using default placeholder face instead!'); + characterId = Constants.DEFAULT_HEALTH_ICON; + charId = characterId; } isLegacyStyle = !isNewSpritesheet(charId);