Move PlayMusicOnMapLoad to Mods.Common

This commit is contained in:
reaperrr
2014-10-04 18:50:14 +02:00
parent c741fcedec
commit 9381386b7c
3 changed files with 2 additions and 2 deletions

View File

@@ -98,6 +98,7 @@
<Compile Include="Widgets\MenuButtonWidget.cs" />
<Compile Include="Widgets\RadarWidget.cs" />
<Compile Include="Widgets\ResourceBarWidget.cs" />
<Compile Include="World\PlayMusicOnMapLoad.cs" />
<Compile Include="World\RadarPings.cs" />
<Compile Include="World\SmudgeLayer.cs" />
</ItemGroup>

View File

@@ -0,0 +1,51 @@
#region Copyright & License Information
/*
* Copyright 2007-2014 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
* see COPYING.
*/
#endregion
using System;
using OpenRA.Graphics;
using OpenRA.Traits;
namespace OpenRA.Mods.Common
{
class PlayMusicOnMapLoadInfo : ITraitInfo
{
public readonly string Music = null;
public readonly bool Loop = false;
public object Create(ActorInitializer init) { return new PlayMusicOnMapLoad(init.world, this); }
}
class PlayMusicOnMapLoad : IWorldLoaded
{
readonly PlayMusicOnMapLoadInfo info;
readonly World world;
public PlayMusicOnMapLoad(World world, PlayMusicOnMapLoadInfo info)
{
this.world = world;
this.info = info;
}
public void WorldLoaded(World world, WorldRenderer wr)
{
PlayMusic();
}
void PlayMusic()
{
var onComplete = info.Loop ? (Action)PlayMusic : () => {};
if (Game.Settings.Sound.MapMusic &&
world.Map.Rules.Music.ContainsKey(info.Music))
Sound.PlayMusicThen(world.Map.Rules.Music[info.Music], onComplete);
}
}
}