Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assignable Sounds to Countdown (per-stage) #15439

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion assets/base_game/shared/stages/limo.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"directory": "week4",
"defaultZoom": 0.9,
"stageUI": "",
"introSounds": ["intro3", "intro2", "intro1", "introGo"],

"boyfriend": [1030, -120],
"girlfriend": [400, 130],
Expand All @@ -27,4 +28,4 @@
"boyfriend": "bf-car",
"gf": "gf-car"
}
}
}
3 changes: 2 additions & 1 deletion assets/base_game/shared/stages/mall.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"directory": "week5",
"defaultZoom": 0.8,
"stageUI": "",
"introSounds": ["intro3", "intro2", "intro1", "introGo"],

"boyfriend": [970, 100],
"girlfriend": [400, 130],
Expand All @@ -28,4 +29,4 @@
"boyfriend": "bf-christmas",
"gf": "gf-christmas"
}
}
}
3 changes: 2 additions & 1 deletion assets/base_game/shared/stages/mallEvil.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"directory": "week5",
"defaultZoom": 1.05,
"stageUI": "",
"introSounds": ["intro3", "intro2", "intro1", "introGo"],

"boyfriend": [1090, 100],
"girlfriend": [400, 130],
Expand All @@ -24,4 +25,4 @@
"boyfriend": "bf-christmas",
"gf": "gf-christmas"
}
}
}
3 changes: 2 additions & 1 deletion assets/base_game/shared/stages/philly.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"directory": "week3",
"defaultZoom": 1.05,
"stageUI": "",
"introSounds": ["intro3", "intro2", "intro1", "introGo"],

"boyfriend": [770, 100],
"girlfriend": [400, 130],
Expand All @@ -27,4 +28,4 @@
"boyfriend": "bf",
"gf": "gf"
}
}
}
3 changes: 2 additions & 1 deletion assets/base_game/shared/stages/phillyBlazin.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"directory": "weekend1",
"defaultZoom": 0.75,
"stageUI": "",
"introSounds": ["intro3", "intro2", "intro1", "introGo"],

"boyfriend": [900, 800],
"girlfriend": [470, 595],
Expand Down Expand Up @@ -30,4 +31,4 @@
"boyfriend": "pico-playable",
"gf": "nene"
}
}
}
3 changes: 2 additions & 1 deletion assets/base_game/shared/stages/phillyStreets.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"directory": "weekend1",
"defaultZoom": 0.77,
"stageUI": "",
"introSounds": ["intro3", "intro2", "intro1", "introGo"],

"boyfriend": [1930, 450],
"girlfriend": [1175, 200],
Expand Down Expand Up @@ -38,4 +39,4 @@
"boyfriend": "pico-playable",
"gf": "nene"
}
}
}
3 changes: 2 additions & 1 deletion assets/base_game/shared/stages/school.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"directory": "week6",
"defaultZoom": 1.05,
"stageUI": "pixel",
"introSounds": ["intro3-pixel", "intro2-pixel", "intro1-pixel", "introGo-pixel"],

"boyfriend": [970, 320],
"girlfriend": [580, 430],
Expand All @@ -28,4 +29,4 @@
"boyfriend": "bf-pixel",
"gf": "gf-pixel"
}
}
}
3 changes: 2 additions & 1 deletion assets/base_game/shared/stages/schoolEvil.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"directory": "week6",
"defaultZoom": 1.05,
"stageUI": "pixel",
"introSounds": ["intro3-pixel", "intro2-pixel", "intro1-pixel", "introGo-pixel"],

"boyfriend": [970, 320],
"girlfriend": [580, 430],
Expand All @@ -24,4 +25,4 @@
"boyfriend": "bf-pixel",
"gf": "gf-pixel"
}
}
}
3 changes: 2 additions & 1 deletion assets/base_game/shared/stages/spooky.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"directory": "week2",
"defaultZoom": 1.05,
"stageUI": "",
"introSounds": ["intro3", "intro2", "intro1", "introGo"],

