Merge pull request #9494 from abcdefg30/luabackground
Add lua support for playing background music
This commit is contained in:
@@ -20,7 +20,6 @@ using OpenRA.Graphics;
|
|||||||
using OpenRA.Mods.Common.Effects;
|
using OpenRA.Mods.Common.Effects;
|
||||||
using OpenRA.Mods.Common.Traits;
|
using OpenRA.Mods.Common.Traits;
|
||||||
using OpenRA.Scripting;
|
using OpenRA.Scripting;
|
||||||
using OpenRA.Traits;
|
|
||||||
|
|
||||||
namespace OpenRA.Mods.Common.Scripting
|
namespace OpenRA.Mods.Common.Scripting
|
||||||
{
|
{
|
||||||
@@ -62,16 +61,8 @@ namespace OpenRA.Mods.Common.Scripting
|
|||||||
if (!playlist.IsMusicAvailable)
|
if (!playlist.IsMusicAvailable)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
MusicInfo musicInfo;
|
var musicInfo = !string.IsNullOrEmpty(track) ? GetMusicTrack(track)
|
||||||
if (string.IsNullOrEmpty(track))
|
: playlist.GetNextSong();
|
||||||
musicInfo = playlist.GetNextSong();
|
|
||||||
else if (world.Map.Rules.Music.ContainsKey(track))
|
|
||||||
musicInfo = world.Map.Rules.Music[track];
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Log.Write("lua", "Missing music track: " + track);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (func != null)
|
if (func != null)
|
||||||
{
|
{
|
||||||
@@ -95,6 +86,28 @@ namespace OpenRA.Mods.Common.Scripting
|
|||||||
playlist.Play(musicInfo);
|
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 : GetMusicTrack(track));
|
||||||
|
}
|
||||||
|
|
||||||
|
MusicInfo GetMusicTrack(string track)
|
||||||
|
{
|
||||||
|
var music = world.Map.Rules.Music;
|
||||||
|
if (music.ContainsKey(track))
|
||||||
|
return music[track];
|
||||||
|
|
||||||
|
Log.Write("lua", "Missing music track: " + track);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
[Desc("Stop the current song.")]
|
[Desc("Stop the current song.")]
|
||||||
public void StopMusic()
|
public void StopMusic()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -168,6 +168,14 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
Game.Sound.PlayMusicThen(music, onComplete);
|
Game.Sound.PlayMusicThen(music, onComplete);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void SetBackgroundMusic(MusicInfo music)
|
||||||
|
{
|
||||||
|
currentBackgroundSong = music;
|
||||||
|
|
||||||
|
if (CurrentSongIsBackground)
|
||||||
|
Stop();
|
||||||
|
}
|
||||||
|
|
||||||
public MusicInfo GetNextSong()
|
public MusicInfo GetNextSong()
|
||||||
{
|
{
|
||||||
return GetSong(false);
|
return GetSong(false);
|
||||||
|
|||||||
Reference in New Issue
Block a user