Skip to content

Commit

Permalink
Fix music choice per level
Browse files Browse the repository at this point in the history
  • Loading branch information
Vanilagy committed Oct 14, 2020
1 parent af0cb6b commit 09c0eff
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/ts/level.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import { PhysicsHelper } from "./physics";
import { ParticleManager } from "./particles";
import { StorageManager } from "./storage";
import { Replay } from "./replay";
import { getCurrentLevelArray } from "./ui/level_select";

/** How often the physics will be updated, per second. */
export const PHYSICS_TICK_RATE = 120;
Expand Down Expand Up @@ -306,11 +307,8 @@ export class Level extends Scheduler {
}

async initSounds() {
let missionInfo = this.mission.elements.find((element) => element._type === MissionElementType.ScriptObject && element._subtype === "MissionInfo") as MissionElementScriptObject;
let musicProfile = this.mission.elements.find((element) => element._type === MissionElementType.AudioProfile && element.description === "AudioMusic") as MissionElementAudioProfile;
let musicFileName = musicProfile.filename.slice(musicProfile.filename.lastIndexOf('/') + 1).toLowerCase();
// If the song is Shell, then choose the music based on the index of the level.
if (musicFileName.includes('shell')) musicFileName = ['groovepolice.ogg', 'classic vibe.ogg', 'beach party.ogg'][Number(missionInfo.level) % 3];
let levelIndex = getCurrentLevelArray().findIndex(x => x.simGroup === this.mission);
let musicFileName = ['groovepolice.ogg', 'classic vibe.ogg', 'beach party.ogg'][(levelIndex + 1) % 3]; // The music choice is based off of level index

await AudioManager.loadBuffers(["spawn.wav", "ready.wav", "set.wav", "go.wav", "whoosh.wav", "timetravelactive.wav", "infotutorial.wav", musicFileName]);
this.music = AudioManager.createAudioSource(musicFileName, AudioManager.musicGain);
Expand Down

0 comments on commit 09c0eff

Please sign in to comment.