Extract default TileSet/Sequence dictionaries to ModData.

This commit is contained in:
Paul Chote
2016-03-11 18:08:23 +00:00
parent c32bf9f8f7
commit a3b1baa654
16 changed files with 61 additions and 50 deletions

View File

@@ -24,8 +24,8 @@ namespace OpenRA
public readonly IReadOnlyDictionary<string, SoundInfo> Voices;
public readonly IReadOnlyDictionary<string, SoundInfo> Notifications;
public readonly IReadOnlyDictionary<string, MusicInfo> Music;
public readonly IReadOnlyDictionary<string, TileSet> TileSets;
public readonly IReadOnlyDictionary<string, SequenceProvider> Sequences;
public readonly TileSet TileSet;
public readonly SequenceProvider Sequences;
public Ruleset(
IDictionary<string, ActorInfo> actors,
@@ -33,16 +33,16 @@ namespace OpenRA
IDictionary<string, SoundInfo> voices,
IDictionary<string, SoundInfo> notifications,
IDictionary<string, MusicInfo> music,
IDictionary<string, TileSet> tileSets,
IDictionary<string, SequenceProvider> sequences)
TileSet tileSet,
SequenceProvider sequences)
{
Actors = new ReadOnlyDictionary<string, ActorInfo>(actors);
Weapons = new ReadOnlyDictionary<string, WeaponInfo>(weapons);
Voices = new ReadOnlyDictionary<string, SoundInfo>(voices);
Notifications = new ReadOnlyDictionary<string, SoundInfo>(notifications);
Music = new ReadOnlyDictionary<string, MusicInfo>(music);
TileSets = new ReadOnlyDictionary<string, TileSet>(tileSets);
Sequences = new ReadOnlyDictionary<string, SequenceProvider>(sequences);
TileSet = tileSet;
Sequences = sequences;
foreach (var a in Actors.Values)
{

View File

@@ -28,7 +28,6 @@ namespace OpenRA
readonly Dictionary<string, SoundInfo> voiceCache = new Dictionary<string, SoundInfo>();
readonly Dictionary<string, SoundInfo> notificationCache = new Dictionary<string, SoundInfo>();
readonly Dictionary<string, MusicInfo> musicCache = new Dictionary<string, MusicInfo>();
readonly Dictionary<string, TileSet> tileSetCache = new Dictionary<string, TileSet>();
public event EventHandler LoadingProgress;
void RaiseProgress()
@@ -43,6 +42,7 @@ namespace OpenRA
}
public Ruleset Load(IReadOnlyFileSystem fileSystem,
TileSet tileSet,
MiniYaml additionalRules,
MiniYaml additionalWeapons,
MiniYaml additionalVoices,
@@ -57,7 +57,6 @@ namespace OpenRA
Dictionary<string, SoundInfo> voices;
Dictionary<string, SoundInfo> notifications;
Dictionary<string, MusicInfo> music;
Dictionary<string, TileSet> tileSets;
using (new PerfTimer("Actors"))
actors = LoadYamlRules(fileSystem, actorCache, m.Rules, additionalRules,
@@ -79,12 +78,8 @@ namespace OpenRA
music = LoadYamlRules(fileSystem, musicCache, m.Music, additionalMusic,
k => new MusicInfo(k.Key, k.Value));
using (new PerfTimer("TileSets"))
tileSets = LoadTileSets(fileSystem, tileSetCache, m.TileSets);
// TODO: only initialize, and then cache, the provider for the given map
var sequences = tileSets.ToDictionary(t => t.Key, t => new SequenceProvider(fileSystem, modData, t.Value, additionalSequences));
return new Ruleset(actors, weapons, voices, notifications, music, tileSets, sequences);
var sequences = tileSet != null ? new SequenceProvider(fileSystem, modData, tileSet, additionalSequences) : null;
return new Ruleset(actors, weapons, voices, notifications, music, tileSet, sequences);
}
/// <summary>
@@ -93,9 +88,9 @@ namespace OpenRA
/// </summary>
public Ruleset Load(IReadOnlyFileSystem fileSystem, Map map = null)
{
return map != null ? Load(fileSystem, map.RuleDefinitions, map.WeaponDefinitions,
map.VoiceDefinitions, map.NotificationDefinitions, map.MusicDefinitions,
map.SequenceDefinitions) : Load(fileSystem, null, null, null, null, null, null);
return map != null ? Load(fileSystem, modData.DefaultTileSets[map.Tileset], map.RuleDefinitions,
map.WeaponDefinitions,map.VoiceDefinitions, map.NotificationDefinitions, map.MusicDefinitions,
map.SequenceDefinitions) : Load(fileSystem, null, null, null, null, null, null, null);
}
Dictionary<string, T> LoadYamlRules<T>(IReadOnlyFileSystem fileSystem,