Skip to content

Commit

Permalink
add support for animated winning/losing icons and refactor icons code
Browse files Browse the repository at this point in the history
  • Loading branch information
Vortex2Oblivion committed Dec 5, 2024
1 parent bca9878 commit 327849f
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 107 deletions.
6 changes: 6 additions & 0 deletions mods/Friday Night Funkin'/images/icons/bf-pixel-icons.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"scale": 1,
"offset": [0, 0],
"fps": 0,
"antialiasing": false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"scale": 1,
"offset": [0, 0],
"fps": 0,
"antialiasing": false
}
6 changes: 6 additions & 0 deletions mods/Friday Night Funkin'/images/icons/senpai-icons.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"scale": 1,
"offset": [0, 0],
"fps": 0,
"antialiasing": false
}
6 changes: 6 additions & 0 deletions mods/Friday Night Funkin'/images/icons/spirit-icons.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"scale": 1,
"offset": [0, 0],
"fps": 0,
"antialiasing": false
}
16 changes: 5 additions & 11 deletions source/states/FreeplayState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -323,11 +323,11 @@ class FreeplayState extends MusicBeatState {
if (i == lastSelectedSong)
continue;

iconArray[i].scale.set(1, 1);
iconArray[i].scale.set(iconArray[i].startSize, iconArray[i].startSize);
}