"boyfriend": [770, 100],
"girlfriend": [400, 130],
Expand All @@ -23,4 +24,4 @@
"boyfriend": "bf",
"gf": "gf"
}
}
}
3 changes: 2 additions & 1 deletion assets/base_game/shared/stages/stage.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"directory": "week1",
"defaultZoom": 0.9,
"stageUI": "",
"introSounds": ["intro3", "intro2", "intro1", "introGo"],

"boyfriend": [770, 100],
"girlfriend": [400, 130],
Expand All @@ -25,4 +26,4 @@
"boyfriend": "bf",
"gf": "gf"
}
}
}
3 changes: 2 additions & 1 deletion assets/base_game/shared/stages/tank.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"directory": "week7",
"defaultZoom": 0.9,
"stageUI": "",
"introSounds": ["intro3", "intro2", "intro1", "introGo"],

"boyfriend": [810, 100],
"girlfriend": [200, 65],
Expand Down Expand Up @@ -31,4 +32,4 @@
"boyfriend": "bf",
"gf": "gf-tankmen"
}
}
}
14 changes: 14 additions & 0 deletions source/backend/CoolUtil.hx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,20 @@ class CoolUtil
inline public static function capitalize(text:String)
return text.charAt(0).toUpperCase() + text.substr(1).toLowerCase();

/**
* Plays a sound safely by checking if it exists or not.
*
* made to play some sounds in-game with no concerns as to whether it will crash or not.
*
* this is safer than calling Paths.sound due to an extra check
* @param sound The sound stream (i.e: String, openfl.media.Sound, etc)
* @param volume Sound's volume
**/
public static function playSoundSafe(sound:flixel.system.FlxAssets.FlxSoundAsset, ?beepOnError: Bool = true, volume: Float = 1.0)
{
if(sound != null) FlxG.sound.play(sound, volume);
}

inline public static function coolTextFile(path:String):Array<String>
{
var daList:String = null;
Expand Down
12 changes: 6 additions & 6 deletions source/backend/Paths.hx
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,11 @@ class Paths
return 'assets/videos/$key.$VIDEO_EXT';
}

inline static public function sound(key:String, ?modsAllowed:Bool = true):Sound
return returnSound('sounds/$key', modsAllowed);
inline static public function sound(key:String, ?modsAllowed:Bool = true, ?playBeep: Bool = true):Sound
return returnSound('sounds/$key', null, modsAllowed, playBeep);

inline static public function music(key:String, ?modsAllowed:Bool = true):Sound
return returnSound('music/$key', modsAllowed);
inline static public function music(key:String, ?modsAllowed:Bool = true, ?playBeep: Bool = true):Sound
return returnSound('music/$key', null, modsAllowed, playBeep);

inline static public function inst(song:String, ?modsAllowed:Bool = true):Sound
return returnSound('${formatToSongPath(song)}/Inst', 'songs', modsAllowed);
Expand Down Expand Up @@ -196,7 +196,7 @@ class Paths

if (bitmap == null)
{
trace('oh no its returning null NOOOO ($file)');
trace('Tried loading bitmap, caught null at "$file"');
return null;
}
}
Expand Down Expand Up @@ -244,7 +244,7 @@ class Paths
return 'assets/fonts/$key';
}

public static function fileExists(key:String, type:AssetType, ?ignoreMods:Bool = false, ?parentFolder:String = null)
public static function fileExists(key:String, ?type:AssetType = TEXT, ?ignoreMods:Bool = false, ?parentFolder:String = null)
{
#if MODS_ALLOWED
if(!ignoreMods)
Expand Down
3 changes: 3 additions & 0 deletions source/backend/StageData.hx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ typedef StageFile = {
var defaultZoom:Float;
@:optional var isPixelStage:Null<Bool>;
var stageUI:String;
@default(["intro3", "intro2", "intro1", "introGo"])
var introSounds: Array<String>;

var boyfriend:Array<Dynamic>;
var girlfriend:Array<Dynamic>;
Expand Down Expand Up @@ -42,6 +44,7 @@ class StageData {
directory: "",
defaultZoom: 0.9,
stageUI: "normal",
introSounds: ["intro3", "intro2", "intro1", "introGo"],

boyfriend: [770, 100],
girlfriend: [400, 130],
Expand Down
2 changes: 1 addition & 1 deletion source/states/MainMenuState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ class MainMenuState extends MusicBeatState
}
}
});

