#1050 Extract generic PlayMusicOnMapLoad trait from cnc shellmap script

This commit is contained in:
Chris Forbes
2011-08-16 18:00:21 +12:00
parent c47833e9a0
commit 55ec88316a
4 changed files with 52 additions and 24 deletions

View File

@@ -0,0 +1,45 @@
#region Copyright & License Information
/*
* Copyright 2007-2011 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 System.Collections.Generic;
using OpenRA.FileFormats;
using OpenRA.Traits;
using OpenRA.Widgets;
namespace OpenRA.Mods.RA
{
class PlayMusicOnMapLoadInfo : ITraitInfo
{
public readonly string Music = null;
public readonly bool Loop = false;
public object Create(ActorInitializer init) { return new PlayMusicOnMapLoad(this); }
}
class PlayMusicOnMapLoad : IWorldLoaded
{
PlayMusicOnMapLoadInfo Info;
public PlayMusicOnMapLoad(PlayMusicOnMapLoadInfo info) { Info = info; }
public void WorldLoaded(World w) { PlayMusic(); }
void PlayMusic()
{
var onComplete = Info.Loop ? (Action)PlayMusic : () => {};
if (Game.Settings.Game.ShellmapMusic &&
Rules.Music.ContainsKey(Info.Music))
Sound.PlayMusicThen(Rules.Music[Info.Music], onComplete);
}
}
}