Move advanced map yaml to their own files.
This commit is contained in:
@@ -21,7 +21,7 @@ namespace OpenRA
|
||||
{
|
||||
public sealed class RulesetCache
|
||||
{
|
||||
static readonly List<MiniYamlNode> NoMapRules = new List<MiniYamlNode>();
|
||||
static readonly string[] NoMapRules = new string[0];
|
||||
|
||||
readonly ModData modData;
|
||||
|
||||
@@ -94,12 +94,12 @@ namespace OpenRA
|
||||
|
||||
Dictionary<string, T> LoadYamlRules<T>(IReadOnlyFileSystem fileSystem,
|
||||
Dictionary<string, T> itemCache,
|
||||
string[] files, List<MiniYamlNode> nodes,
|
||||
string[] files, string[] mapFiles,
|
||||
Func<MiniYamlNode, T> f)
|
||||
{
|
||||
RaiseProgress();
|
||||
|
||||
var inputKey = string.Concat(string.Join("|", files), "|", nodes.WriteToString());
|
||||
var inputKey = string.Concat(string.Join("|", files.Append(mapFiles)), "|");
|
||||
Func<MiniYamlNode, T> wrap = wkv =>
|
||||
{
|
||||
var key = inputKey + wkv.Value.ToLines(wkv.Key).JoinWith("|");
|
||||
@@ -114,7 +114,7 @@ namespace OpenRA
|
||||
return t;
|
||||
};
|
||||
|
||||
var tree = MiniYaml.Merge(files.Select(s => MiniYaml.FromStream(fileSystem.Open(s))).Append(nodes))
|
||||
var tree = MiniYaml.Merge(files.Append(mapFiles).Select(s => MiniYaml.FromStream(fileSystem.Open(s))))
|
||||
.ToDictionaryWithConflictLog(n => n.Key, n => n.Value, "LoadYamlRules", null, null);
|
||||
RaiseProgress();
|
||||
|
||||
|
||||
@@ -100,14 +100,13 @@ namespace OpenRA.Graphics
|
||||
public Sequences LoadSequences(IReadOnlyFileSystem fileSystem, Map map)
|
||||
{
|
||||
using (new Support.PerfTimer("LoadSequences"))
|
||||
return Load(fileSystem, map != null ? map.SequenceDefinitions : new List<MiniYamlNode>());
|
||||
return Load(fileSystem, map != null ? map.SequenceDefinitions : new string[0]);
|
||||
}
|
||||
|
||||
Sequences Load(IReadOnlyFileSystem fileSystem, List<MiniYamlNode> sequenceNodes)
|
||||
Sequences Load(IReadOnlyFileSystem fileSystem, string[] mapSequences)
|
||||
{
|
||||
var nodes = MiniYaml.Merge(modData.Manifest.Sequences
|
||||
.Select(s => MiniYaml.FromStream(fileSystem.Open(s)))
|
||||
.Append(sequenceNodes));
|
||||
var nodes = MiniYaml.Merge(modData.Manifest.Sequences.Append(mapSequences)
|
||||
.Select(s => MiniYaml.FromStream(fileSystem.Open(s))));
|
||||
|
||||
var items = new Dictionary<string, UnitSequences>();
|
||||
foreach (var n in nodes)
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace OpenRA.Graphics
|
||||
{
|
||||
static Dictionary<string, Dictionary<string, Voxel>> units;
|
||||
|
||||
public static void Initialize(VoxelLoader loader, IReadOnlyFileSystem fileSystem, string[] voxelFiles, List<MiniYamlNode> voxelNodes)
|
||||
public static void Initialize(VoxelLoader loader, IReadOnlyFileSystem fileSystem, IEnumerable<string> voxelFiles)
|
||||
{
|
||||
units = new Dictionary<string, Dictionary<string, Voxel>>();
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ using System.Text;
|
||||
using OpenRA.FileSystem;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Network;
|
||||
using OpenRA.Primitives;
|
||||
using OpenRA.Support;
|
||||
using OpenRA.Traits;
|
||||
|
||||
@@ -139,16 +140,16 @@ namespace OpenRA
|
||||
public Lazy<CPos[]> SpawnPoints;
|
||||
|
||||
// Yaml map data
|
||||
[FieldLoader.Ignore] public List<MiniYamlNode> RuleDefinitions = new List<MiniYamlNode>();
|
||||
[FieldLoader.Ignore] public List<MiniYamlNode> SequenceDefinitions = new List<MiniYamlNode>();
|
||||
[FieldLoader.Ignore] public List<MiniYamlNode> VoxelSequenceDefinitions = new List<MiniYamlNode>();
|
||||
[FieldLoader.Ignore] public List<MiniYamlNode> WeaponDefinitions = new List<MiniYamlNode>();
|
||||
[FieldLoader.Ignore] public List<MiniYamlNode> VoiceDefinitions = new List<MiniYamlNode>();
|
||||
[FieldLoader.Ignore] public List<MiniYamlNode> MusicDefinitions = new List<MiniYamlNode>();
|
||||
[FieldLoader.Ignore] public List<MiniYamlNode> NotificationDefinitions = new List<MiniYamlNode>();
|
||||
[FieldLoader.Ignore] public List<MiniYamlNode> TranslationDefinitions = new List<MiniYamlNode>();
|
||||
[FieldLoader.Ignore] public List<MiniYamlNode> PlayerDefinitions = new List<MiniYamlNode>();
|
||||
[FieldLoader.Ignore] public readonly string[] RuleDefinitions = { };
|
||||
[FieldLoader.Ignore] public readonly string[] SequenceDefinitions = { };
|
||||
[FieldLoader.Ignore] public readonly string[] VoxelSequenceDefinitions = { };
|
||||
[FieldLoader.Ignore] public readonly string[] WeaponDefinitions = { };
|
||||
[FieldLoader.Ignore] public readonly string[] VoiceDefinitions = { };
|
||||
[FieldLoader.Ignore] public readonly string[] MusicDefinitions = { };
|
||||
[FieldLoader.Ignore] public readonly string[] NotificationDefinitions = { };
|
||||
[FieldLoader.Ignore] public readonly string[] TranslationDefinitions = { };
|
||||
|
||||
[FieldLoader.Ignore] public List<MiniYamlNode> PlayerDefinitions = new List<MiniYamlNode>();
|
||||
[FieldLoader.Ignore] public List<MiniYamlNode> ActorDefinitions = new List<MiniYamlNode>();
|
||||
|
||||
// Binary map data
|
||||
@@ -182,6 +183,13 @@ namespace OpenRA
|
||||
throw new InvalidOperationException("Required file {0} not present in this map".F(filename));
|
||||
}
|
||||
|
||||
void LoadFileList(MiniYaml yaml, string section, ref string[] files)
|
||||
{
|
||||
MiniYamlNode node;
|
||||
if ((node = yaml.Nodes.FirstOrDefault(n => n.Key == section)) != null)
|
||||
files = FieldLoader.GetValue<string[]>(section, node.Value.Value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new map created by the editor or importer.
|
||||
/// The map will not receive a valid UID until after it has been saved and reloaded.
|
||||
@@ -251,16 +259,16 @@ namespace OpenRA
|
||||
return spawns.ToArray();
|
||||
});
|
||||
|
||||
RuleDefinitions = MiniYaml.NodesOrEmpty(yaml, "Rules");
|
||||
SequenceDefinitions = MiniYaml.NodesOrEmpty(yaml, "Sequences");
|
||||
VoxelSequenceDefinitions = MiniYaml.NodesOrEmpty(yaml, "VoxelSequences");
|
||||
WeaponDefinitions = MiniYaml.NodesOrEmpty(yaml, "Weapons");
|
||||
VoiceDefinitions = MiniYaml.NodesOrEmpty(yaml, "Voices");
|
||||
MusicDefinitions = MiniYaml.NodesOrEmpty(yaml, "Music");
|
||||
NotificationDefinitions = MiniYaml.NodesOrEmpty(yaml, "Notifications");
|
||||
TranslationDefinitions = MiniYaml.NodesOrEmpty(yaml, "Translations");
|
||||
PlayerDefinitions = MiniYaml.NodesOrEmpty(yaml, "Players");
|
||||
LoadFileList(yaml, "Rules", ref RuleDefinitions);
|
||||
LoadFileList(yaml, "Sequences", ref SequenceDefinitions);
|
||||
LoadFileList(yaml, "VoxelSequences", ref VoxelSequenceDefinitions);
|
||||
LoadFileList(yaml, "Weapons", ref WeaponDefinitions);
|
||||
LoadFileList(yaml, "Voices", ref VoiceDefinitions);
|
||||
LoadFileList(yaml, "Music", ref MusicDefinitions);
|
||||
LoadFileList(yaml, "Notifications", ref NotificationDefinitions);
|
||||
LoadFileList(yaml, "Translations", ref TranslationDefinitions);
|
||||
|
||||
PlayerDefinitions = MiniYaml.NodesOrEmpty(yaml, "Players");
|
||||
ActorDefinitions = MiniYaml.NodesOrEmpty(yaml, "Actors");
|
||||
|
||||
MapTiles = Exts.Lazy(LoadMapTiles);
|
||||
@@ -438,14 +446,22 @@ namespace OpenRA
|
||||
|
||||
root.Add(new MiniYamlNode("Players", null, PlayerDefinitions));
|
||||
root.Add(new MiniYamlNode("Actors", null, ActorDefinitions));
|
||||
root.Add(new MiniYamlNode("Rules", null, RuleDefinitions));
|
||||
root.Add(new MiniYamlNode("Sequences", null, SequenceDefinitions));
|
||||
root.Add(new MiniYamlNode("VoxelSequences", null, VoxelSequenceDefinitions));
|
||||
root.Add(new MiniYamlNode("Weapons", null, WeaponDefinitions));
|
||||
root.Add(new MiniYamlNode("Voices", null, VoiceDefinitions));
|
||||
root.Add(new MiniYamlNode("Music", null, MusicDefinitions));
|
||||
root.Add(new MiniYamlNode("Notifications", null, NotificationDefinitions));
|
||||
root.Add(new MiniYamlNode("Translations", null, TranslationDefinitions));
|
||||
|
||||
var fileFields = new[]
|
||||
{
|
||||
Pair.New("Rules", RuleDefinitions),
|
||||
Pair.New("Sequences", SequenceDefinitions),
|
||||
Pair.New("VoxelSequences", VoxelSequenceDefinitions),
|
||||
Pair.New("Weapons", WeaponDefinitions),
|
||||
Pair.New("Voices", VoiceDefinitions),
|
||||
Pair.New("Music", MusicDefinitions),
|
||||
Pair.New("Notifications", NotificationDefinitions),
|
||||
Pair.New("Translations", TranslationDefinitions)
|
||||
};
|
||||
|
||||
foreach (var kv in fileFields)
|
||||
if (kv.Second.Any())
|
||||
root.Add(new MiniYamlNode(kv.First, FieldSaver.FormatValue(kv.Second)));
|
||||
|
||||
// Saving to a new package: copy over all the content from the map
|
||||
if (Package != null && toPackage != Package)
|
||||
|
||||
@@ -130,9 +130,8 @@ namespace OpenRA
|
||||
return;
|
||||
}
|
||||
|
||||
var yaml = MiniYaml.Merge(Manifest.Translations
|
||||
.Select(t => MiniYaml.FromStream(ModFiles.Open(t)))
|
||||
.Append(map.TranslationDefinitions));
|
||||
var yaml = MiniYaml.Merge(Manifest.Translations.Append(map.TranslationDefinitions)
|
||||
.Select(t => MiniYaml.FromStream(map.Open(t))));
|
||||
Languages = yaml.Select(t => t.Key).ToArray();
|
||||
|
||||
foreach (var y in yaml)
|
||||
@@ -183,7 +182,7 @@ namespace OpenRA
|
||||
foreach (var entry in map.Rules.Music)
|
||||
entry.Value.Load(map);
|
||||
|
||||
VoxelProvider.Initialize(VoxelLoader, map, Manifest.VoxelSequences, map.VoxelSequenceDefinitions);
|
||||
VoxelProvider.Initialize(VoxelLoader, map, Manifest.VoxelSequences.Append(map.VoxelSequenceDefinitions));
|
||||
VoxelLoader.Finish();
|
||||
|
||||
return map;
|
||||
|
||||
Reference in New Issue
Block a user