Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUGFIX] Default health icon (face) not used #3005

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 9 additions & 20 deletions source/funkin/play/components/HealthIcon.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>;
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.
Expand Down Expand Up @@ -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<String>, playerId:Int = 0)
{
super(0, 0);
this.playerId = playerId;
Expand All @@ -131,7 +131,7 @@ class HealthIcon extends FunkinSprite
snapToTargetSize();
}

function set_characterId(value:Null<String>):Null<String>
function set_characterId(value:Null<String>):String
{
if (value == characterId) return value;

Expand Down Expand Up @@ -412,20 +412,9 @@ class HealthIcon extends FunkinSprite
}
}

function correctCharacterId(charId:Null<String>):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
Expand All @@ -435,11 +424,11 @@ class HealthIcon extends FunkinSprite

function loadCharacter(charId:Null<String>):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);
Expand Down
Loading