for (memb in menuItems)
{
if(memb == item)
Expand Down
90 changes: 56 additions & 34 deletions source/states/PlayState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ class PlayState extends MusicBeatState
private var luaDebugGroup:FlxTypedGroup<psychlua.DebugLuaText>;
#end
public var introSoundsSuffix:String = '';
public var introSoundNames:Array<String> = [];

// Less laggy controls
private var keysArray:Array<String>;
Expand Down Expand Up @@ -353,6 +354,17 @@ class PlayState extends MusicBeatState
if(girlfriendCameraOffset == null)
girlfriendCameraOffset = [0, 0];

introSoundNames = stageData.introSounds;
if(introSoundNames == null || introSoundNames.length < 4)
introSoundNames = getDefaultCountdownSounds(stageUI); // in case stageData doesn't have any sounds
for(sndName in introSoundNames) {
if(sndName == null) continue;
// trim trailing spaces in the sound, just in case, JUST in case.
var sndi: Int = introSoundNames.indexOf(sndName);
introSoundNames[sndi] = sndName.trim();
}
//trace(introSoundNames);

boyfriendGroup = new FlxSpriteGroup(BF_X, BF_Y);
dadGroup = new FlxSpriteGroup(DAD_X, DAD_Y);
gfGroup = new FlxSpriteGroup(GF_X, GF_Y);
Expand All @@ -371,7 +383,6 @@ class PlayState extends MusicBeatState
case 'phillyStreets': new PhillyStreets(); //Weekend 1 - Darnell, Lit Up, 2Hot
case 'phillyBlazin': new PhillyBlazin(); //Weekend 1 - Blazin
}
if(isPixelStage) introSoundsSuffix = '-pixel';

#if (LUA_ALLOWED || HSCRIPT_ALLOWED)
luaDebugGroup = new FlxTypedGroup<psychlua.DebugLuaText>();
Expand Down Expand Up @@ -905,28 +916,39 @@ class PlayState extends MusicBeatState
var startTimer:FlxTimer;
var finishTimer:FlxTimer = null;

// I would make a countdown class to handle this better but honestly this works fine
// it's a BIT cluttered due to everything being in playstate, but it works @crowplexus
// For being able to mess with the sprites on Lua
public var countdownReady:FlxSprite;
public var countdownSet:FlxSprite;
public var countdownGo:FlxSprite;
public var countdownPrepare:FlxSprite; // new additional sprite, for "three" sound during countdown
public var countdownReady:FlxSprite; // two
public var countdownSet:FlxSprite; // one
public var countdownGo:FlxSprite; // go

public static var startOnTime:Float = 0;

function cacheCountdown()
{
var introAssets:Map<String, Array<String>> = new Map<String, Array<String>>();
var introImagesArray:Array<String> = switch(stageUI) {
case "pixel": ['${stageUI}UI/ready-pixel', '${stageUI}UI/set-pixel', '${stageUI}UI/date-pixel'];
case "normal": ["ready", "set" ,"go"];
default: ['${stageUI}UI/ready', '${stageUI}UI/set', '${stageUI}UI/go'];
}
introAssets.set(stageUI, introImagesArray);
var introAlts:Array<String> = introAssets.get(stageUI);
for (asset in introAlts) Paths.image(asset);
var introSprites:Array<String> = getCountdownSpriteNames(stageUI);
for (asset in introSprites) Paths.image(asset);
for (sound in introSoundNames) Paths.sound(sound + introSoundsSuffix, true, false); // this should cover backwards compat
}

