1
0
Fork 0
mirror of https://github.com/ninjamuffin99/Funkin.git synced 2025-09-04 04:38:09 +00:00
Funkin/source/funkin/ui/freeplay/FreeplayScore.hx

136 lines
3 KiB
Haxe
Raw Permalink Normal View History

package funkin.ui.freeplay;
2021-12-06 05:13:11 +00:00
import flixel.FlxSprite;
import flixel.group.FlxSpriteGroup.FlxTypedSpriteGroup;
2025-05-20 08:13:08 +00:00
@:nullSafety
2021-12-06 05:13:11 +00:00
class FreeplayScore extends FlxTypedSpriteGroup<ScoreNum>
{
public var scoreShit(default, set):Int = 0;
function set_scoreShit(val):Int
{
if (group == null || group.members == null) return val;
var dumbNumb:Int = Std.parseInt(Std.string(val)) ?? 0;
2024-10-10 17:21:51 +00:00
dumbNumb = Std.int(Math.min(dumbNumb, Math.pow(10, group.members.length) - 1));
var loopNum:Int = group.members.length - 1;
while (dumbNumb > 0)
{
group.members[loopNum].digit = dumbNumb % 10;
dumbNumb = Math.floor(dumbNumb / 10);
loopNum--;
}
while (loopNum >= 0)
{
group.members[loopNum].digit = 0;
loopNum--;
}
return val;
}
2024-08-29 23:58:19 +00:00
public function new(x:Float, y:Float, digitCount:Int, scoreShit:Int = 100, ?styleData:FreeplayStyle)
{
super(0, y);
2024-04-03 08:52:12 +00:00
for (i in 0...digitCount)
{
2024-08-29 23:58:19 +00:00
if (styleData == null)
{
add(new ScoreNum(x + (45 * i), y, 0));
}
else
{
add(new ScoreNum(x + (45 * i), y, 0, styleData));
}
}
this.scoreShit = scoreShit;
}
public function updateScore(scoreNew:Int)
{
scoreShit = scoreNew;
}
2021-12-06 05:13:11 +00:00
}
/**
* ScoreNum is the number graphic that is used for the completion percentage.
* It handles offsetting / positioning of the numbers so they look a bit nicer placed
* NOTE: this is actually a bit similar to the ResultScore class, should perhaps tidy the logic up?
*/
2025-05-20 08:13:08 +00:00
@:nullSafety
2021-12-06 05:13:11 +00:00
class ScoreNum extends FlxSprite
{
public var digit(default, set):Int = 0;
function set_digit(val):Int
{
if (animation.curAnim != null && animation.curAnim.name != numToString[val])
{
animation.play(numToString[val], true, false, 0);
updateHitbox();
switch (val)
{
case 1:
offset.x -= 15;
case 5:
2024-08-29 23:58:19 +00:00
// set offsets
// offset.x += 0;
// offset.y += 10;
case 7:
2024-08-29 23:58:19 +00:00
// offset.y += 6;
case 4:
2024-08-29 23:58:19 +00:00
// offset.y += 5;
case 9:
2024-08-29 23:58:19 +00:00
// offset.y += 5;
default:
centerOffsets(false);
}
}
return val;
}
2024-08-29 23:58:19 +00:00
public function new(x:Float, y:Float, ?initDigit:Int = 0, ?styleData:FreeplayStyle)
{
super(x, y);
2024-08-29 23:58:19 +00:00
if (styleData == null)
{
frames = Paths.getSparrowAtlas('digital_numbers');
}
else
{
frames = Paths.getSparrowAtlas(styleData.getNumbersAssetKey());
}
for (i in 0...10)
{
animation.addByPrefix(getIntToString(i), '${getIntToString(i)} DIGITAL', 24, false);
}
2025-05-20 08:13:08 +00:00
this.digit = initDigit ?? 0;
animation.play(getIntToString(digit), true);
setGraphicSize(Std.int(width * 0.4));
updateHitbox();
}
final numToString:Array<String> = ["ZERO", "ONE", "TWO", "THREE", "FOUR", "FIVE", "SIX", "SEVEN", "EIGHT", "NINE"];
function getIntToString(number:Int):String
{
if (numToString[number] == null) return numToString[0];
return numToString[number];
}
2021-12-06 05:13:11 +00:00
}