Use IReadOnlyFileSystem in artwork loaders.

This commit is contained in:
Paul Chote
2016-02-15 01:04:00 +00:00
parent a1bc70cb58
commit b347fade71
15 changed files with 70 additions and 66 deletions

View File

@@ -11,6 +11,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using OpenRA.FileSystem;
using OpenRA.GameRules;
using OpenRA.Graphics;
using OpenRA.Support;
@@ -47,7 +48,7 @@ namespace OpenRA
/// Cache and return the Ruleset for a given map.
/// If a map isn't specified then return the default mod Ruleset.
/// </summary>
public Ruleset Load(Map map = null)
public Ruleset Load(IReadOnlyFileSystem fileSystem, Map map = null)
{
var m = modData.Manifest;
@@ -59,38 +60,38 @@ namespace OpenRA
Dictionary<string, TileSet> tileSets;
using (new PerfTimer("Actors"))
actors = LoadYamlRules(actorCache, m.Rules,
actors = LoadYamlRules(fileSystem, actorCache, m.Rules,
map != null ? map.RuleDefinitions : NoMapRules,
k => new ActorInfo(Game.ModData.ObjectCreator, k.Key.ToLowerInvariant(), k.Value));
using (new PerfTimer("Weapons"))
weapons = LoadYamlRules(weaponCache, m.Weapons,
weapons = LoadYamlRules(fileSystem, weaponCache, m.Weapons,
map != null ? map.WeaponDefinitions : NoMapRules,
k => new WeaponInfo(k.Key.ToLowerInvariant(), k.Value));
using (new PerfTimer("Voices"))
voices = LoadYamlRules(voiceCache, m.Voices,
voices = LoadYamlRules(fileSystem, voiceCache, m.Voices,
map != null ? map.VoiceDefinitions : NoMapRules,
k => new SoundInfo(k.Value));
using (new PerfTimer("Notifications"))
notifications = LoadYamlRules(notificationCache, m.Notifications,
notifications = LoadYamlRules(fileSystem, notificationCache, m.Notifications,
map != null ? map.NotificationDefinitions : NoMapRules,
k => new SoundInfo(k.Value));
using (new PerfTimer("Music"))
music = LoadYamlRules(musicCache, m.Music,
music = LoadYamlRules(fileSystem, musicCache, m.Music,
map != null ? map.MusicDefinitions : NoMapRules,
k => new MusicInfo(k.Key, k.Value));
using (new PerfTimer("TileSets"))
tileSets = LoadTileSets(tileSetCache, sequenceCaches, m.TileSets);
tileSets = LoadTileSets(fileSystem, tileSetCache, sequenceCaches, m.TileSets);
var sequences = sequenceCaches.ToDictionary(kvp => kvp.Key, kvp => new SequenceProvider(kvp.Value, map));
var sequences = sequenceCaches.ToDictionary(kvp => kvp.Key, kvp => new SequenceProvider(fileSystem, kvp.Value, map));
return new Ruleset(actors, weapons, voices, notifications, music, tileSets, sequences);
}
Dictionary<string, T> LoadYamlRules<T>(
Dictionary<string, T> LoadYamlRules<T>(IReadOnlyFileSystem fileSystem,
Dictionary<string, T> itemCache,
string[] files, List<MiniYamlNode> nodes,
Func<MiniYamlNode, T> f)
@@ -112,7 +113,7 @@ namespace OpenRA
return t;
};
var tree = MiniYaml.Merge(files.Select(s => MiniYaml.FromStream(modData.ModFiles.Open(s))).Append(nodes))
var tree = MiniYaml.Merge(files.Select(s => MiniYaml.FromStream(fileSystem.Open(s))).Append(nodes))
.ToDictionaryWithConflictLog(n => n.Key, n => n.Value, "LoadYamlRules", null, null);
RaiseProgress();
@@ -121,7 +122,7 @@ namespace OpenRA
return itemSet;
}
Dictionary<string, TileSet> LoadTileSets(Dictionary<string, TileSet> itemCache, Dictionary<string, SequenceCache> sequenceCaches, string[] files)
Dictionary<string, TileSet> LoadTileSets(IReadOnlyFileSystem fileSystem, Dictionary<string, TileSet> itemCache, Dictionary<string, SequenceCache> sequenceCaches, string[] files)
{
var items = new Dictionary<string, TileSet>();
@@ -136,7 +137,7 @@ namespace OpenRA
itemCache.Add(file, t);
// every time we load a tile set, we create a sequence cache for it
var sc = new SequenceCache(modData, t);
var sc = new SequenceCache(modData, fileSystem, t);
sequenceCaches.Add(t.Id, sc);
items.Add(t.Id, t);