Paths.sound('intro3' + introSoundsSuffix);
Paths.sound('intro2' + introSoundsSuffix);
Paths.sound('intro1' + introSoundsSuffix);
Paths.sound('introGo' + introSoundsSuffix);
function getCountdownSpriteNames(?givenUI: Null<String>):Array<String> {
if(givenUI == null) givenUI = stageUI;
return switch(givenUI) {
case "pixel": ['${givenUI}UI/ready-pixel', '${givenUI}UI/ready-pixel', '${givenUI}UI/set-pixel', '${givenUI}UI/date-pixel'];
case "normal": ["prepare", "ready", "set" ,"go"];
default: ['${givenUI}UI/prepare', '${givenUI}UI/ready', '${givenUI}UI/set', '${givenUI}UI/go'];
};
}

function getDefaultCountdownSounds(?givenUI: Null<String>):Array<String> {
// function to prevent null strings for countdown sounds, if you need to hardcode anything
// this is your place to do it
if(givenUI == null) givenUI = stageUI;
return switch(givenUI) { // add custom ones here if you need to hardcode or something
default: ["intro3", "intro2", "intro1", "introGo"];
}
}

public function startCountdown()
Expand Down Expand Up @@ -977,34 +999,27 @@ class PlayState extends MusicBeatState
{
characterBopper(tmr.loopsLeft);

var introAssets:Map<String, Array<String>> = new Map<String, Array<String>>();
var introImagesArray:Array<String> = switch(stageUI) {
case "pixel": ['${stageUI}UI/ready-pixel', '${stageUI}UI/set-pixel', '${stageUI}UI/date-pixel'];
case "normal": ["ready", "set" ,"go"];
default: ['${stageUI}UI/ready', '${stageUI}UI/set', '${stageUI}UI/go'];
}
introAssets.set(stageUI, introImagesArray);

var introAlts:Array<String> = introAssets.get(stageUI);
var introSprites:Array<String> = getCountdownSpriteNames(stageUI);
var antialias:Bool = (ClientPrefs.data.antialiasing && !isPixelStage);
var tick:Countdown = THREE;

switch (swagCounter)
{
case 0:
FlxG.sound.play(Paths.sound('intro3' + introSoundsSuffix), 0.6);
countdownPrepare = createCountdownSprite(introSprites[0], antialias);
CoolUtil.playSoundSafe(Paths.sound(introSoundNames[0] + introSoundsSuffix, true, false), 0.6);
tick = THREE;
case 1:
countdownReady = createCountdownSprite(introAlts[0], antialias);
FlxG.sound.play(Paths.sound('intro2' + introSoundsSuffix), 0.6);
countdownReady = createCountdownSprite(introSprites[1], antialias);
CoolUtil.playSoundSafe(Paths.sound(introSoundNames[1] + introSoundsSuffix, true, false), 0.6);
tick = TWO;
case 2:
countdownSet = createCountdownSprite(introAlts[1], antialias);
FlxG.sound.play(Paths.sound('intro1' + introSoundsSuffix), 0.6);
countdownSet = createCountdownSprite(introSprites[2], antialias);
CoolUtil.playSoundSafe(Paths.sound(introSoundNames[2] + introSoundsSuffix, true, false), 0.6);
tick = ONE;
case 3:
countdownGo = createCountdownSprite(introAlts[2], antialias);
FlxG.sound.play(Paths.sound('introGo' + introSoundsSuffix), 0.6);
countdownGo = createCountdownSprite(introSprites[3], antialias);
CoolUtil.playSoundSafe(Paths.sound(introSoundNames[3] + introSoundsSuffix, true, false), 0.6);
tick = GO;
case 4:
tick = START;
Expand Down Expand Up @@ -1035,7 +1050,14 @@ class PlayState extends MusicBeatState

inline private function createCountdownSprite(image:String, antialias:Bool):FlxSprite
{
var spr:FlxSprite = new FlxSprite().loadGraphic(Paths.image(image));
var countdownGraphic = Paths.image(image);
if (countdownGraphic == null) {
var dum:FlxSprite = new FlxSprite();
new FlxTimer().start(Conductor.crochet / 1000, function(_) dum.destroy());
return dum; // return an empty sprite if the image doesn't exist
}

var spr:FlxSprite = new FlxSprite().loadGraphic(countdownGraphic);
spr.cameras = [camHUD];
spr.scrollFactor.set();
spr.updateHitbox();
Expand Down
Loading
Loading