Skip to content

Commit

Permalink
Fucking normal ressetings fuck thgis shit with callback to track start
Browse files Browse the repository at this point in the history
its real shit
its breaks everything
its breaks me
  • Loading branch information
PurSnake committed Jul 11, 2024
1 parent 1bac9af commit 7fa6aaa
Show file tree
Hide file tree
Showing 8 changed files with 112 additions and 112 deletions.
4 changes: 1 addition & 3 deletions source/funkin/play/Countdown.hx
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,13 @@ class Countdown
countdownStep = BEFORE;
var cancelled:Bool = propagateCountdownEvent(countdownStep);
if (cancelled)
{
return false;
}

// Stop any existing countdown.
stopCountdown();

PlayState.instance.isInCountdown = true;
Conductor.instance.update(PlayState.instance.startTimestamp + Conductor.instance.beatLengthMs * -5);
Conductor.instance.update(PlayState.startTimestamp + Conductor.instance.beatLengthMs * -5);
// Handle onBeatHit events manually
// @:privateAccess
// PlayState.instance.dispatchEvent(new SongTimeScriptEvent(SONG_BEAT_HIT, 0, 0));
Expand Down
26 changes: 11 additions & 15 deletions source/funkin/play/GameOverSubState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class GameOverSubState extends MusicBeatSubState

var targetCameraZoom:Float = 1.0;

public static var restartState:Bool = false;
public static var resetState:Bool = true;

public function new(params:GameOverParams)
{
Expand Down Expand Up @@ -248,7 +248,7 @@ class GameOverSubState extends MusicBeatSubState
{
isEnding = true;
blueballed = false;
PlayState.instance.deathCounter = 0;
PlayState.deathCounter = 0;
// PlayState.seenCutscene = false; // old thing...
if (gameOverMusic != null) gameOverMusic.stop();

Expand Down Expand Up @@ -315,7 +315,7 @@ class GameOverSubState extends MusicBeatSubState
/**
* Do behavior which occurs when you confirm and move to restart the level.
*/
function confirmDeath():Void
dynamic function confirmDeath():Void
{
if (!isEnding)
{
Expand All @@ -336,7 +336,7 @@ class GameOverSubState extends MusicBeatSubState
FlxG.camera.fade(FlxColor.BLACK, 1, true, null, true);
PlayState.instance.needsReset = true;

if (PlayState.instance.isMinimalMode || boyfriend == null) {}
if (PlayState.instance.isMinimalMode || boyfriend == null || resetState) {}
else
{
// Readd Boyfriend to the stage.
Expand All @@ -349,9 +349,15 @@ class GameOverSubState extends MusicBeatSubState
resetCameraZoom();

//if ((this.isChartingMode || PlayState.instance.isMinimalMode) && !restartState)
close();
//close();
//else
//FlxG.resetState();

if (resetState && !(this.isChartingMode || PlayState.instance.isMinimalMode))
{
flixel.addons.transition.FlxTransitionableState.skipNextTransIn = flixel.addons.transition.FlxTransitionableState.skipNextTransOut = true;
FlxG.resetState();
} else close();
});
});
}
Expand All @@ -375,16 +381,6 @@ class GameOverSubState extends MusicBeatSubState
if (ending) basePath += 'End';
else if (starting) basePath += 'Start';

/*var musicPath:String = Paths.music(basePath + suffix);
while (!Assets.exists(musicPath) && suffix.length > 0)
{
suffix = suffix.split('-').slice(0, -1).join('-');
musicPath = Paths.music(basePath + suffix);
}
if (!Assets.exists(musicPath)) return null;
trace('Resolved music path: ' + musicPath);
return musicPath;*/

var music = Paths.music(basePath + suffix);
var musicPath:String = Paths.musicStr(basePath + suffix);
while (!Assets.exists(musicPath) && suffix.length > 0)
Expand Down
43 changes: 16 additions & 27 deletions source/funkin/play/PauseSubState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class PauseSubState extends MusicBeatSubState
*/
public static var musicSuffix:String = '';

public static var restartState:Bool = false;
public static var resetState:Bool = true;

