Add lua support for playing background music
This commit is contained in:
@@ -95,6 +95,18 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
playlist.Play(musicInfo);
|
||||
}
|
||||
|
||||
[Desc("Play track defined in music.yaml or map.yaml as background music." +
|
||||
" If music is already playing use Media.StopMusic() to stop it" +
|
||||
" and the background music will start automatically." +
|
||||
" Keep the track empty to disable background music.")]
|
||||
public void SetBackgroundMusic(string track = null)
|
||||
{
|
||||
if (!playlist.IsMusicAvailable)
|
||||
return;
|
||||
|
||||
playlist.SetBackgroundMusic(string.IsNullOrEmpty(track) ? null : world.Map.Rules.Music[track]);
|
||||
}
|
||||
|
||||
[Desc("Stop the current song.")]
|
||||
public void StopMusic()
|
||||
{
|
||||
|
||||
@@ -168,6 +168,14 @@ namespace OpenRA.Mods.Common.Traits
|
||||
Game.Sound.PlayMusicThen(music, onComplete);
|
||||
}
|
||||
|
||||
public void SetBackgroundMusic(MusicInfo music)
|
||||
{
|
||||
currentBackgroundSong = music;
|
||||
|
||||
if (CurrentSongIsBackground)
|
||||
Stop();
|
||||
}
|
||||
|
||||
public MusicInfo GetNextSong()
|
||||
{
|
||||
return GetSong(false);
|
||||
|
||||
Reference in New Issue
Block a user