Skip to content

Commit

Permalink
ARI IS AWESOME
Browse files Browse the repository at this point in the history
freeplay loading thread
  • Loading branch information
Yoshubs authored Sep 23, 2021
2 parents 7fd1bfc + ca0f22a commit dc68102
Showing 1 changed file with 60 additions and 1 deletion.
61 changes: 60 additions & 1 deletion source/gameFolder/meta/state/menus/FreeplayState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import gameFolder.meta.data.font.Alphabet;
import lime.utils.Assets;
import openfl.media.Sound;
import sys.FileSystem;
import sys.thread.Thread;

using StringTools;

Expand All @@ -31,13 +32,16 @@ class FreeplayState extends MusicBeatState

var selector:FlxText;
var curSelected:Int = 0;
var curSongPlaying:Int = -1;
var curDifficulty:Int = 1;

var scoreText:FlxText;
var diffText:FlxText;
var lerpScore:Int = 0;
var intendedScore:Int = 0;

var songThread:Thread;

private var grpSongs:FlxTypedGroup<Alphabet>;
private var curPlaying:Bool = false;

Expand Down Expand Up @@ -211,6 +215,7 @@ class FreeplayState extends MusicBeatState

if (controls.BACK)
{
songThread.sendMessage(-1);
Main.switchState(this, new MainMenuState());
}

Expand All @@ -229,6 +234,8 @@ class FreeplayState extends MusicBeatState
if (FlxG.sound.music != null)
FlxG.sound.music.stop();

songThread.sendMessage(-1);

Main.switchState(this, new PlayState());
}

Expand Down Expand Up @@ -305,11 +312,63 @@ class FreeplayState extends MusicBeatState
}
//

trace("curSelected: " + curSelected);

changeDiff();
changeSongPlaying();
}

function changeSongPlaying()
{
if (songThread == null)
{
songThread = Thread.create(function()
{
while (true)
{
var index:Null<Int> = Thread.readMessage(false);
if (index != null)
{
if (index == -1)
{
trace("Killing thread");
return;
}

if (index == curSelected && index != curSongPlaying)
{
trace("Loading index " + index);

var inst:Sound = Sound.fromFile('./' + Paths.inst(songs[curSelected].songName));

if (index == curSelected)
{
FlxG.sound.playMusic(inst);

if (FlxG.sound.music.fadeTween != null)
FlxG.sound.music.fadeTween.cancel();

FlxG.sound.music.volume = 0.0;
FlxG.sound.music.fadeIn(1.0, 0.0, 1.0);

curSongPlaying = curSelected;
}
else
{
trace("Nevermind, skipping " + index);
}
}
else
trace("Skipping " + index);
}
}
});
}

songThread.sendMessage(curSelected);
}

var playingSongs:Array<FlxSound> = [];
var songPlayThread:sys.thread.Thread;
}

class SongMetadata
Expand Down

0 comments on commit dc68102

Please sign in to comment.