Merge pull request #352 from FunkinCrew/a-bot-bars

A-Bot bars phase 1
This commit is contained in:
Cameron Taylor 2024-04-19 15:11:56 -04:00 committed by GitHub
commit ba240c45a4
6 changed files with 160 additions and 122 deletions

View file

@ -124,6 +124,8 @@
<haxelib name="polymod" /> <!-- Modding framework --> <haxelib name="polymod" /> <!-- Modding framework -->
<haxelib name="flxanimate" /> <!-- Texture atlas rendering --> <haxelib name="flxanimate" /> <!-- Texture atlas rendering -->
<haxelib name="hxCodec" if="desktop" unless="hl" /> <!-- Video playback --> <haxelib name="hxCodec" if="desktop" unless="hl" /> <!-- Video playback -->
<haxelib name="funkVis"/>
<haxelib name="json2object" /> <!-- JSON parsing --> <haxelib name="json2object" /> <!-- JSON parsing -->
<haxelib name="thx.semver" /> <!-- Version string handling --> <haxelib name="thx.semver" /> <!-- Version string handling -->

2
assets

@ -1 +1 @@
Subproject commit a24f42932fbe9032d28be1603f197fb50c938276 Subproject commit daf702a6ec8b60f1922261872cc74eb107fece06

View file

