Move advanced map yaml to their own files.
This commit is contained in:
@@ -21,7 +21,7 @@ namespace OpenRA
|
|||||||
{
|
{
|
||||||
public sealed class RulesetCache
|
public sealed class RulesetCache
|
||||||
{
|
{
|
||||||
static readonly List<MiniYamlNode> NoMapRules = new List<MiniYamlNode>();
|
static readonly string[] NoMapRules = new string[0];
|
||||||
|
|
||||||
readonly ModData modData;
|
readonly ModData modData;
|
||||||
|
|
||||||
@@ -94,12 +94,12 @@ namespace OpenRA
|
|||||||
|
|
||||||
Dictionary<string, T> LoadYamlRules<T>(IReadOnlyFileSystem fileSystem,
|
Dictionary<string, T> LoadYamlRules<T>(IReadOnlyFileSystem fileSystem,
|
||||||
Dictionary<string, T> itemCache,
|
Dictionary<string, T> itemCache,
|
||||||
string[] files, List<MiniYamlNode> nodes,
|
string[] files, string[] mapFiles,
|
||||||
Func<MiniYamlNode, T> f)
|
Func<MiniYamlNode, T> f)
|
||||||
{
|
{
|
||||||
RaiseProgress();
|
RaiseProgress();
|
||||||
|
|
||||||
var inputKey = string.Concat(string.Join("|", files), "|", nodes.WriteToString());
|
var inputKey = string.Concat(string.Join("|", files.Append(mapFiles)), "|");
|
||||||
Func<MiniYamlNode, T> wrap = wkv =>
|
Func<MiniYamlNode, T> wrap = wkv =>
|
||||||
{
|
{
|
||||||
var key = inputKey + wkv.Value.ToLines(wkv.Key).JoinWith("|");
|
var key = inputKey + wkv.Value.ToLines(wkv.Key).JoinWith("|");
|
||||||
@@ -114,7 +114,7 @@ namespace OpenRA
|
|||||||
return t;
|
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);
|
.ToDictionaryWithConflictLog(n => n.Key, n => n.Value, "LoadYamlRules", null, null);
|
||||||
RaiseProgress();
|
RaiseProgress();
|
||||||
|
|
||||||
|
|||||||
@@ -100,14 +100,13 @@ namespace OpenRA.Graphics
|
|||||||
public Sequences LoadSequences(IReadOnlyFileSystem fileSystem, Map map)
|
public Sequences LoadSequences(IReadOnlyFileSystem fileSystem, Map map)
|
||||||
{
|
{
|
||||||
using (new Support.PerfTimer("LoadSequences"))
|
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
|
var nodes = MiniYaml.Merge(modData.Manifest.Sequences.Append(mapSequences)
|
||||||
.Select(s => MiniYaml.FromStream(fileSystem.Open(s)))
|
.Select(s => MiniYaml.FromStream(fileSystem.Open(s))));
|
||||||
.Append(sequenceNodes));
|
|
||||||
|
|
||||||
var items = new Dictionary<string, UnitSequences>();
|
var items = new Dictionary<string, UnitSequences>();
|
||||||
foreach (var n in nodes)
|
foreach (var n in nodes)
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ namespace OpenRA.Graphics
|
|||||||
{
|
{
|
||||||
static Dictionary<string, Dictionary<string, Voxel>> units;
|
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>>();
|
units = new Dictionary<string, Dictionary<string, Voxel>>();
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ using System.Text;
|
|||||||
using OpenRA.FileSystem;
|
using OpenRA.FileSystem;
|
||||||
using OpenRA.Graphics;
|
using OpenRA.Graphics;
|
||||||
using OpenRA.Network;
|
using OpenRA.Network;
|
||||||
|
using OpenRA.Primitives;
|
||||||
using OpenRA.Support;
|
using OpenRA.Support;
|
||||||
using OpenRA.Traits;
|
using OpenRA.Traits;
|
||||||
|
|
||||||
@@ -139,16 +140,16 @@ namespace OpenRA
|
|||||||
public Lazy<CPos[]> SpawnPoints;
|
public Lazy<CPos[]> SpawnPoints;
|
||||||
|
|
||||||
// Yaml map data
|
// Yaml map data
|
||||||
[FieldLoader.Ignore] public List<MiniYamlNode> RuleDefinitions = new List<MiniYamlNode>();
|
[FieldLoader.Ignore] public readonly string[] RuleDefinitions = { };
|
||||||
[FieldLoader.Ignore] public List<MiniYamlNode> SequenceDefinitions = new List<MiniYamlNode>();
|
[FieldLoader.Ignore] public readonly string[] SequenceDefinitions = { };
|
||||||
[FieldLoader.Ignore] public List<MiniYamlNode> VoxelSequenceDefinitions = new List<MiniYamlNode>();
|
[FieldLoader.Ignore] public readonly string[] VoxelSequenceDefinitions = { };
|
||||||
[FieldLoader.Ignore] public List<MiniYamlNode> WeaponDefinitions = new List<MiniYamlNode>();
|
[FieldLoader.Ignore] public readonly string[] WeaponDefinitions = { };
|
||||||
[FieldLoader.Ignore] public List<MiniYamlNode> VoiceDefinitions = new List<MiniYamlNode>();
|
[FieldLoader.Ignore] public readonly string[] VoiceDefinitions = { };
|
||||||
[FieldLoader.Ignore] public List<MiniYamlNode> MusicDefinitions = new List<MiniYamlNode>();
|
[FieldLoader.Ignore] public readonly string[] MusicDefinitions = { };
|
||||||
[FieldLoader.Ignore] public List<MiniYamlNode> NotificationDefinitions = new List<MiniYamlNode>();
|
[FieldLoader.Ignore] public readonly string[] NotificationDefinitions = { };
|
||||||
[FieldLoader.Ignore] public List<MiniYamlNode> TranslationDefinitions = new List<MiniYamlNode>();
|
[FieldLoader.Ignore] public readonly string[] TranslationDefinitions = { };
|
||||||
[FieldLoader.Ignore] public List<MiniYamlNode> PlayerDefinitions = new List<MiniYamlNode>();
|
|
||||||
|
|
||||||
|
[FieldLoader.Ignore] public List<MiniYamlNode> PlayerDefinitions = new List<MiniYamlNode>();
|
||||||
[FieldLoader.Ignore] public List<MiniYamlNode> ActorDefinitions = new List<MiniYamlNode>();
|
[FieldLoader.Ignore] public List<MiniYamlNode> ActorDefinitions = new List<MiniYamlNode>();
|
||||||
|
|
||||||
// Binary map data
|
// Binary map data
|
||||||
@@ -182,6 +183,13 @@ namespace OpenRA
|
|||||||
throw new InvalidOperationException("Required file {0} not present in this map".F(filename));
|
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>
|
/// <summary>
|
||||||
/// Initializes a new map created by the editor or importer.
|
/// 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.
|
/// 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();
|
return spawns.ToArray();
|
||||||
});
|
});
|
||||||
|
|
||||||
RuleDefinitions = MiniYaml.NodesOrEmpty(yaml, "Rules");
|
LoadFileList(yaml, "Rules", ref RuleDefinitions);
|
||||||
SequenceDefinitions = MiniYaml.NodesOrEmpty(yaml, "Sequences");
|
LoadFileList(yaml, "Sequences", ref SequenceDefinitions);
|
||||||
VoxelSequenceDefinitions = MiniYaml.NodesOrEmpty(yaml, "VoxelSequences");
|
LoadFileList(yaml, "VoxelSequences", ref VoxelSequenceDefinitions);
|
||||||
WeaponDefinitions = MiniYaml.NodesOrEmpty(yaml, "Weapons");
|
LoadFileList(yaml, "Weapons", ref WeaponDefinitions);
|
||||||
VoiceDefinitions = MiniYaml.NodesOrEmpty(yaml, "Voices");
|
LoadFileList(yaml, "Voices", ref VoiceDefinitions);
|
||||||
MusicDefinitions = MiniYaml.NodesOrEmpty(yaml, "Music");
|
LoadFileList(yaml, "Music", ref MusicDefinitions);
|
||||||
NotificationDefinitions = MiniYaml.NodesOrEmpty(yaml, "Notifications");
|
LoadFileList(yaml, "Notifications", ref NotificationDefinitions);
|
||||||
TranslationDefinitions = MiniYaml.NodesOrEmpty(yaml, "Translations");
|
LoadFileList(yaml, "Translations", ref TranslationDefinitions);
|
||||||
PlayerDefinitions = MiniYaml.NodesOrEmpty(yaml, "Players");
|
|
||||||
|
|
||||||
|
PlayerDefinitions = MiniYaml.NodesOrEmpty(yaml, "Players");
|
||||||
ActorDefinitions = MiniYaml.NodesOrEmpty(yaml, "Actors");
|
ActorDefinitions = MiniYaml.NodesOrEmpty(yaml, "Actors");
|
||||||
|
|
||||||
MapTiles = Exts.Lazy(LoadMapTiles);
|
MapTiles = Exts.Lazy(LoadMapTiles);
|
||||||
@@ -438,14 +446,22 @@ namespace OpenRA
|
|||||||
|
|
||||||
root.Add(new MiniYamlNode("Players", null, PlayerDefinitions));
|
root.Add(new MiniYamlNode("Players", null, PlayerDefinitions));
|
||||||
root.Add(new MiniYamlNode("Actors", null, ActorDefinitions));
|
root.Add(new MiniYamlNode("Actors", null, ActorDefinitions));
|
||||||
root.Add(new MiniYamlNode("Rules", null, RuleDefinitions));
|
|
||||||
root.Add(new MiniYamlNode("Sequences", null, SequenceDefinitions));
|
var fileFields = new[]
|
||||||
root.Add(new MiniYamlNode("VoxelSequences", null, VoxelSequenceDefinitions));
|
{
|
||||||
root.Add(new MiniYamlNode("Weapons", null, WeaponDefinitions));
|
Pair.New("Rules", RuleDefinitions),
|
||||||
root.Add(new MiniYamlNode("Voices", null, VoiceDefinitions));
|
Pair.New("Sequences", SequenceDefinitions),
|
||||||
root.Add(new MiniYamlNode("Music", null, MusicDefinitions));
|
Pair.New("VoxelSequences", VoxelSequenceDefinitions),
|
||||||
root.Add(new MiniYamlNode("Notifications", null, NotificationDefinitions));
|
Pair.New("Weapons", WeaponDefinitions),
|
||||||
root.Add(new MiniYamlNode("Translations", null, TranslationDefinitions));
|
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
|
// Saving to a new package: copy over all the content from the map
|
||||||
if (Package != null && toPackage != Package)
|
if (Package != null && toPackage != Package)
|
||||||
|
|||||||
@@ -130,9 +130,8 @@ namespace OpenRA
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var yaml = MiniYaml.Merge(Manifest.Translations
|
var yaml = MiniYaml.Merge(Manifest.Translations.Append(map.TranslationDefinitions)
|
||||||
.Select(t => MiniYaml.FromStream(ModFiles.Open(t)))
|
.Select(t => MiniYaml.FromStream(map.Open(t))));
|
||||||
.Append(map.TranslationDefinitions));
|
|
||||||
Languages = yaml.Select(t => t.Key).ToArray();
|
Languages = yaml.Select(t => t.Key).ToArray();
|
||||||
|
|
||||||
foreach (var y in yaml)
|
foreach (var y in yaml)
|
||||||
@@ -183,7 +182,7 @@ namespace OpenRA
|
|||||||
foreach (var entry in map.Rules.Music)
|
foreach (var entry in map.Rules.Music)
|
||||||
entry.Value.Load(map);
|
entry.Value.Load(map);
|
||||||
|
|
||||||
VoxelProvider.Initialize(VoxelLoader, map, Manifest.VoxelSequences, map.VoxelSequenceDefinitions);
|
VoxelProvider.Initialize(VoxelLoader, map, Manifest.VoxelSequences.Append(map.VoxelSequenceDefinitions));
|
||||||
VoxelLoader.Finish();
|
VoxelLoader.Finish();
|
||||||
|
|
||||||
return map;
|
return map;
|
||||||
|
|||||||
@@ -32,8 +32,8 @@ namespace OpenRA.Mods.Common.Lint
|
|||||||
var modData = Game.ModData;
|
var modData = Game.ModData;
|
||||||
this.emitError = emitError;
|
this.emitError = emitError;
|
||||||
|
|
||||||
var sequenceSource = map != null ? map.SequenceDefinitions : new List<MiniYamlNode>();
|
var mapSequences = map != null ? map.SequenceDefinitions : new string[0];
|
||||||
sequenceDefinitions = MiniYaml.Merge(modData.Manifest.Sequences.Select(s => MiniYaml.FromStream(map.Open(s))).Append(sequenceSource));
|
sequenceDefinitions = MiniYaml.Merge(modData.Manifest.Sequences.Append(mapSequences).Select(s => MiniYaml.FromStream(map.Open(s))));
|
||||||
|
|
||||||
var rules = map == null ? modData.DefaultRules : map.Rules;
|
var rules = map == null ? modData.DefaultRules : map.Rules;
|
||||||
var factions = rules.Actors["world"].TraitInfos<FactionInfo>().Select(f => f.InternalName).ToArray();
|
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 ModData ModData;
|
||||||
public Map Map;
|
public Map Map;
|
||||||
|
public IReadWritePackage Package;
|
||||||
public List<string> Players = new List<string>();
|
public List<string> Players = new List<string>();
|
||||||
public MapPlayers MapPlayers;
|
public MapPlayers MapPlayers;
|
||||||
public MiniYaml Rules = new MiniYaml("");
|
public MiniYaml Rules = new MiniYaml("");
|
||||||
@@ -51,6 +52,8 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
|||||||
Game.ModData = modData;
|
Game.ModData = modData;
|
||||||
|
|
||||||
var filename = args[1];
|
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))
|
using (var stream = modData.DefaultFileSystem.Open(filename))
|
||||||
{
|
{
|
||||||
var file = new IniFile(stream);
|
var file = new IniFile(stream);
|
||||||
@@ -79,7 +82,7 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
|||||||
|
|
||||||
ReadActors(file);
|
ReadActors(file);
|
||||||
|
|
||||||
LoadSmudges(file, "SMUDGE", MapSize, Map);
|
LoadSmudges(file, "SMUDGE");
|
||||||
|
|
||||||
var waypoints = file.GetSection("Waypoints");
|
var waypoints = file.GetSection("Waypoints");
|
||||||
LoadWaypoints(Map, waypoints, MapSize);
|
LoadWaypoints(Map, waypoints, MapSize);
|
||||||
@@ -93,11 +96,16 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
|||||||
|
|
||||||
Map.FixOpenAreas();
|
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 rulesText = Rules.Nodes.ToLines(false).JoinWith("\n");
|
||||||
var package = new ZipFile(modData.ModFiles, dest, true);
|
Package.Update("rules.yaml", System.Text.Encoding.ASCII.GetBytes(rulesText));
|
||||||
Map.Save(package);
|
}
|
||||||
|
|
||||||
|
Map.Save(Package);
|
||||||
Console.WriteLine(dest + " saved.");
|
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 scorches = new List<MiniYamlNode>();
|
||||||
var craters = new List<MiniYamlNode>();
|
var craters = new List<MiniYamlNode>();
|
||||||
@@ -281,7 +289,7 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
|||||||
var parts = s.Value.Split(',');
|
var parts = s.Value.Split(',');
|
||||||
var loc = Exts.ParseIntegerInvariant(parts[1]);
|
var loc = Exts.ParseIntegerInvariant(parts[1]);
|
||||||
var type = parts[0].ToLowerInvariant();
|
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 value = "{0},{1}".F(type, parts[2]);
|
||||||
var node = new MiniYamlNode(key, value);
|
var node = new MiniYamlNode(key, value);
|
||||||
if (type.StartsWith("sc"))
|
if (type.StartsWith("sc"))
|
||||||
@@ -290,7 +298,10 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
|||||||
craters.Add(node);
|
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())
|
if (scorches.Any())
|
||||||
{
|
{
|
||||||
var initialScorches = new MiniYamlNode("InitialSmudges", new MiniYaml("", scorches));
|
var initialScorches = new MiniYamlNode("InitialSmudges", new MiniYaml("", scorches));
|
||||||
@@ -305,8 +316,8 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
|||||||
worldNode.Value.Nodes.Add(smudgeLayer);
|
worldNode.Value.Nodes.Add(smudgeLayer);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (worldNode.Value.Nodes.Any())
|
if (worldNode.Value.Nodes.Any() && !Rules.Nodes.Contains(worldNode))
|
||||||
map.RuleDefinitions.Add(worldNode);
|
Rules.Nodes.Add(worldNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: fix this -- will have bitrotted pretty badly.
|
// TODO: fix this -- will have bitrotted pretty badly.
|
||||||
|
|||||||
@@ -25,6 +25,21 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
|||||||
return args.Length >= 3;
|
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)
|
public static void UpgradeMap(ModData modData, IReadWritePackage package, int engineDate)
|
||||||
{
|
{
|
||||||
UpgradeRules.UpgradeMapFormat(modData, package);
|
UpgradeRules.UpgradeMapFormat(modData, package);
|
||||||
@@ -37,8 +52,8 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
|||||||
}
|
}
|
||||||
|
|
||||||
var map = new Map(modData, package);
|
var map = new Map(modData, package);
|
||||||
UpgradeRules.UpgradeWeaponRules(engineDate, ref map.WeaponDefinitions, null, 0);
|
ProcessYaml(map, map.WeaponDefinitions, engineDate, UpgradeRules.UpgradeWeaponRules);
|
||||||
UpgradeRules.UpgradeActorRules(engineDate, ref map.RuleDefinitions, null, 0);
|
ProcessYaml(map, map.RuleDefinitions, engineDate, UpgradeRules.UpgradeActorRules);
|
||||||
UpgradeRules.UpgradePlayers(engineDate, ref map.PlayerDefinitions, null, 0);
|
UpgradeRules.UpgradePlayers(engineDate, ref map.PlayerDefinitions, null, 0);
|
||||||
UpgradeRules.UpgradeActors(engineDate, ref map.ActorDefinitions, null, 0);
|
UpgradeRules.UpgradeActors(engineDate, ref map.ActorDefinitions, null, 0);
|
||||||
map.Save(package);
|
map.Save(package);
|
||||||
|
|||||||
@@ -165,6 +165,8 @@ namespace OpenRA.Mods.TS.UtilityCommands
|
|||||||
var filename = args[1];
|
var filename = args[1];
|
||||||
var file = new IniFile(File.Open(args[1], FileMode.Open));
|
var file = new IniFile(File.Open(args[1], FileMode.Open));
|
||||||
var map = GenerateMapHeader(filename, file, modData);
|
var map = GenerateMapHeader(filename, file, modData);
|
||||||
|
var dest = Path.GetFileNameWithoutExtension(args[1]) + ".oramap";
|
||||||
|
var package = new ZipFile(modData.DefaultFileSystem, dest, true);
|
||||||
|
|
||||||
ReadTiles(map, file);
|
ReadTiles(map, file);
|
||||||
ReadActors(map, file, "Structures");
|
ReadActors(map, file, "Structures");
|
||||||
@@ -173,13 +175,11 @@ namespace OpenRA.Mods.TS.UtilityCommands
|
|||||||
ReadTerrainActors(map, file);
|
ReadTerrainActors(map, file);
|
||||||
ReadWaypoints(map, file);
|
ReadWaypoints(map, file);
|
||||||
ReadOverlay(map, file);
|
ReadOverlay(map, file);
|
||||||
ReadLighting(map, file);
|
ReadLighting(map, package, file);
|
||||||
|
|
||||||
var mapPlayers = new MapPlayers(map.Rules, spawnCount);
|
var mapPlayers = new MapPlayers(map.Rules, spawnCount);
|
||||||
map.PlayerDefinitions = mapPlayers.ToMiniYaml();
|
map.PlayerDefinitions = mapPlayers.ToMiniYaml();
|
||||||
|
|
||||||
var dest = Path.GetFileNameWithoutExtension(args[1]) + ".oramap";
|
|
||||||
var package = new ZipFile(modData.DefaultFileSystem, dest, true);
|
|
||||||
map.Save(package);
|
map.Save(package);
|
||||||
Console.WriteLine(dest + " saved.");
|
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 lightingTypes = new[] { "Red", "Green", "Blue", "Ambient" };
|
||||||
var lightingSection = file.GetSection("Lighting");
|
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)
|
foreach (var kv in lightingSection)
|
||||||
{
|
{
|
||||||
if (lightingTypes.Contains(kv.Key))
|
if (lightingTypes.Contains(kv.Key))
|
||||||
{
|
{
|
||||||
var val = FieldLoader.GetValue<float>(kv.Key, kv.Value);
|
var val = FieldLoader.GetValue<float>(kv.Key, kv.Value);
|
||||||
if (val != 1.0f)
|
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
|
else
|
||||||
Console.WriteLine("Ignoring unknown lighting type: `{0}`".F(kv.Key));
|
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>()
|
// HACK: bypassing the readonly modifier here is still better than leaving this mutable by everyone
|
||||||
{
|
typeof(Map).GetField("RuleDefinitions").SetValue(map, new[] { "rules.yaml" });
|
||||||
new MiniYamlNode("GlobalLightingPaletteEffect", new MiniYaml("", lightingNodes))
|
|
||||||
})));
|
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