/**
* Reset the pause configuration to the default.
Expand Down Expand Up @@ -313,7 +313,7 @@ class PauseSubState extends MusicBeatSubState
metadataDifficulty.scrollFactor.set(0, 0);
metadata.add(metadataDifficulty);

metadataDeaths = new FlxText(20, metadataDifficulty.y + 32, FlxG.width - 40, '${PlayState.instance?.deathCounter} Blue Balls');
metadataDeaths = new FlxText(20, metadataDifficulty.y + 32, FlxG.width - 40, '${PlayState?.deathCounter} Blue Balls');
metadataDeaths.setFormat(Paths.font('vcr.ttf'), 32, FlxColor.WHITE, FlxTextAlign.RIGHT);
metadataDeaths.scrollFactor.set(0, 0);
metadata.add(metadataDeaths);
Expand Down Expand Up @@ -399,9 +399,7 @@ class PauseSubState extends MusicBeatSubState
delay += 0.1;
}

new FlxTimer().start(0.2, (_) -> {
allowInput = true;
});
new FlxTimer().start(0.2, (_) -> allowInput = true);
}

// ===============
Expand All @@ -415,14 +413,8 @@ class PauseSubState extends MusicBeatSubState
{
if (!allowInput) return;

if (controls.UI_UP_P)
{
changeSelection(-1);
}
if (controls.UI_DOWN_P)
{
changeSelection(1);
}

if (controls.UI_UP_P || controls.UI_DOWN_P) changeSelection(controls.UI_UP_P ? -1 : 1);

if (controls.ACCEPT)
{
Expand Down Expand Up @@ -597,7 +589,7 @@ class PauseSubState extends MusicBeatSubState
switch (this.currentMode)
{
case Standard | Difficulty:
metadataDeaths.text = '${PlayState.instance?.deathCounter} Blue Balls';
metadataDeaths.text = '${PlayState?.deathCounter} Blue Balls';
case Charting:
metadataDeaths.text = 'Chart Editor Preview';
case Conversation:
Expand Down Expand Up @@ -653,14 +645,13 @@ class PauseSubState extends MusicBeatSubState

//////OG
PlayState.instance.needsReset = true;
//if (PlayState.instance.isChartingMode)
state.close();
/*else
if (resetState && !PlayState.instance.isChartingMode)
{
FlxG.sound.music.volume = PlayState.instance.vocals.volume = 0;
FlxG.sound?.music?.volume = 0;
PlayState.instance?.vocals?.volume = 0;
FlxTransitionableState.skipNextTransIn = FlxTransitionableState.skipNextTransOut = false;
FlxG.resetState();
}*/
} else state.close();
}

/**
Expand All @@ -670,15 +661,13 @@ class PauseSubState extends MusicBeatSubState
static function restartPlayState(state:PauseSubState):Void
{
PlayState.instance.needsReset = true;
//if (PlayState.instance.isChartingMode && !restartState)
state.close();
/*else
if (resetState && !PlayState.instance.isChartingMode)
{
FlxG.sound.music.volume = PlayState.instance.vocals.volume = 0;
FlxG.sound?.music?.volume = 0;
PlayState.instance?.vocals?.volume = 0;
FlxTransitionableState.skipNextTransIn = FlxTransitionableState.skipNextTransOut = false;
//FlxG.resetState();
FlxG.state.startOutro(() -> FlxG.resetState());
}*/
FlxG.resetState();
} else state.close();
}

/**
Expand Down Expand Up @@ -745,7 +734,7 @@ class PauseSubState extends MusicBeatSubState
{
state.allowInput = false;

PlayState.instance.deathCounter = 0;
PlayState.deathCounter = 0;

FlxTransitionableState.skipNextTransIn = true;
FlxTransitionableState.skipNextTransOut = true;
Expand Down
5 changes: 3 additions & 2 deletions source/funkin/play/PlayState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ class PlayState extends MusicBeatSubState
* The current 'Blueball Counter' to display in the pause menu.
* Resets when you beat a song or go back to the main menu.
*/
public var deathCounter:Int = 0;
public static var deathCounter:Int = 0;

/**
* The player's current health.
Expand All @@ -222,7 +222,7 @@ class PlayState extends MusicBeatSubState
* For example, if `startTimestamp` is `30000`, the song will start at the 30 second mark.
* Used for chart playtesting or practice.
*/
public var startTimestamp:Float = 0.0;
public static var startTimestamp:Float = 0.0;