@ -4,7 +4,7 @@
"name": "discord_rpc", "name": "discord_rpc",
"type": "git", "type": "git",
"dir": null, "dir": null,
"ref": "2d83fa863ef0c1eace5f1cf67c3ac315d1a3a8a5", "ref": "2d83fa8",
"url": "https://github.com/Aidan63/linc_discord-rpc" "url": "https://github.com/Aidan63/linc_discord-rpc"
}, },
{ {
@ -18,7 +18,7 @@
"name": "flixel-addons", "name": "flixel-addons",
"type": "git", "type": "git",
"dir": null, "dir": null,
"ref": "a523c3b56622f0640933944171efed46929e360e", "ref": "a523c3b",
"url": "https://github.com/FunkinCrew/flixel-addons" "url": "https://github.com/FunkinCrew/flixel-addons"
}, },
{ {
@ -30,14 +30,14 @@
"name": "flixel-ui", "name": "flixel-ui",
"type": "git", "type": "git",
"dir": null, "dir": null,
"ref": "719b4f10d94186ed55f6fef1b6618d32abec8c15", "ref": "719b4f1",
"url": "https://github.com/HaxeFlixel/flixel-ui" "url": "https://github.com/HaxeFlixel/flixel-ui"
}, },
{ {
"name": "flxanimate", "name": "flxanimate",
"type": "git", "type": "git",
"dir": null, "dir": null,
"ref": "9bacdd6ea39f5e3a33b0f5dfb7bc583fe76060d4", "ref": "9bacdd6",
"url": "https://github.com/FunkinCrew/flxanimate" "url": "https://github.com/FunkinCrew/flxanimate"
}, },
{ {
@ -45,6 +45,13 @@
"type": "haxelib", "type": "haxelib",
"version": "3.5.0" "version": "3.5.0"
}, },
{
"name": "funkVis",
"type": "git",
"dir": null,
"ref": "backend-rework",
"url": "https://github.com/FunkinCrew/funkVis"
},
{ {
"name": "hamcrest", "name": "hamcrest",
"type": "haxelib", "type": "haxelib",
@ -54,14 +61,14 @@
"name": "haxeui-core", "name": "haxeui-core",
"type": "git", "type": "git",
"dir": null, "dir": null,
"ref": "0212d8fdfcafeb5f0d5a41e1ddba8ff21d0e183b", "ref": "0212d8fd",
"url": "https://github.com/haxeui/haxeui-core" "url": "https://github.com/haxeui/haxeui-core"
}, },
{ {
"name": "haxeui-flixel", "name": "haxeui-flixel",
"type": "git", "type": "git",
"dir": null, "dir": null,
"ref": "63a906a6148958dbfde8c7b48d90b0693767fd95", "ref": "63a906a",
"url": "https://github.com/haxeui/haxeui-flixel" "url": "https://github.com/haxeui/haxeui-flixel"
}, },
{ {
@ -73,7 +80,7 @@
"name": "hxCodec", "name": "hxCodec",
"type": "git", "type": "git",
"dir": null, "dir": null,
"ref": "387e1665d6feb5762358134f168e6ebfe46acec8", "ref": "387e166",
"url": "https://github.com/FunkinCrew/hxCodec" "url": "https://github.com/FunkinCrew/hxCodec"
}, },
{ {
@ -85,7 +92,7 @@
"name": "hxcpp-debug-server", "name": "hxcpp-debug-server",
"type": "git", "type": "git",
"dir": "hxcpp-debug-server", "dir": "hxcpp-debug-server",
"ref": "147294123f983e35f50a966741474438069a7a8f", "ref": "1472941",
"url": "https://github.com/FunkinCrew/hxcpp-debugger" "url": "https://github.com/FunkinCrew/hxcpp-debugger"
}, },
{ {
@ -97,7 +104,7 @@
"name": "json2object", "name": "json2object",
"type": "git", "type": "git",
"dir": null, "dir": null,
"ref": "a8c26f18463c98da32f744c214fe02273e1823fa", "ref": "a8c26f1",
"url": "https://github.com/FunkinCrew/json2object" "url": "https://github.com/FunkinCrew/json2object"
}, },
{ {
@ -111,28 +118,28 @@
"name": "mconsole", "name": "mconsole",
"type": "git", "type": "git",
"dir": null, "dir": null,
"ref": "master", "ref": "06c0499",
"url": "https://github.com/massive-oss/mconsole" "url": "https://github.com/massive-oss/mconsole"
}, },
{ {
"name": "mcover", "name": "mcover",
"type": "git", "type": "git",
"dir": "src", "dir": "src",
"ref": "master", "ref": "c3c47cd",
"url": "https://github.com/massive-oss/mcover" "url": "https://github.com/massive-oss/mcover"
}, },
{ {
"name": "mockatoo", "name": "mockatoo",
"type": "git", "type": "git",
"dir": "src", "dir": "src",
"ref": "master", "ref": "13d77a0",
"url": "https://github.com/FunkinCrew/mockatoo" "url": "https://github.com/FunkinCrew/mockatoo"
}, },
{ {
"name": "munit", "name": "munit",
"type": "git", "type": "git",
"dir": "src", "dir": "src",
"ref": "master", "ref": "f61be7f",
"url": "https://github.com/FunkinCrew/MassiveUnit" "url": "https://github.com/FunkinCrew/MassiveUnit"
}, },
{ {

View file

@ -113,6 +113,8 @@ class Main extends Sprite
addChild(game); addChild(game);
addChild(fpsCounter);
#if hxcpp_debug_server #if hxcpp_debug_server
trace('hxcpp_debug_server is enabled! You can now connect to the game with a debugger.'); trace('hxcpp_debug_server is enabled! You can now connect to the game with a debugger.');
#else #else

View file

@ -8,110 +8,97 @@ import flixel.group.FlxSpriteGroup.FlxTypedSpriteGroup;
import flixel.math.FlxMath; import flixel.math.FlxMath;
import flixel.sound.FlxSound; import flixel.sound.FlxSound;
import funkin.util.MathUtil; import funkin.util.MathUtil;
import funkVis.dsp.SpectralAnalyzer;
import funkVis.audioclip.frontends.LimeAudioClip;
using Lambda; using Lambda;
class ABotVis extends FlxTypedSpriteGroup<FlxSprite> class ABotVis extends FlxTypedSpriteGroup<FlxSprite>
{ {
public var vis:VisShit; // public var vis:VisShit;
var analyzer:SpectralAnalyzer;
var volumes:Array<Float> = []; var volumes:Array<Float> = [];
public var snd:FlxSound;
public function new(snd:FlxSound) public function new(snd:FlxSound)
{ {
super(); super();
vis = new VisShit(snd); this.snd = snd;
// vis = new VisShit(snd);
// vis.snd = snd; // vis.snd = snd;
var visFrms:FlxAtlasFrames = Paths.getSparrowAtlas('aBotViz'); var visFrms:FlxAtlasFrames = Paths.getSparrowAtlas('aBotViz');
// these are the differences in X position, from left to right
var positionX:Array<Float> = [0, 59, 56, 66, 54, 52, 51];
var positionY:Array<Float> = [0, -8, -3.5, -0.4, 0.5, 4.7, 7];
for (lol in 1...8) for (lol in 1...8)
{ {
// pushes initial value // pushes initial value
volumes.push(0.0); volumes.push(0.0);
var sum = function(num:Float, total:Float) return total += num;
var posX:Float = positionX.slice(0, lol).fold(sum, 0);
var posY:Float = positionY.slice(0, lol).fold(sum, 0);
var viz:FlxSprite = new FlxSprite(50 * lol, 0); var viz:FlxSprite = new FlxSprite(posX, posY);
viz.frames = visFrms; viz.frames = visFrms;
add(viz); add(viz);
var visStr = 'VIZ'; var visStr = 'viz';
if (lol == 5) visStr = 'viz'; // lol makes it lowercase, accomodates for art that I dont wanna rename!
viz.animation.addByPrefix('VIZ', visStr + lol, 0); viz.animation.addByPrefix('VIZ', visStr + lol, 0);
viz.animation.play('VIZ', false, false, -1); viz.animation.play('VIZ', false, false, 2);
} }
} }
public function initAnalyzer()
{
@:privateAccess
analyzer = new SpectralAnalyzer(7, new LimeAudioClip(cast snd._channel.__source), 0.01, 30);
analyzer.maxDb = -35;
// analyzer.fftN = 2048;
}
var visTimer:Float = -1;
var visTimeMax:Float = 1 / 30;
override function update(elapsed:Float) override function update(elapsed:Float)
{ {
// updateViz(); // updateViz();
updateFFT(elapsed); // updateFFT(elapsed);
//
super.update(elapsed); super.update(elapsed);
} }
function updateFFT(elapsed:Float) static inline function min(x:Int, y:Int):Int
{ {
if (vis.snd != null) return x > y ? y : x;
{
vis.checkAndSetBuffer();
if (vis.setBuffer)
{
var remappedShit:Int = 0;
if (vis.snd.playing) remappedShit = Std.int(FlxMath.remapToRange(vis.snd.time, 0, vis.snd.length, 0, vis.numSamples));
else
remappedShit = Std.int(FlxMath.remapToRange(Conductor.instance.songPosition, 0, vis.snd.length, 0, vis.numSamples));
var fftSamples:Array<Float> = [];
var swagBucks = remappedShit;
for (i in remappedShit...remappedShit + (Std.int((44100 * (1 / 144)))))
{
var left = vis.audioData[swagBucks] / 32767;
var right = vis.audioData[swagBucks + 1] / 32767;
var balanced = (left + right) / 2;
swagBucks += 2;
fftSamples.push(balanced);
} }
var freqShit = vis.funnyFFT(fftSamples); override function draw()
for (i in 0...group.members.length)
{ {
var getSliceShit = function(s:Int) { #if web
var powShit = FlxMath.remapToRange(s, 0, group.members.length, 0, MathUtil.logBase(10, freqShit[0].length)); if (analyzer != null) drawFFT();
return Math.round(Math.pow(10, powShit)); #end
}; super.draw();
// var powShit:Float = getSliceShit(i);
var hzSliced:Int = getSliceShit(i);
var sliceLength:Int = Std.int(freqShit[0].length / group.members.length);
var volSlice = freqShit[0].slice(hzSliced, getSliceShit(i + 1));
var avgVel:Float = 0;
for (slice in volSlice)
{
avgVel += slice;
} }
avgVel /= volSlice.length; /**
* TJW funkVis based visualizer! updateFFT() is the old nasty shit that dont worky!
*/
function drawFFT():Void
{
var levels = analyzer.getLevels(false);
avgVel *= 10000000; for (i in 0...min(group.members.length, levels.length))
{
volumes[i] += avgVel - (elapsed * (volumes[i] * 50)); var animFrame:Int = Math.round(levels[i].value * 5);
var animFrame:Int = Std.int(volumes[i]);
animFrame = Math.floor(Math.min(5, animFrame)); animFrame = Math.floor(Math.min(5, animFrame));
animFrame = Math.floor(Math.max(0, animFrame)); animFrame = Math.floor(Math.max(0, animFrame));
@ -119,42 +106,82 @@ class ABotVis extends FlxTypedSpriteGroup<FlxSprite>
animFrame = Std.int(Math.abs(animFrame - 5)); // shitty dumbass flip, cuz dave got da shit backwards lol! animFrame = Std.int(Math.abs(animFrame - 5)); // shitty dumbass flip, cuz dave got da shit backwards lol!
group.members[i].animation.curAnim.curFrame = animFrame; group.members[i].animation.curAnim.curFrame = animFrame;
if (FlxG.keys.justPressed.U)
{
trace(avgVel);
trace(group.members[i].animation.curAnim.curFrame);
} }
} }
// group.members[0].animation.curAnim.curFrame = // function updateFFT(elapsed:Float)
} // {
} // if (vis.snd != null)
} // {
// vis.checkAndSetBuffer();
public function updateViz() // if (vis.setBuffer)
{ // {
if (vis.snd != null) // var remappedShit:Int = 0;
{ // if (vis.snd.playing) remappedShit = Std.int(FlxMath.remapToRange(vis.snd.time, 0, vis.snd.length, 0, vis.numSamples));
var remappedShit:Int = 0; // else
vis.checkAndSetBuffer(); // remappedShit = Std.int(FlxMath.remapToRange(Conductor.instance.songPosition, 0, vis.snd.length, 0, vis.numSamples));
// var fftSamples:Array<Float> = [];
if (vis.setBuffer) // var swagBucks = remappedShit;
{ // for (i in remappedShit...remappedShit + (Std.int((44100 * (1 / 144)))))
// var startingSample:Int = Std.int(FlxMath.remapToRange) // {
// var left = vis.audioData[swagBucks] / 32767;
if (vis.snd.playing) remappedShit = Std.int(FlxMath.remapToRange(vis.snd.time, 0, vis.snd.length, 0, vis.numSamples)); // var right = vis.audioData[swagBucks + 1] / 32767;
// var balanced = (left + right) / 2;
for (i in 0...group.members.length) // swagBucks += 2;
{ // fftSamples.push(balanced);
var sampleApprox:Int = Std.int(FlxMath.remapToRange(i, 0, group.members.length, remappedShit, remappedShit + 500)); // }
// var freqShit = vis.funnyFFT(fftSamples);
var left = vis.audioData[sampleApprox] / 32767; // for (i in 0...group.members.length)
// {
var animFrame:Int = Std.int(FlxMath.remapToRange(left, -1, 1, 0, 6)); // var getSliceShit = function(s:Int) {
// var powShit = FlxMath.remapToRange(s, 0, group.members.length, 0, MathUtil.logBase(10, freqShit[0].length));
group.members[i].animation.curAnim.curFrame = animFrame; // return Math.round(Math.pow(10, powShit));
} // };
} // // var powShit:Float = getSliceShit(i);
} // var hzSliced:Int = getSliceShit(i);
} // var sliceLength:Int = Std.int(freqShit[0].length / group.members.length);
// var volSlice = freqShit[0].slice(hzSliced, getSliceShit(i + 1));
// var avgVel:Float = 0;
// for (slice in volSlice)
// {
// avgVel += slice;
// }
// avgVel /= volSlice.length;
// avgVel *= 10000000;
// volumes[i] += avgVel - (elapsed * (volumes[i] * 50));
// var animFrame:Int = Std.int(volumes[i]);
// animFrame = Math.floor(Math.min(5, animFrame));
// animFrame = Math.floor(Math.max(0, animFrame));
// animFrame = Std.int(Math.abs(animFrame - 5)); // shitty dumbass flip, cuz dave got da shit backwards lol!
// group.members[i].animation.curAnim.curFrame = animFrame;
// if (FlxG.keys.justPressed.U)
// {
// trace(avgVel);
// trace(group.members[i].animation.curAnim.curFrame);
// }
// }
// // group.members[0].animation.curAnim.curFrame =
// }
// }
// }
// public function updateViz()
// {
// if (vis.snd != null)
// {
// var remappedShit:Int = 0;
// vis.checkAndSetBuffer();
// if (vis.setBuffer)
// {
// // var startingSample:Int = Std.int(FlxMath.remapToRange)
// if (vis.snd.playing) remappedShit = Std.int(FlxMath.remapToRange(vis.snd.time, 0, vis.snd.length, 0, vis.numSamples));
// for (i in 0...group.members.length)
// {
// var sampleApprox:Int = Std.int(FlxMath.remapToRange(i, 0, group.members.length, remappedShit, remappedShit + 500));
// var left = vis.audioData[sampleApprox] / 32767;
// var animFrame:Int = Std.int(FlxMath.remapToRange(left, -1, 1, 0, 6));
// group.members[i].animation.curAnim.curFrame = animFrame;
// }
// }
// }
// }
} }

View file

@ -1919,8 +1919,6 @@ class PlayState extends MusicBeatSubState
*/ */
function startSong():Void function startSong():Void
{ {
dispatchEvent(new ScriptEvent(SONG_START));
startingSong = false; startingSong = false;
if (!overrideMusic && !isGamePaused && currentChart != null) if (!overrideMusic && !isGamePaused && currentChart != null)
@ -1942,7 +1940,7 @@ class PlayState extends MusicBeatSubState
// Prevent the volume from being wrong. // Prevent the volume from being wrong.
FlxG.sound.music.volume = 1.0; FlxG.sound.music.volume = 1.0;
FlxG.sound.music.fadeTween?.cancel(); if (FlxG.sound.music.fadeTween != null) FlxG.sound.music.fadeTween.cancel();
trace('Playing vocals...'); trace('Playing vocals...');
add(vocals); add(vocals);
@ -1961,6 +1959,8 @@ class PlayState extends MusicBeatSubState
// FlxG.sound.music.time = startTimestamp - Conductor.instance.instrumentalOffset; // FlxG.sound.music.time = startTimestamp - Conductor.instance.instrumentalOffset;
handleSkippedNotes(); handleSkippedNotes();
} }
dispatchEvent(new ScriptEvent(SONG_START));
} }
/** /**