1
0
Fork 0
mirror of https://github.com/ninjamuffin99/Funkin.git synced 2024-11-15 11:22:55 +00:00

goodbye scripts, hello notestyles!

This commit is contained in:
anysad 2024-07-16 20:53:12 +03:00 committed by EliteMasterEric
parent d5a53855d3
commit d3209e57b7
4 changed files with 131 additions and 93 deletions

View file

@ -12,6 +12,8 @@ import flixel.util.FlxTimer;
import funkin.util.EaseUtil;
import funkin.audio.FunkinSound;
import openfl.utils.Assets;
import funkin.data.notestyle.NoteStyleRegistry;
import funkin.play.notes.notestyle.NoteStyle;
class Countdown
{
@ -21,9 +23,9 @@ class Countdown
public static var countdownStep(default, null):CountdownStep = BEFORE;
/**
* Which alternate countdown sound effect to use.
* You can set this via script.
* For example, in Week 6 it is `-pixel`.
* Which alternate graphic/sound on countdown to use.
* This is set via the current notestyle.
* For example, in Week 6 it is `pixel`.
*/
public static var soundSuffix:String = '';
@ -34,6 +36,10 @@ class Countdown
*/
public static var graphicSuffix:String = '';
static var noteStyle:NoteStyle;
static var isPixel:Bool = false;
/**
* The currently running countdown. This will be null if there is no countdown running.
*/
@ -63,6 +69,12 @@ class Countdown
// @:privateAccess
// PlayState.instance.dispatchEvent(new SongTimeScriptEvent(SONG_BEAT_HIT, 0, 0));
var fetchedNoteStyle:NoteStyle = NoteStyleRegistry.instance.fetchEntry(PlayState.instance.currentChart.noteStyle);
if (fetchedNoteStyle == null) noteStyle = NoteStyleRegistry.instance.fetchDefault();
else
noteStyle = fetchedNoteStyle;
if (noteStyle._data.assets.note.isPixel) isPixel = true;
// The timer function gets called based on the beat of the song.
countdownTimer = new FlxTimer();
@ -80,10 +92,10 @@ class Countdown
// PlayState.instance.dispatchEvent(new SongTimeScriptEvent(SONG_BEAT_HIT, 0, 0));
// Countdown graphic.
showCountdownGraphic(countdownStep, graphicSuffix.toLowerCase().contains('pixel'));
showCountdownGraphic(countdownStep, noteStyle, isPixel);
// Countdown sound.
playCountdownSound(countdownStep);
playCountdownSound(countdownStep, noteStyle);
// Event handling bullshit.
var cancelled:Bool = propagateCountdownEvent(countdownStep);
@ -196,17 +208,31 @@ class Countdown
*/
public static function reset()
{
soundSuffix = '';
graphicSuffix = '';
noteStyle = NoteStyleRegistry.instance.fetchDefault();
isPixel = false;
}
/**
* Retrieves the graphic to use for this step of the countdown.
*/
public static function showCountdownGraphic(index:CountdownStep, isGraphicPixel:Bool):Void
public static function showCountdownGraphic(index:CountdownStep, noteStyle:NoteStyle, isGraphicPixel:Bool):Void
{
var indexString:String = null;
switch (index)
{
case TWO:
indexString = 'ready';
case ONE:
indexString = 'set';
case GO:
indexString = 'go';
default:
// null
}
if (indexString == null) return;
var spritePath:String = null;
spritePath = resolveGraphicPath(graphicSuffix, index);
spritePath = resolveGraphicPath(noteStyle, indexString);
if (spritePath == null) return;
@ -214,6 +240,8 @@ class Countdown
countdownSprite.scrollFactor.set(0, 0);
if (isGraphicPixel) countdownSprite.setGraphicSize(Std.int(countdownSprite.width * Constants.PIXEL_ART_SCALE));
else
countdownSprite.setGraphicSize(Std.int(countdownSprite.width * 0.7));
var fadeEase = FlxEase.cubeInOut;
if (isGraphicPixel) fadeEase = EaseUtil.stepped(8);
@ -223,6 +251,8 @@ class Countdown
countdownSprite.updateHitbox();
countdownSprite.screenCenter();
countdownSprite.cameras = [PlayState.instance.camHUD];
// Fade sprite in, then out, then destroy it.
FlxTween.tween(countdownSprite, {y: countdownSprite.y += 100}, Conductor.instance.beatLengthMs / 1000,
{
@ -240,29 +270,19 @@ class Countdown
PlayState.instance.add(countdownSprite);
}
static function resolveGraphicPath(suffix:String, index:CountdownStep):Null<String>
static function resolveGraphicPath(noteStyle:NoteStyle, index:String):Null<String>
{
var basePath:String = 'ui/countdown/';
var indexString:String = null;
switch (index)
var spritePath:String = basePath + noteStyle.id + '/$index';
// If nothing is found, revert it to default notestyle skin
if (!Assets.exists(Paths.image(spritePath)))
{
case TWO:
indexString = 'ready';
case ONE:
indexString = 'set';
case GO:
indexString = 'go';
default:
// null
if (!isPixel) spritePath = basePath + Constants.DEFAULT_NOTE_STYLE + '/$index';
else
spritePath = basePath + Constants.DEFAULT_PIXEL_NOTE_STYLE + '/$index';
}
basePath += indexString;
var spritePath:String = basePath + suffix;
while (!Assets.exists(Paths.image(spritePath)) && suffix.length > 0)
{
suffix = suffix.split('-').slice(0, -1).join('-');
spritePath = basePath + suffix;
}
if (!Assets.exists(Paths.image(spritePath))) return null;
trace('Resolved sprite path: ' + Paths.image(spritePath));
return spritePath;
}
@ -270,23 +290,25 @@ class Countdown
/**
* Retrieves the sound file to use for this step of the countdown.
*/
public static function playCountdownSound(index:CountdownStep):Void
public static function playCountdownSound(step:CountdownStep, noteStyle:NoteStyle):Void
{
FunkinSound.playOnce(resolveSoundPath(soundSuffix, index), Constants.COUNTDOWN_VOLUME);
return FunkinSound.playOnce(Paths.sound(resolveSoundPath(noteStyle, step)), Constants.COUNTDOWN_VOLUME);
}
static function resolveSoundPath(suffix:String, step:CountdownStep):Null<String>
static function resolveSoundPath(noteStyle:NoteStyle, step:CountdownStep):Null<String>
{
var basePath:String = 'gameplay/countdown/intro';
if (step != CountdownStep.BEFORE || step != CountdownStep.AFTER) basePath += step;
if (step == CountdownStep.BEFORE || step == CountdownStep.AFTER) return null;
var basePath:String = 'gameplay/countdown/';
var soundPath:String = Paths.sound(basePath + suffix);
while (!Assets.exists(soundPath) && suffix.length > 0)
var soundPath:String = basePath + noteStyle.id + '/intro$step';
// If nothing is found, revert it to default notestyle sound
if (!Assets.exists(Paths.sound(soundPath)))
{
suffix = suffix.split('-').slice(0, -1).join('-');
soundPath = Paths.sound(basePath + suffix);
if (!isPixel) soundPath = basePath + Constants.DEFAULT_NOTE_STYLE + '/intro$step';
else
soundPath = basePath + Constants.DEFAULT_PIXEL_NOTE_STYLE + '/intro$step';
}
if (!Assets.exists(soundPath)) return null;
trace('Resolved sound path: ' + soundPath);
return soundPath;
}

View file

@ -9,6 +9,8 @@ import funkin.play.PlayState;
import funkin.util.TimerUtil;
import funkin.util.EaseUtil;
import openfl.utils.Assets;
import funkin.data.notestyle.NoteStyleRegistry;
import funkin.play.notes.notestyle.NoteStyle;
class PopUpStuff extends FlxTypedGroup<FunkinSprite>
{
@ -16,30 +18,37 @@ class PopUpStuff extends FlxTypedGroup<FunkinSprite>
/**
* Which alternate graphic on popup to use.
* You can set this via script.
* For example, in Week 6 it is `-pixel`.
* This is set via the current notestyle.
* For example, in Week 6 it is `pixel`.
*/
public static var graphicSuffix:String = '';
static var noteStyle:NoteStyle;
static var isPixel:Bool = false;
override public function new()
{
super();
var fetchedNoteStyle:NoteStyle = NoteStyleRegistry.instance.fetchEntry(PlayState.instance.currentChart.noteStyle);
if (fetchedNoteStyle == null) noteStyle = NoteStyleRegistry.instance.fetchDefault();
else
noteStyle = fetchedNoteStyle;
if (noteStyle._data.assets.note.isPixel) isPixel = true;
}
static function resolveGraphicPath(suffix:String, index:String):Null<String>
static function resolveGraphicPath(noteStyle:NoteStyle, index:String):Null<String>
{
var folder:String;
if (suffix != '') folder = suffix.substring(0, suffix.indexOf("-")) + suffix.substring(suffix.indexOf("-") + 1);
else
folder = 'normal';
var basePath:String = 'gameplay/popup/$folder/$index';
var spritePath:String = basePath + suffix;
while (!Assets.exists(Paths.image(spritePath)) && suffix.length > 0)
var basePath:String = 'ui/popup/';
var spritePath:String = basePath + noteStyle.id + '/$index';
// If nothing is found, revert it to default notestyle skin
if (!Assets.exists(Paths.image(spritePath)))
{
suffix = suffix.split('-').slice(0, -1).join('-');
spritePath = basePath + suffix;
if (!isPixel) spritePath = basePath + Constants.DEFAULT_NOTE_STYLE + '/$index';
else
spritePath = basePath + Constants.DEFAULT_PIXEL_NOTE_STYLE + '/$index';
}
if (!Assets.exists(Paths.image(spritePath))) return null;
return spritePath;
}
@ -49,7 +58,7 @@ class PopUpStuff extends FlxTypedGroup<FunkinSprite>
if (daRating == null) daRating = "good";
var ratingPath:String = resolveGraphicPath(graphicSuffix, daRating);
var ratingPath:String = resolveGraphicPath(noteStyle, daRating);
// if (PlayState.instance.currentStageId.startsWith('school')) ratingPath = "weeb/pixelUI/" + ratingPath + "-pixel";
@ -68,7 +77,7 @@ class PopUpStuff extends FlxTypedGroup<FunkinSprite>
var fadeEase = null;
if (graphicSuffix.toLowerCase().contains('pixel'))
if (isPixel)
{
rating.setGraphicSize(Std.int(rating.width * Constants.PIXEL_ART_SCALE * 0.7));
rating.antialiasing = false;
@ -105,7 +114,7 @@ class PopUpStuff extends FlxTypedGroup<FunkinSprite>
if (combo == null) combo = 0;
var comboPath:String = resolveGraphicPath(graphicSuffix, Std.string(combo));
var comboPath:String = resolveGraphicPath(noteStyle, 'combo');
var comboSpr:FunkinSprite = FunkinSprite.create(comboPath);
comboSpr.y = (FlxG.camera.height * 0.44) + offsets[1];
comboSpr.x = (FlxG.width * 0.507) + offsets[0];
@ -160,7 +169,7 @@ class PopUpStuff extends FlxTypedGroup<FunkinSprite>
var daLoop:Int = 1;
for (i in seperatedScore)
{
var numScore:FunkinSprite = FunkinSprite.create(0, comboSpr.y, resolveGraphicPath(graphicSuffix, 'num' + Std.int(i)));
var numScore:FunkinSprite = FunkinSprite.create(0, comboSpr.y, resolveGraphicPath(noteStyle, 'num' + Std.int(i)));
if (graphicSuffix.toLowerCase().contains('pixel'))
{
@ -206,6 +215,7 @@ class PopUpStuff extends FlxTypedGroup<FunkinSprite>
*/
public static function reset()
{
graphicSuffix = '';
noteStyle = NoteStyleRegistry.instance.fetchDefault();
isPixel = false;
}
}

View file

@ -291,46 +291,47 @@ class LoadingState extends MusicBeatSubState
FunkinSprite.preparePurgeCache();
FunkinSprite.cacheTexture(Paths.image('healthBar'));
FunkinSprite.cacheTexture(Paths.image('menuDesat'));
FunkinSprite.cacheTexture(Paths.image('gameplay/popup/normal/combo'));
FunkinSprite.cacheTexture(Paths.image('gameplay/popup/normal/num0'));
FunkinSprite.cacheTexture(Paths.image('gameplay/popup/normal/num1'));
FunkinSprite.cacheTexture(Paths.image('gameplay/popup/normal/num2'));
FunkinSprite.cacheTexture(Paths.image('gameplay/popup/normal/num3'));
FunkinSprite.cacheTexture(Paths.image('gameplay/popup/normal/num4'));
FunkinSprite.cacheTexture(Paths.image('gameplay/popup/normal/num5'));
FunkinSprite.cacheTexture(Paths.image('gameplay/popup/normal/num6'));
FunkinSprite.cacheTexture(Paths.image('gameplay/popup/normal/num7'));
FunkinSprite.cacheTexture(Paths.image('gameplay/popup/normal/num8'));
FunkinSprite.cacheTexture(Paths.image('gameplay/popup/normal/num9'));
FunkinSprite.cacheTexture(Paths.image('gameplay/popup/pixel/combo-pixel'));
FunkinSprite.cacheTexture(Paths.image('gameplay/popup/pixel/num0-pixel'));
FunkinSprite.cacheTexture(Paths.image('gameplay/popup/pixel/num1-pixel'));
FunkinSprite.cacheTexture(Paths.image('gameplay/popup/pixel/num2-pixel'));
FunkinSprite.cacheTexture(Paths.image('gameplay/popup/pixel/num3-pixel'));
FunkinSprite.cacheTexture(Paths.image('gameplay/popup/pixel/num4-pixel'));
FunkinSprite.cacheTexture(Paths.image('gameplay/popup/pixel/num5-pixel'));
FunkinSprite.cacheTexture(Paths.image('gameplay/popup/pixel/num6-pixel'));
FunkinSprite.cacheTexture(Paths.image('gameplay/popup/pixel/num7-pixel'));
FunkinSprite.cacheTexture(Paths.image('gameplay/popup/pixel/num8-pixel'));
FunkinSprite.cacheTexture(Paths.image('gameplay/popup/pixel/num9-pixel'));
// Lord have mercy on me and this caching -anysad
FunkinSprite.cacheTexture(Paths.image('ui/popup/funkin/combo'));
FunkinSprite.cacheTexture(Paths.image('ui/popup/funkin/num0'));
FunkinSprite.cacheTexture(Paths.image('ui/popup/funkin/num1'));
FunkinSprite.cacheTexture(Paths.image('ui/popup/funkin/num2'));
FunkinSprite.cacheTexture(Paths.image('ui/popup/funkin/num3'));
FunkinSprite.cacheTexture(Paths.image('ui/popup/funkin/num4'));
FunkinSprite.cacheTexture(Paths.image('ui/popup/funkin/num5'));
FunkinSprite.cacheTexture(Paths.image('ui/popup/funkin/num6'));
FunkinSprite.cacheTexture(Paths.image('ui/popup/funkin/num7'));
FunkinSprite.cacheTexture(Paths.image('ui/popup/funkin/num8'));
FunkinSprite.cacheTexture(Paths.image('ui/popup/funkin/num9'));
FunkinSprite.cacheTexture(Paths.image('ui/popup/pixel/combo'));
FunkinSprite.cacheTexture(Paths.image('ui/popup/pixel/num0'));
FunkinSprite.cacheTexture(Paths.image('ui/popup/pixel/num1'));
FunkinSprite.cacheTexture(Paths.image('ui/popup/pixel/num2'));
FunkinSprite.cacheTexture(Paths.image('ui/popup/pixel/num3'));
FunkinSprite.cacheTexture(Paths.image('ui/popup/pixel/num4'));
FunkinSprite.cacheTexture(Paths.image('ui/popup/pixel/num5'));
FunkinSprite.cacheTexture(Paths.image('ui/popup/pixel/num6'));
FunkinSprite.cacheTexture(Paths.image('ui/popup/pixel/num7'));
FunkinSprite.cacheTexture(Paths.image('ui/popup/pixel/num8'));
FunkinSprite.cacheTexture(Paths.image('ui/popup/pixel/num9'));
FunkinSprite.cacheTexture(Paths.image('notes', 'shared'));
FunkinSprite.cacheTexture(Paths.image('noteSplashes', 'shared'));
FunkinSprite.cacheTexture(Paths.image('noteStrumline', 'shared'));
FunkinSprite.cacheTexture(Paths.image('NOTE_hold_assets'));
FunkinSprite.cacheTexture(Paths.image('ui/countdown/ready', 'shared'));
FunkinSprite.cacheTexture(Paths.image('ui/countdown/set', 'shared'));
FunkinSprite.cacheTexture(Paths.image('ui/countdown/go', 'shared'));
FunkinSprite.cacheTexture(Paths.image('ui/countdown/ready-pixel', 'shared'));
FunkinSprite.cacheTexture(Paths.image('ui/countdown/set-pixel', 'shared'));
FunkinSprite.cacheTexture(Paths.image('ui/countdown/go-pixel', 'shared'));
FunkinSprite.cacheTexture(Paths.image('gameplay/popup/normal/sick'));
FunkinSprite.cacheTexture(Paths.image('gameplay/popup/normal/good'));
FunkinSprite.cacheTexture(Paths.image('gameplay/popup/normal/bad'));
FunkinSprite.cacheTexture(Paths.image('gameplay/popup/normal/shit'));
FunkinSprite.cacheTexture(Paths.image('gameplay/popup/pixel/sick-pixel'));
FunkinSprite.cacheTexture(Paths.image('gameplay/popup/pixel/good-pixel'));
FunkinSprite.cacheTexture(Paths.image('gameplay/popup/pixel/bad-pixel'));
FunkinSprite.cacheTexture(Paths.image('gameplay/popup/pixel/shit-pixel'));
FunkinSprite.cacheTexture(Paths.image('ui/countdown/funkin/ready', 'shared'));
FunkinSprite.cacheTexture(Paths.image('ui/countdown/funkin/set', 'shared'));
FunkinSprite.cacheTexture(Paths.image('ui/countdown/funkin/go', 'shared'));
FunkinSprite.cacheTexture(Paths.image('ui/countdown/pixel/ready', 'shared'));
FunkinSprite.cacheTexture(Paths.image('ui/countdown/pixel/set', 'shared'));
FunkinSprite.cacheTexture(Paths.image('ui/countdown/pixel/go', 'shared'));
FunkinSprite.cacheTexture(Paths.image('ui/popup/normal/sick'));
FunkinSprite.cacheTexture(Paths.image('ui/popup/normal/good'));
FunkinSprite.cacheTexture(Paths.image('ui/popup/normal/bad'));
FunkinSprite.cacheTexture(Paths.image('ui/popup/normal/shit'));
FunkinSprite.cacheTexture(Paths.image('ui/popup/pixel/sick'));
FunkinSprite.cacheTexture(Paths.image('ui/popup/pixel/good'));
FunkinSprite.cacheTexture(Paths.image('ui/popup/pixel/bad'));
FunkinSprite.cacheTexture(Paths.image('ui/popup/pixel/shit'));
FunkinSprite.cacheTexture(Paths.image('miss', 'shared')); // TODO: remove this
// List all image assets in the level's library.

View file

@ -258,6 +258,11 @@ class Constants
*/
public static final DEFAULT_NOTE_STYLE:String = 'funkin';
/**
* The default pixel note style for songs.
*/
public static final DEFAULT_PIXEL_NOTE_STYLE:String = 'pixel';
/**
* The default album for songs in Freeplay.
*/