Skip to content

Commit

Permalink
videoSprite now works outside PlayState
Browse files Browse the repository at this point in the history
and the easter egg now works too
  • Loading branch information
moxie-coder committed Jan 13, 2025
1 parent b705189 commit a9627a2
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 11 deletions.
51 changes: 43 additions & 8 deletions source/TitleState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class TitleState extends MusicBeatState
'ANNOUNCER'
];
final allowedKeys:String = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
final allowedShit = ~/^[ABCDEFGHIJKLMNOPQRSTUVWXYZ]+$/;
var sarcasmKeysBuffer:String = '';

var blackScreen:FlxSprite;
Expand Down Expand Up @@ -364,19 +365,24 @@ class TitleState extends MusicBeatState
throw 'Crash test';
*/

// Sarcasm Easter Egg, this might not work! :D
function sarcasmEasterEgg()
sarcasmKeysBuffer += KeyboardFunctions.keypressToString();
if (sarcasmKeysBuffer.length >= 32)
sarcasmKeysBuffer = sarcasmKeysBuffer.substring(1);

for (wordRaw in sarcasmKeys)
{
//if(FlxG.save.data == null) FlxG.save.data = ''; // Crash prevention
switch(sarcasmEgg)
final word:String = wordRaw.toUpperCase();
if (sarcasmKeysBuffer.contains(word) && allowedShit.match(word))
{
case 'ANNOUNCER':
FlxG.sound.play(Paths.sound('sarcasmComplete'));
switch (word)
{
case 'ANNOUNCER':
FlxG.sound.play(Paths.sound('sarcasmComplete'));
sarcasmKeysBuffer = '';
}
}
}

sarcasmEasterEgg();

if (initialized && !transitioning && skippedIntro)
{
if (newTitle && !pressedEnter)
Expand Down Expand Up @@ -565,3 +571,32 @@ class TitleState extends MusicBeatState
}
}
}

// copied & pasted from an haxelib, but it's better
private class KeyboardFunctions
{
/**
* Just a simple function to determine which key was pressed. Good for sequential keypresses. An example of how to use this is by simply adding the value to a string in the update function.
*
* Ex:
* ```
* public var value:String = '';
* override function update(elapsed:Float) {
* value += keypressToString(); // This will add a key to the string everytime a key is pressed
* }
* ```
* @return Key that was pressed as a String
*/
public static function keypressToString():String
{
var characterToAdd:String = "";
if (FlxG.keys.justPressed.ANY) {
final key = cast(FlxG.keys.firstJustPressed(), FlxKey);
if (key != FlxKey.NONE){
final i = key.toString().toUpperCase();
characterToAdd += FlxKey.fromStringMap.get(i);
}
}
return characterToAdd;
}
}
18 changes: 15 additions & 3 deletions source/VideoSprite.hx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ class VideoSprite extends FlxSpriteGroup
public var waiting:Bool = false;
public var didPlay:Bool = false;

public var addCover:Bool = true;

private var controls(get, never):Controls;

inline function get_controls():Controls
Expand All @@ -42,7 +44,7 @@ class VideoSprite extends FlxSpriteGroup
cameras = [FlxG.cameras.list[FlxG.cameras.list.length - 1]];

waiting = isWaiting;
if (!waiting) // for mid song videos, if not mid song, don't add the cover since it's not needed
if (!waiting || addCover) // for mid song videos, if not mid song, don't add the cover since it's not needed
{
cover = new FlxSprite().makeGraphic(1, 1, FlxColor.BLACK);
cover.scale.set(FlxG.width + 100, FlxG.height + 100);
Expand Down Expand Up @@ -73,7 +75,12 @@ class VideoSprite extends FlxSpriteGroup
cover.destroy();
}

PlayState.instance.remove(this);
final curState = FlxG.state;

if (PlayState.instance != null)
PlayState.instance.remove(this);
else if (curState != null)
curState.remove(this, true);
destroy();
alreadyDestroyed = true;
});
Expand Down Expand Up @@ -119,7 +126,12 @@ class VideoSprite extends FlxSpriteGroup
finishCallback();
onSkip = null;

PlayState.instance.remove(this);
final curState = FlxG.state;

if (PlayState.instance != null)
PlayState.instance.remove(this);
else if (curState != null)
curState.remove(this, true);
super.destroy();
}

Expand Down

0 comments on commit a9627a2

Please sign in to comment.