From 0c0829b2d0ea349f983c6c3478927a9a285e06f9 Mon Sep 17 00:00:00 2001 From: Cameron Taylor <cameron.taylor.ninja@gmail.com> Date: Wed, 11 Oct 2023 07:43:44 -0400 Subject: [PATCH] sound effects for stickersubstate --- assets | 2 +- source/funkin/ui/StickerSubState.hx | 57 +++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 1 deletion(-) diff --git a/assets b/assets index d946072ac..775a0c0a5 160000 --- a/assets +++ b/assets @@ -1 +1 @@ -Subproject commit d946072ac531e049e2a817048b65fa1ca541134a +Subproject commit 775a0c0a5b2d3009fbec17560c7364a4ac61e3c7 diff --git a/source/funkin/ui/StickerSubState.hx b/source/funkin/ui/StickerSubState.hx index 067f50c31..bde36b160 100644 --- a/source/funkin/ui/StickerSubState.hx +++ b/source/funkin/ui/StickerSubState.hx @@ -17,6 +17,9 @@ import openfl.geom.Matrix; import openfl.display.Sprite; import openfl.display.Bitmap; +using Lambda; +using StringTools; + class StickerSubState extends MusicBeatSubState { public var grpStickers:FlxTypedGroup<StickerSprite>; @@ -26,10 +29,60 @@ class StickerSubState extends MusicBeatSubState var nextState:NEXTSTATE = FREEPLAY; + // what "folders" to potentially load from (as of writing only "keys" exist) + var soundSelections:Array<String> = []; + // what "folder" was randomly selected + var soundSelection:String = ""; + var sounds:Array<String> = []; + public function new(?oldStickers:Array<StickerSprite>, ?nextState:NEXTSTATE = FREEPLAY):Void { super(); + // todo still + // make sure that ONLY plays mp3/ogg files + // if there's no mp3/ogg file, then it regenerates/reloads the random folder + + var assetsInList = openfl.utils.Assets.list(); + + var soundFilterFunc = function(a:String) { + return a.startsWith('assets/shared/sounds/stickersounds/'); + }; + + soundSelections = assetsInList.filter(soundFilterFunc); + soundSelections = soundSelections.map(function(a:String) { + return a.replace('assets/shared/sounds/stickersounds/', '').split('/')[0]; + }); + + // cracked cleanup... yuchh... + for (i in soundSelections) + { + while (soundSelections.contains(i)) + { + soundSelections.remove(i); + } + soundSelections.push(i); + } + + trace(soundSelections); + + soundSelection = FlxG.random.getObject(soundSelections); + + var filterFunc = function(a:String) { + return a.startsWith('assets/shared/sounds/stickersounds/' + soundSelection + '/'); + }; + var assetsInList3 = openfl.utils.Assets.list(); + sounds = assetsInList3.filter(filterFunc); + for (i in 0...sounds.length) + { + sounds[i] = sounds[i].replace('assets/shared/sounds/', ''); + sounds[i] = sounds[i].substring(0, sounds[i].lastIndexOf('.')); + } + + trace(sounds); + + // trace(assetsInList); + this.nextState = nextState; grpStickers = new FlxTypedGroup<StickerSprite>(); @@ -66,6 +119,8 @@ class StickerSubState extends MusicBeatSubState { new FlxTimer().start(sticker.timing, _ -> { sticker.visible = false; + var daSound:String = FlxG.random.getObject(sounds); + FlxG.sound.play(Paths.sound(daSound)); if (ind == grpStickers.members.length - 1) { @@ -152,6 +207,8 @@ class StickerSubState extends MusicBeatSubState new FlxTimer().start(sticker.timing, _ -> { sticker.visible = true; + var daSound:String = FlxG.random.getObject(sounds); + FlxG.sound.play(Paths.sound(daSound)); var frameTimer:Int = FlxG.random.int(0, 2);