if (lastSelectedSong != -1 && iconArray[lastSelectedSong] != null)
iconArray[lastSelectedSong].scale.set(FlxMath.lerp(iconArray[lastSelectedSong].scale.x, 1, elapsed * 9),
iconArray[lastSelectedSong].scale.set(FlxMath.lerp(iconArray[lastSelectedSong].scale.x, iconArray[lastSelectedSong].startSize, elapsed * 9),
FlxMath.lerp(iconArray[lastSelectedSong].scale.y, 1, elapsed * 9));

lerpScore = Math.floor(FlxMath.lerp(lerpScore, intendedScore, 0.4));
Expand Down Expand Up @@ -566,19 +566,13 @@ class FreeplayState extends MusicBeatState {
for (i in 0...iconArray.length) {
iconArray[i].alpha = 0.6;

if (iconArray[i].animation.curAnim != null && !iconArray[i].animatedIcon)
iconArray[i].animation.curAnim.curFrame = 0;
if (iconArray[i].animation.curAnim != null)
iconArray[i].animation.play("neutral");
}

if (iconArray != null && curSelected >= 0 && (curSelected <= iconArray.length) && iconArray.length != 0) {
iconArray[curSelected].alpha = 1;
}

if (iconArray[curSelected].animation.curAnim != null && !iconArray[curSelected].animatedIcon) {
iconArray[curSelected].animation.curAnim.curFrame = 2;

if (iconArray[curSelected].animation.curAnim.curFrame != 2)
iconArray[curSelected].animation.curAnim.curFrame = 0;
iconArray[curSelected].animation.play("win");
}
}

Expand Down
46 changes: 15 additions & 31 deletions source/states/PlayState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -2021,30 +2021,17 @@ class PlayState extends MusicBeatState {
else
healthShown = health;

if (healthBar.percent < 20) {
if (!iconP1.animatedIcon)
iconP1.animation.curAnim.curFrame = 1;
if (!iconP2.animatedIcon)
iconP2.animation.curAnim.curFrame = 2;

if (iconP2.animation.curAnim.curFrame != 2 && !iconP2.animatedIcon)
iconP2.animation.curAnim.curFrame = 0;
} else {
if (!iconP1.animatedIcon)
iconP1.animation.curAnim.curFrame = 0;
if (healthBar.percent <= 20) {
iconP1.animation.play("lose");
iconP2.animation.play("win");

if (!iconP2.animatedIcon)
iconP2.animation.curAnim.curFrame = 0;
} else if(healthBar.percent >= 80) {
iconP1.animation.play("win");
iconP2.animation.play("lose");
}

if (healthBar.percent > 80) {
if (!iconP2.animatedIcon)
iconP2.animation.curAnim.curFrame = 1;
if (!iconP1.animatedIcon)
iconP1.animation.curAnim.curFrame = 2;

if (iconP1.animation.curAnim.curFrame != 2 && !iconP1.animatedIcon)
iconP1.animation.curAnim.curFrame = 0;
else{
iconP1.animation.play("neutral");
iconP2.animation.play("neutral");
}

if (!switchedStates) {
Expand Down Expand Up @@ -3579,8 +3566,8 @@ class PlayState extends MusicBeatState {
camHUD.zoom += 0.03 * cameraZoomStrength;
}

iconP1.scale.set(iconP1.scale.x + 0.2, iconP1.scale.y + 0.2);
iconP2.scale.set(iconP2.scale.x + 0.2, iconP2.scale.y + 0.2);
iconP1.scale.add(0.2, 0.2);
iconP2.scale.add(0.2, 0.2);

iconP1.updateHitbox();
iconP2.updateHitbox();
Expand Down Expand Up @@ -3953,8 +3940,8 @@ class PlayState extends MusicBeatState {
}
#end

iconP2.scale.set(1, 1);
iconP2.changeIconSet(dad.icon);
iconP2.scale.set(iconP2.startSize, iconP2.startSize);
iconP2.setupIcon(dad.icon);

healthBar.createFilledBar(dad.barColor, boyfriend.barColor);
healthBar.updateFilledBar();
Expand Down Expand Up @@ -3999,14 +3986,11 @@ class PlayState extends MusicBeatState {
#end
}

@:privateAccess
{
iconP1.scale.set(1, 1);
iconP1.changeIconSet(boyfriend.icon);
iconP1.scale.set(iconP1.startSize, iconP1.startSize);
iconP1.setupIcon(boyfriend.icon);

healthBar.createFilledBar(dad.barColor, boyfriend.barColor);
healthBar.updateFilledBar();
}
}
} else
CoolUtil.coolError("The character " + event[3] + " isn't in any character cache!\nHow did this happen? ¯|_(ツ)_|¯",
Expand Down
8 changes: 4 additions & 4 deletions source/toolbox/ChartingState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -1713,11 +1713,11 @@ class ChartingState extends MusicBeatState {
var healthIconP2:String = loadHealthIconFromCharacter(_song.player2);

if (_song.notes[curSection].mustHitSection) {
leftIcon.playSwagAnim(healthIconP1);
rightIcon.playSwagAnim(healthIconP2);
leftIcon.setupIcon(healthIconP1);
rightIcon.setupIcon(healthIconP2);
} else {
leftIcon.playSwagAnim(healthIconP2);
rightIcon.playSwagAnim(healthIconP1);
leftIcon.setupIcon(healthIconP2);
rightIcon.setupIcon(healthIconP1);
}

leftIcon.setGraphicSize(0, 45);
Expand Down
108 changes: 47 additions & 61 deletions source/ui/HealthIcon.hx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package ui;

import haxe.Json;
import lime.utils.Assets;

class HealthIcon extends TrackerSprite {
Expand All @@ -20,77 +21,62 @@ class HealthIcon extends TrackerSprite {
this.isPlayer = isPlayer;

// plays anim lol
playSwagAnim(char);
setupIcon(this.char = char);
scrollFactor.set();
}

public function playSwagAnim(?char:String = 'bf') {
changeIconSet(char);
this.char = char;
}

var selected:String;

public function changeIconSet(char:String = 'bf') {
public function setupIcon(char:String = 'placeholder') {
antialiasing = Options.getData("antialiasing");

if (Assets.exists(Paths.image('icons/' + char + '-icons').split(".png")[0] + ".xml")
|| Assets.exists(Paths.image('icons/icon-' + char).split(".png")[0] + ".xml")
|| Assets.exists(Paths.image('icons/' + char).split(".png")[0] + ".xml")) {

if (Assets.exists(Paths.image('icons/' + char + '-icons').split(".png")[0] + ".xml")) {
frames = Paths.getSparrowAtlas('icons/' + char + '-icons');
selected = Paths.image('icons/' + char + '-icons');
} else if (Assets.exists(Paths.image('icons/icon-' + char).split(".png")[0] + ".xml")) {
frames = Paths.getSparrowAtlas('icons/icon-' + char);
selected = Paths.image('icons/icon-' + char);
} else if (Assets.exists(Paths.image('icons/' + char).split(".png")[0] + ".xml")) {
frames = Paths.getSparrowAtlas('icons/' + char);
selected = Paths.image('icons/' + char);
var iconPath:String = 'placeholder-icons';
var iconConfig:HealthIconConfig = {
offset: [0, 0],
scale: 1,
fps: 24,
antialiasing: true
};
for (path in ['$char-icons', 'icon-$char', char]) {
if (Assets.exists(Paths.image('icons/$path'))) {
iconPath = path;
break;
}
}

animation.addByPrefix(char, char, 24, true, isPlayer);

if (Assets.exists(selected.split(".png")[0] + ".txt")) {
var theFunny = Assets.getText(selected.split(".png")[0] + ".txt").split(" ");

setGraphicSize(Std.int(width * Std.parseFloat(theFunny[2])));
updateHitbox();

offsetX = Std.parseFloat(theFunny[0]);
offsetY = Std.parseFloat(theFunny[1]);
}
if (Assets.exists('assets/images/icons/$iconPath.json')) {
iconConfig = cast Json.parse(Assets.getText('assets/images/icons/$iconPath.json'));
} else if (Assets.exists('assets/images/icons/$iconPath.txt')) {
var textArray:Array<String> = Assets.getText('assets/images/icons/$iconPath.txt').split(" ");
iconConfig.offset = [Std.parseFloat(textArray[0]), Std.parseFloat(textArray[1])];
iconConfig.scale = Std.parseFloat(textArray[2]);
}

animatedIcon = true;
animatedIcon = Assets.exists('assets/images/icons/$iconPath.xml');
if (animatedIcon) {
frames = Paths.getSparrowAtlas('icons/$iconPath');
animation.addByPrefix('neutral', '${char}0', iconConfig.fps, true, isPlayer);
animation.addByPrefix('lose', '${char}-lose0', iconConfig.fps, true, isPlayer);
animation.addByPrefix('win', '${char}-win0', iconConfig.fps, true, isPlayer);
} else {
if (Assets.exists(Paths.image('icons/' + char + '-icons'))) // LE ICONS
loadGraphic(Paths.gpuBitmap('icons/' + char + '-icons'));
else if (Assets.exists(Paths.image('icons/' + 'icon-' + char))) // BASE GAME ICONS
loadGraphic(Paths.gpuBitmap('icons/' + 'icon-' + char));
else if (Assets.exists(Paths.image('icons/' + char))) // just the name as file name
loadGraphic(Paths.gpuBitmap('icons/' + char));
else // UNKNOWN ICON
loadGraphic(Paths.gpuBitmap('icons/placeholder-icon'));

if (height != 150) // damn weird edge cases >:(
loadGraphic(graphic, true, Std.int(width / 2), Std.int(height));
else
loadGraphic(graphic, true, 150, 150);

animation.add(char, [0, 1, 2], 0, false, isPlayer);
loadGraphic(Paths.gpuBitmap('icons/$iconPath'), true, 150, 150);
animation.add('neutral', [0], 0, false, isPlayer);
animation.add('lose', [1], 0, false, isPlayer);
animation.add('win', [2], 0, false, isPlayer);
}
animation.play('neutral');

animation.play(char);
scale.set(iconConfig.scale, iconConfig.scale);
offsetX = iconConfig.offset[0];
offsetY = iconConfig.offset[1];
antialiasing = (iconConfig.antialiasing || !char.endsWith('-pixel'));
startSize = scale.x;

// antialiasing override
switch (char) {
case 'senpai' | 'senpai-angry' | 'spirit':
antialiasing = false;
}

if (char.endsWith('-pixel')) {
antialiasing = false;
}
updateHitbox();
centerOffsets();
centerOrigin();
}
}

typedef HealthIconConfig = {
var offset:Array<Float>;
var scale:Float;
var fps:Int;
var antialiasing:Bool;
}

0 comments on commit 327849f

Please sign in to comment.