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;
|
||||
|
||||
@@ -32,8 +32,8 @@ namespace OpenRA.Mods.Common.Lint
|
||||
var modData = Game.ModData;
|
||||
this.emitError = emitError;
|
||||
|
||||
var sequenceSource = map != null ? map.SequenceDefinitions : new List<MiniYamlNode>();
|
||||
sequenceDefinitions = MiniYaml.Merge(modData.Manifest.Sequences.Select(s => MiniYaml.FromStream(map.Open(s))).Append(sequenceSource));
|
||||
var mapSequences = map != null ? map.SequenceDefinitions : new string[0];
|
||||
sequenceDefinitions = MiniYaml.Merge(modData.Manifest.Sequences.Append(mapSequences).Select(s => MiniYaml.FromStream(map.Open(s))));
|
||||
|
||||
var rules = map == null ? modData.DefaultRules : map.Rules;
|
||||
var factions = rules.Actors["world"].TraitInfos<FactionInfo>().Select(f => f.InternalName).ToArray();
|
||||
|
||||
@@ -33,6 +33,7 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
||||
|
||||
public ModData ModData;
|
||||
public Map Map;
|
||||
public IReadWritePackage Package;
|
||||
public List<string> Players = new List<string>();
|
||||
public MapPlayers MapPlayers;
|
||||
public MiniYaml Rules = new MiniYaml("");
|
||||
@@ -51,6 +52,8 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
||||
Game.ModData = modData;
|
||||
|
||||
var filename = args[1];
|
||||
var dest = Path.GetFileNameWithoutExtension(args[1]) + ".oramap";
|
||||
Package = new ZipFile(modData.ModFiles, dest, true);
|
||||
using (var stream = modData.DefaultFileSystem.Open(filename))
|
||||
{
|
||||
var file = new IniFile(stream);
|
||||
@@ -79,7 +82,7 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
||||
|
||||
ReadActors(file);
|
||||
|
||||
LoadSmudges(file, "SMUDGE", MapSize, Map);
|
||||
LoadSmudges(file, "SMUDGE");
|
||||
|
||||
var waypoints = file.GetSection("Waypoints");
|
||||
LoadWaypoints(Map, waypoints, MapSize);
|
||||
@@ -93,11 +96,16 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
||||
|
||||
Map.FixOpenAreas();
|
||||
|
||||
Map.RuleDefinitions = Rules.Nodes;
|
||||
if (Rules.Nodes.Any())
|
||||
{
|
||||
// HACK: bypassing the readonly modifier here is still better than leaving this mutable by everyone
|
||||
typeof(Map).GetField("RuleDefinitions").SetValue(Map, new[] { "rules.yaml" });
|
||||
|
||||
var dest = Path.GetFileNameWithoutExtension(args[1]) + ".oramap";
|
||||
var package = new ZipFile(modData.ModFiles, dest, true);
|
||||
Map.Save(package);
|
||||
var rulesText = Rules.Nodes.ToLines(false).JoinWith("\n");
|
||||
Package.Update("rules.yaml", System.Text.Encoding.ASCII.GetBytes(rulesText));
|
||||
}
|
||||
|
||||
Map.Save(Package);
|
||||
Console.WriteLine(dest + " saved.");
|
||||
}
|
||||
|
||||
@@ -271,7 +279,7 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
||||
}
|
||||
}
|
||||
|
||||
static void LoadSmudges(IniFile file, string section, int mapSize, Map map)
|
||||
void LoadSmudges(IniFile file, string section)
|
||||
{
|
||||
var scorches = new List<MiniYamlNode>();
|
||||
var craters = new List<MiniYamlNode>();
|
||||
@@ -281,7 +289,7 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
||||
var parts = s.Value.Split(',');
|
||||
var loc = Exts.ParseIntegerInvariant(parts[1]);
|
||||
var type = parts[0].ToLowerInvariant();
|
||||
var key = "{0},{1}".F(loc % mapSize, loc / mapSize);
|
||||
var key = "{0},{1}".F(loc % MapSize, loc / MapSize);
|
||||
var value = "{0},{1}".F(type, parts[2]);
|
||||
var node = new MiniYamlNode(key, value);
|
||||
if (type.StartsWith("sc"))
|
||||
@@ -290,7 +298,10 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
||||
craters.Add(node);
|
||||
}
|
||||
|
||||
var worldNode = new MiniYamlNode("World", new MiniYaml("", new List<MiniYamlNode>()));
|
||||
var worldNode = Rules.Nodes.FirstOrDefault(n => n.Key == "World");
|
||||
if (worldNode == null)
|
||||
worldNode = new MiniYamlNode("World", new MiniYaml("", new List<MiniYamlNode>()));
|
||||
|
||||
if (scorches.Any())
|
||||
{
|
||||
var initialScorches = new MiniYamlNode("InitialSmudges", new MiniYaml("", scorches));
|
||||
@@ -305,8 +316,8 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
||||
worldNode.Value.Nodes.Add(smudgeLayer);
|
||||
}
|
||||
|
||||
if (worldNode.Value.Nodes.Any())
|
||||
map.RuleDefinitions.Add(worldNode);
|
||||
if (worldNode.Value.Nodes.Any() && !Rules.Nodes.Contains(worldNode))
|
||||
Rules.Nodes.Add(worldNode);
|
||||
}
|
||||
|
||||
// TODO: fix this -- will have bitrotted pretty badly.
|
||||
|
||||
@@ -25,6 +25,21 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
||||
return args.Length >= 3;
|
||||
}
|
||||
|
||||
delegate void UpgradeAction(int engineVersion, ref List<MiniYamlNode> nodes, MiniYamlNode parent, int depth);
|
||||
|
||||
static void ProcessYaml(Map map, IEnumerable<string> files, int engineDate, UpgradeAction processFile)
|
||||
{
|
||||
foreach (var filename in files)
|
||||
{
|
||||
if (!map.Package.Contains(filename))
|
||||
continue;
|
||||
|
||||
var yaml = MiniYaml.FromStream(map.Package.GetStream(filename));
|
||||
processFile(engineDate, ref yaml, null, 0);
|
||||
((IReadWritePackage)map.Package).Update(filename, Encoding.ASCII.GetBytes(yaml.WriteToString()));
|
||||
}
|
||||
}
|
||||
|
||||
public static void UpgradeMap(ModData modData, IReadWritePackage package, int engineDate)
|
||||
{
|
||||
UpgradeRules.UpgradeMapFormat(modData, package);
|
||||
@@ -37,8 +52,8 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
||||
}
|
||||
|
||||
var map = new Map(modData, package);
|
||||
UpgradeRules.UpgradeWeaponRules(engineDate, ref map.WeaponDefinitions, null, 0);
|
||||
UpgradeRules.UpgradeActorRules(engineDate, ref map.RuleDefinitions, null, 0);
|
||||
ProcessYaml(map, map.WeaponDefinitions, engineDate, UpgradeRules.UpgradeWeaponRules);
|
||||
ProcessYaml(map, map.RuleDefinitions, engineDate, UpgradeRules.UpgradeActorRules);
|
||||
UpgradeRules.UpgradePlayers(engineDate, ref map.PlayerDefinitions, null, 0);
|
||||
UpgradeRules.UpgradeActors(engineDate, ref map.ActorDefinitions, null, 0);
|
||||
map.Save(package);
|
||||
|
||||
@@ -165,6 +165,8 @@ namespace OpenRA.Mods.TS.UtilityCommands
|
||||
var filename = args[1];
|
||||
var file = new IniFile(File.Open(args[1], FileMode.Open));
|
||||
var map = GenerateMapHeader(filename, file, modData);
|
||||
var dest = Path.GetFileNameWithoutExtension(args[1]) + ".oramap";
|
||||
var package = new ZipFile(modData.DefaultFileSystem, dest, true);
|
||||
|
||||
ReadTiles(map, file);
|
||||
ReadActors(map, file, "Structures");
|
||||
@@ -173,13 +175,11 @@ namespace OpenRA.Mods.TS.UtilityCommands
|
||||
ReadTerrainActors(map, file);
|
||||
ReadWaypoints(map, file);
|
||||
ReadOverlay(map, file);
|
||||
ReadLighting(map, file);
|
||||
ReadLighting(map, package, file);
|
||||
|
||||
var mapPlayers = new MapPlayers(map.Rules, spawnCount);
|
||||
map.PlayerDefinitions = mapPlayers.ToMiniYaml();
|
||||
|
||||
var dest = Path.GetFileNameWithoutExtension(args[1]) + ".oramap";
|
||||
var package = new ZipFile(modData.DefaultFileSystem, dest, true);
|
||||
map.Save(package);
|
||||
Console.WriteLine(dest + " saved.");
|
||||
}
|
||||
@@ -431,29 +431,32 @@ namespace OpenRA.Mods.TS.UtilityCommands
|
||||
}
|
||||
}
|
||||
|
||||
void ReadLighting(Map map, IniFile file)
|
||||
void ReadLighting(Map map, IReadWritePackage package, IniFile file)
|
||||
{
|
||||
var lightingTypes = new[] { "Red", "Green", "Blue", "Ambient" };
|
||||
var lightingSection = file.GetSection("Lighting");
|
||||
var lightingNodes = new List<MiniYamlNode>();
|
||||
var lightingNode = new MiniYamlNode("GlobalLightingPaletteEffect", new MiniYaml("", new List<MiniYamlNode>()));
|
||||
var worldNode = new MiniYamlNode("World", new MiniYaml("", new List<MiniYamlNode>() { lightingNode }));
|
||||
|
||||
foreach (var kv in lightingSection)
|
||||
{
|
||||
if (lightingTypes.Contains(kv.Key))
|
||||
{
|
||||
var val = FieldLoader.GetValue<float>(kv.Key, kv.Value);
|
||||
if (val != 1.0f)
|
||||
lightingNodes.Add(new MiniYamlNode(kv.Key, FieldSaver.FormatValue(val)));
|
||||
lightingNode.Value.Nodes.Add(new MiniYamlNode(kv.Key, FieldSaver.FormatValue(val)));
|
||||
}
|
||||
else
|
||||
Console.WriteLine("Ignoring unknown lighting type: `{0}`".F(kv.Key));
|
||||
}
|
||||
|
||||
if (lightingNodes.Any())
|
||||
if (lightingNode.Value.Nodes.Any())
|
||||
{
|
||||
map.RuleDefinitions.Add(new MiniYamlNode("World", new MiniYaml("", new List<MiniYamlNode>()
|
||||
{
|
||||
new MiniYamlNode("GlobalLightingPaletteEffect", new MiniYaml("", lightingNodes))
|
||||
})));
|
||||
// HACK: bypassing the readonly modifier here is still better than leaving this mutable by everyone
|
||||
typeof(Map).GetField("RuleDefinitions").SetValue(map, new[] { "rules.yaml" });
|
||||
|
||||
var rulesText = new List<MiniYamlNode>() { worldNode }.ToLines(false).JoinWith("\n");
|
||||
package.Update("rules.yaml", System.Text.Encoding.ASCII.GetBytes(rulesText));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user