/**
* Play back the song at this speed.
Expand Down Expand Up @@ -611,6 +611,7 @@ class PlayState extends MusicBeatSubState
super();

FlxTransitionableState.skipNextTransIn = (lastParams != null);
if (lastParams == null) deathCounter = 0;
//FlxTransitionableState.skipNextTransOut = false;

//lastParams
Expand Down
30 changes: 11 additions & 19 deletions source/funkin/play/components/HealthIcon.hx
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ import funkin.util.Constants;
* - i.e. `PlayState.instance.iconP1.animation.addByPrefix("jumpscare", "jumpscare", 24, false);`
* @author MasterEric
*/
//@:nullSafety
@:nullSafety
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 @@ -133,7 +133,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 @@ -144,7 +144,7 @@ class HealthIcon extends FunkinSprite
initTargetSize();
}

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

Expand Down Expand Up @@ -180,6 +180,7 @@ class HealthIcon extends FunkinSprite
* Use the provided CharacterHealthIconData to configure this health icon's appearance.
* @param data The data to use to configure this health icon.
*/
@:nullSafety(Off)
public function configure(data:Null<HealthIconData>):Void
{
if (data == null)
Expand Down Expand Up @@ -391,18 +392,9 @@ class HealthIcon extends FunkinSprite
this.animation.add(Winning, [2], 0, false, false);
}

function correctCharacterId(charId:Null<String>):String
function iconExists(charId:String):Bool
{
if (charId == null)
return Constants.DEFAULT_HEALTH_ICON;

if (!Assets.exists(Paths.file('images/icons/icon-$charId.png', IMAGE)))
{
FlxG.log.warn('No icon for character: $charId : using default placeholder face instead!');
return Constants.DEFAULT_HEALTH_ICON;
}

return charId;
return Assets.exists(Paths.file('images/icons/icon-$charId.png'));
}

inline function isNewSpritesheet(charId:String):Bool
Expand All @@ -412,11 +404,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
2 changes: 1 addition & 1 deletion source/funkin/play/notes/Strumline.hx
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ class Strumline extends FlxSpriteGroup
// I don't remember what bug I was trying to fix by adding this.
// if (conductorInUse.currentStep == 0) nextNoteIndex = 0;

var songStart:Float = PlayState.instance?.startTimestamp ?? 0.0;
var songStart:Float = PlayState?.startTimestamp ?? 0.0;
var hitWindowStart:Float = conductorInUse.songPosition - Constants.HIT_WINDOW_MS;
var renderWindowStart:Float = conductorInUse.songPosition + RENDER_DISTANCE_MS;

Expand Down
52 changes: 49 additions & 3 deletions source/funkin/ui/MusicBeatSubState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class MusicBeatSubState extends FlxSubState implements IEventHandler
public static function getCurrentState():FlxState
{
var state = FlxG.state;
while (state.subState != null)
while (state.subState != null && Type.getClass(state.subState) != CustomTransition)
state = state.subState;

return state;
Expand Down Expand Up @@ -218,11 +218,38 @@ class MusicBeatSubState extends FlxSubState implements IEventHandler
finishTransOut();
}
}
else*/
onComplete();
else
onComplete();*/

_parentState == null ? stateStartOutro(onComplete) : onComplete();
}
}

function stateStartOutro(onOutroComplete:() -> Void)
{
if (!_exiting)
{
// play the exit transition, and when it's done call FlxG.switchState
_exiting = true;
transitionOut(onOutroComplete);
trace("KInda using transition out");
if (FlxTransitionableState.skipNextTransOut)
{
FlxTransitionableState.skipNextTransOut = false;
finishTransOut();
trace("Okay, we skipped it :p");
}
}
}


public function transitionOut(?OnExit:Void->Void):Void
{
_onExit = OnExit;
getCurrentState().openSubState(new CustomTransition(0.6, false));
CustomTransition.finishCallback = finishTransOut;
}

public override function openSubState(targetSubState:FlxSubState):Void
{
var event = new SubStateScriptEvent(SUBSTATE_OPEN_BEGIN, targetSubState, true);
Expand Down Expand Up @@ -259,4 +286,23 @@ class MusicBeatSubState extends FlxSubState implements IEventHandler
{
if (CustomTransition.currentTransition != null) CustomTransition.currentTransition.close();
}

var transOutFinished:Bool = false;

var _exiting:Bool = false;
var _onExit:Void->Void;
function finishTransOut()
{
transOutFinished = true;

if (!_exiting)
{
closeSubState();
}

if (_onExit != null)
{
_onExit();
}
}
}
Loading

0 comments on commit 7fa6aaa

Please sign in to comment.