Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update uid generation to include map.png and update map format #19891

Merged
merged 5 commits into from Aug 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
30 changes: 25 additions & 5 deletions OpenRA.Game/Map/Map.cs
Expand Up @@ -15,6 +15,7 @@
using System.Linq;
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
using OpenRA.FileFormats;
using OpenRA.FileSystem;
using OpenRA.Graphics;
Expand Down Expand Up @@ -151,6 +152,7 @@ public void Serialize(Map map, List<MiniYamlNode> nodes)
public class Map : IReadOnlyFileSystem
{
public const int SupportedMapFormat = 11;
public const int CurrentMapFormat = 12;
const short InvalidCachedTerrainIndex = -1;

/// <summary>Defines the order of the fields in map.yaml</summary>
Expand Down Expand Up @@ -253,6 +255,11 @@ public class Map : IReadOnlyFileSystem
internal Translation Translation;

public static string ComputeUID(IReadOnlyPackage package)
PunkPun marked this conversation as resolved.
Show resolved Hide resolved
{
return ComputeUID(package, GetMapFormat(package));
}

static string ComputeUID(IReadOnlyPackage package, int format)
{
// UID is calculated by taking an SHA1 of the yaml and binary data
var requiredFiles = new[] { "map.yaml", "map.bin" };
Expand All @@ -265,7 +272,7 @@ public static string ComputeUID(IReadOnlyPackage package)
try
{
foreach (var filename in contents)
if (filename.EndsWith(".yaml") || filename.EndsWith(".bin") || filename.EndsWith(".lua"))
if (filename.EndsWith(".yaml") || filename.EndsWith(".bin") || filename.EndsWith(".lua") || (format >= 12 && filename == "map.png"))
streams.Add(package.GetStream(filename));

// Take the SHA1
Expand All @@ -285,6 +292,19 @@ public static string ComputeUID(IReadOnlyPackage package)
}
}

static int GetMapFormat(IReadOnlyPackage p)
{
foreach (var line in p.GetStream("map.yaml").ReadAllLines())
{
// PERF This is a way to get MapFormat without expensive yaml parsing
var search = Regex.Match(line, "^MapFormat:\\s*(\\d*)\\s*$");
if (search.Success && search.Groups.Count > 0)
return FieldLoader.GetValue<int>("MapFormat", search.Groups[1].Value);
}

throw new InvalidDataException($"MapFormat is not definedt\n File: {p.Name}");
}

PunkPun marked this conversation as resolved.
Show resolved Hide resolved
/// <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.
Expand Down Expand Up @@ -332,7 +352,7 @@ public Map(ModData modData, IReadOnlyPackage package)
foreach (var field in YamlFields)
field.Deserialize(this, yaml.Nodes);

if (MapFormat != SupportedMapFormat)
if (MapFormat < SupportedMapFormat)
throw new InvalidDataException($"Map format {MapFormat} is not supported.\n File: {package.Name}");

PlayerDefinitions = MiniYaml.NodesOrEmpty(yaml, "Players");
Expand Down Expand Up @@ -400,7 +420,7 @@ public Map(ModData modData, IReadOnlyPackage package)

PostInit();

Uid = ComputeUID(Package);
Uid = ComputeUID(Package, MapFormat);
}

void PostInit()
Expand Down Expand Up @@ -600,7 +620,7 @@ PPos[] ProjectCellInner(MPos uv)

public void Save(IReadWritePackage toPackage)
{
MapFormat = SupportedMapFormat;
MapFormat = CurrentMapFormat;

var root = new List<MiniYamlNode>();
foreach (var field in YamlFields)
Expand All @@ -625,7 +645,7 @@ public void Save(IReadWritePackage toPackage)
Package = toPackage;

// Update UID to match the newly saved data
Uid = ComputeUID(toPackage);
Uid = ComputeUID(toPackage, MapFormat);
}

public byte[] SaveBinaryData()
Expand Down
2 changes: 1 addition & 1 deletion OpenRA.Game/Map/MapPreview.cs
Expand Up @@ -320,7 +320,7 @@ public void UpdateFromMap(IReadOnlyPackage p, IReadOnlyPackage parent, MapClassi
if (yaml.TryGetValue("MapFormat", out var temp))
{
var format = FieldLoader.GetValue<int>("MapFormat", temp.Value);
if (format != Map.SupportedMapFormat)
if (format < Map.SupportedMapFormat)
throw new InvalidDataException($"Map format {format} is not supported.");
}

Expand Down
4 changes: 2 additions & 2 deletions OpenRA.Mods.Common/Lint/CheckMapMetadata.cs
Expand Up @@ -28,8 +28,8 @@ void ILintServerMapPass.Run(Action<string> emitError, Action<string> emitWarning

void Run(Action<string> emitError, int mapFormat, string author, string title, string[] categories)
{
if (mapFormat != Map.SupportedMapFormat)
emitError($"Map format {mapFormat} does not match the supported version {Map.SupportedMapFormat}.");
if (mapFormat < Map.SupportedMapFormat)
emitError($"Map format {mapFormat} does not match the supported version {Map.CurrentMapFormat}.");

if (author == null)
emitError("Map does not define a valid author.");
Expand Down
Binary file modified mods/cnc/maps/16-9.oramap
Binary file not shown.
Binary file modified mods/cnc/maps/african-gambit.oramap
Binary file not shown.
Binary file modified mods/cnc/maps/aggressive-tendencies.oramap
Binary file not shown.
Binary file modified mods/cnc/maps/alpha-juno-5.oramap
Binary file not shown.
Binary file modified mods/cnc/maps/antrax.oramap
Binary file not shown.
Binary file modified mods/cnc/maps/anvil-of-war.oramap
Binary file not shown.
Binary file modified mods/cnc/maps/arcade.oramap
Binary file not shown.
Binary file modified mods/cnc/maps/armageddon.oramap
Binary file not shown.
Binary file modified mods/cnc/maps/axis-of-advance.oramap
Binary file not shown.
Binary file modified mods/cnc/maps/back-to-basics.oramap
Binary file not shown.
Binary file modified mods/cnc/maps/badland-ridges.oramap
Binary file not shown.
2 changes: 1 addition & 1 deletion mods/cnc/maps/blank-shellmap/map.yaml
@@ -1,4 +1,4 @@
MapFormat: 11
MapFormat: 12

RequiresMod: cnc

Expand Down
Binary file modified mods/cnc/maps/blood-and-sand.oramap
Binary file not shown.
Binary file modified mods/cnc/maps/botany.oramap
Binary file not shown.
Binary file modified mods/cnc/maps/break-of-day.oramap
Binary file not shown.
Binary file modified mods/cnc/maps/burning-hammer.oramap
Binary file not shown.
Binary file modified mods/cnc/maps/carters-ridge.oramap
Binary file not shown.
Binary file modified mods/cnc/maps/chill-out.oramap
Binary file not shown.
Binary file modified mods/cnc/maps/chokepoint.oramap
Binary file not shown.
2 changes: 1 addition & 1 deletion mods/cnc/maps/cnc64gdi01/map.yaml
@@ -1,4 +1,4 @@
MapFormat: 11
MapFormat: 12

RequiresMod: cnc

Expand Down
Binary file modified mods/cnc/maps/collateral-chaos.oramap
Binary file not shown.
Binary file modified mods/cnc/maps/control-and-chaos.oramap
Binary file not shown.
Binary file modified mods/cnc/maps/crossing-the-divide.oramap
Binary file not shown.
Binary file modified mods/cnc/maps/desert-invasion.oramap
Binary file not shown.
Binary file modified mods/cnc/maps/desert-mandarins.oramap
Binary file not shown.
2 changes: 1 addition & 1 deletion mods/cnc/maps/desert-rats-cnc/map.yaml
@@ -1,4 +1,4 @@
MapFormat: 11
MapFormat: 12

RequiresMod: cnc

Expand Down
Binary file modified mods/cnc/maps/desert-storm-3.oramap
Binary file not shown.
Binary file modified mods/cnc/maps/deserted-outpost.oramap
Binary file not shown.
Binary file modified mods/cnc/maps/deterring-democracy-plus.oramap
Binary file not shown.
Binary file modified mods/cnc/maps/deterring-democracy.oramap
Binary file not shown.
Binary file modified mods/cnc/maps/dualism.oramap
Binary file not shown.
Binary file modified mods/cnc/maps/east-vs-west-3.oramap
Binary file not shown.
Binary file modified mods/cnc/maps/elysian-expanse.oramap
Binary file not shown.
Binary file modified mods/cnc/maps/escalations.oramap
Binary file not shown.
Binary file modified mods/cnc/maps/fight-win-prevail.oramap
Binary file not shown.
Binary file modified mods/cnc/maps/frigid-pass.oramap
Binary file not shown.
2 changes: 1 addition & 1 deletion mods/cnc/maps/funpark01/map.yaml
@@ -1,4 +1,4 @@
MapFormat: 11
MapFormat: 12

RequiresMod: cnc

Expand Down
2 changes: 1 addition & 1 deletion mods/cnc/maps/gdi01/map.yaml
@@ -1,4 +1,4 @@
MapFormat: 11
MapFormat: 12

RequiresMod: cnc

Expand Down
2 changes: 1 addition & 1 deletion mods/cnc/maps/gdi02/map.yaml
@@ -1,4 +1,4 @@
MapFormat: 11
MapFormat: 12

RequiresMod: cnc

Expand Down
2 changes: 1 addition & 1 deletion mods/cnc/maps/gdi03/map.yaml
@@ -1,4 +1,4 @@
MapFormat: 11
MapFormat: 12

RequiresMod: cnc

Expand Down
2 changes: 1 addition & 1 deletion mods/cnc/maps/gdi04a/map.yaml
@@ -1,4 +1,4 @@
MapFormat: 11
MapFormat: 12

RequiresMod: cnc

Expand Down
2 changes: 1 addition & 1 deletion mods/cnc/maps/gdi04b/map.yaml
@@ -1,4 +1,4 @@
MapFormat: 11
MapFormat: 12

RequiresMod: cnc

Expand Down
2 changes: 1 addition & 1 deletion mods/cnc/maps/gdi04c/map.yaml
@@ -1,4 +1,4 @@
MapFormat: 11
MapFormat: 12

RequiresMod: cnc

Expand Down
2 changes: 1 addition & 1 deletion mods/cnc/maps/gdi05a/map.yaml
@@ -1,4 +1,4 @@
MapFormat: 11
MapFormat: 12

RequiresMod: cnc

Expand Down
2 changes: 1 addition & 1 deletion mods/cnc/maps/gdi05b/map.yaml
@@ -1,4 +1,4 @@
MapFormat: 11
MapFormat: 12

RequiresMod: cnc

Expand Down
2 changes: 1 addition & 1 deletion mods/cnc/maps/gdi05c/map.yaml
@@ -1,4 +1,4 @@
MapFormat: 11
MapFormat: 12

RequiresMod: cnc

Expand Down
2 changes: 1 addition & 1 deletion mods/cnc/maps/gdi06/map.yaml
@@ -1,4 +1,4 @@
MapFormat: 11
MapFormat: 12

RequiresMod: cnc

Expand Down
2 changes: 1 addition & 1 deletion mods/cnc/maps/gdi07/map.yaml
@@ -1,4 +1,4 @@
MapFormat: 11
MapFormat: 12

RequiresMod: cnc

Expand Down
2 changes: 1 addition & 1 deletion mods/cnc/maps/gdi08a/map.yaml
@@ -1,4 +1,4 @@
MapFormat: 11
MapFormat: 12

RequiresMod: cnc

Expand Down
2 changes: 1 addition & 1 deletion mods/cnc/maps/gdi08b/map.yaml
@@ -1,4 +1,4 @@
MapFormat: 11
MapFormat: 12

RequiresMod: cnc

Expand Down
2 changes: 1 addition & 1 deletion mods/cnc/maps/gdi09/map.yaml
@@ -1,4 +1,4 @@
MapFormat: 11
MapFormat: 12

RequiresMod: cnc

Expand Down
Binary file modified mods/cnc/maps/haos-ridges-cnc.oramap
Binary file not shown.
Binary file modified mods/cnc/maps/hattrix.oramap
Binary file not shown.
Binary file modified mods/cnc/maps/hegemony-or-survival.oramap
Binary file not shown.
Binary file modified mods/cnc/maps/island-duel.oramap
Binary file not shown.
Binary file modified mods/cnc/maps/jungle-conflict.oramap
Binary file not shown.
Binary file modified mods/cnc/maps/kolosseum.oramap
Binary file not shown.
Binary file modified mods/cnc/maps/lost-souls.oramap
Binary file not shown.
Binary file modified mods/cnc/maps/manufacturing-consent.oramap
Binary file not shown.
Binary file modified mods/cnc/maps/master-alert.oramap
Binary file not shown.
Binary file modified mods/cnc/maps/master-of-the-jungle-book.oramap
Binary file not shown.
Binary file modified mods/cnc/maps/media-control.oramap
Binary file not shown.
Binary file modified mods/cnc/maps/model-150.oramap
Binary file not shown.
Binary file modified mods/cnc/maps/model-200.oramap
Binary file not shown.
Binary file modified mods/cnc/maps/morbid-aimless-poseidon.oramap
Binary file not shown.
Binary file modified mods/cnc/maps/mt-nukebait.oramap
Binary file not shown.
2 changes: 1 addition & 1 deletion mods/cnc/maps/nod01/map.yaml
@@ -1,4 +1,4 @@
MapFormat: 11
MapFormat: 12

RequiresMod: cnc

Expand Down
2 changes: 1 addition & 1 deletion mods/cnc/maps/nod02a/map.yaml
@@ -1,4 +1,4 @@
MapFormat: 11
MapFormat: 12

RequiresMod: cnc

Expand Down
2 changes: 1 addition & 1 deletion mods/cnc/maps/nod02b/map.yaml
@@ -1,4 +1,4 @@
MapFormat: 11
MapFormat: 12

RequiresMod: cnc

Expand Down
2 changes: 1 addition & 1 deletion mods/cnc/maps/nod03a/map.yaml
@@ -1,4 +1,4 @@
MapFormat: 11
MapFormat: 12

RequiresMod: cnc

Expand Down
2 changes: 1 addition & 1 deletion mods/cnc/maps/nod03b/map.yaml
@@ -1,4 +1,4 @@
MapFormat: 11
MapFormat: 12

RequiresMod: cnc

Expand Down
2 changes: 1 addition & 1 deletion mods/cnc/maps/nod04a/map.yaml
@@ -1,4 +1,4 @@
MapFormat: 11
MapFormat: 12

RequiresMod: cnc

Expand Down
2 changes: 1 addition & 1 deletion mods/cnc/maps/nod04b/map.yaml
@@ -1,4 +1,4 @@
MapFormat: 11
MapFormat: 12

RequiresMod: cnc

Expand Down
2 changes: 1 addition & 1 deletion mods/cnc/maps/nod05/map.yaml
@@ -1,4 +1,4 @@
MapFormat: 11
MapFormat: 12

RequiresMod: cnc

Expand Down
2 changes: 1 addition & 1 deletion mods/cnc/maps/nod06a/map.yaml
@@ -1,4 +1,4 @@
MapFormat: 11
MapFormat: 12

RequiresMod: cnc

Expand Down
2 changes: 1 addition & 1 deletion mods/cnc/maps/nod06b/map.yaml
@@ -1,4 +1,4 @@
MapFormat: 11
MapFormat: 12

RequiresMod: cnc

Expand Down
2 changes: 1 addition & 1 deletion mods/cnc/maps/nod06c/map.yaml
@@ -1,4 +1,4 @@
MapFormat: 11
MapFormat: 12

RequiresMod: cnc

Expand Down
2 changes: 1 addition & 1 deletion mods/cnc/maps/nod07a/map.yaml
@@ -1,4 +1,4 @@
MapFormat: 11
MapFormat: 12

RequiresMod: cnc

Expand Down
2 changes: 1 addition & 1 deletion mods/cnc/maps/nod07b/map.yaml
@@ -1,4 +1,4 @@
MapFormat: 11
MapFormat: 12

RequiresMod: cnc

Expand Down
2 changes: 1 addition & 1 deletion mods/cnc/maps/nod07c/map.yaml
@@ -1,4 +1,4 @@
MapFormat: 11
MapFormat: 12

RequiresMod: cnc

Expand Down
2 changes: 1 addition & 1 deletion mods/cnc/maps/nod08a/map.yaml
@@ -1,4 +1,4 @@
MapFormat: 11
MapFormat: 12

RequiresMod: cnc

Expand Down
2 changes: 1 addition & 1 deletion mods/cnc/maps/nod08b/map.yaml
@@ -1,4 +1,4 @@
MapFormat: 11
MapFormat: 12

RequiresMod: cnc

Expand Down
2 changes: 1 addition & 1 deletion mods/cnc/maps/nod09/map.yaml
@@ -1,4 +1,4 @@
MapFormat: 11
MapFormat: 12

RequiresMod: cnc

Expand Down
2 changes: 1 addition & 1 deletion mods/cnc/maps/nod10a/map.yaml
@@ -1,4 +1,4 @@
MapFormat: 11
MapFormat: 12

RequiresMod: cnc

Expand Down
2 changes: 1 addition & 1 deletion mods/cnc/maps/nod10b/map.yaml
@@ -1,4 +1,4 @@
MapFormat: 11
MapFormat: 12

RequiresMod: cnc

Expand Down
Binary file modified mods/cnc/maps/order-of-battle.oramap
Binary file not shown.
Binary file modified mods/cnc/maps/ping-pong-bay.oramap
Binary file not shown.
Binary file modified mods/cnc/maps/pirates-and-emperors.oramap
Binary file not shown.
Binary file modified mods/cnc/maps/pressure-cnc.oramap
Binary file not shown.
Binary file modified mods/cnc/maps/reaching-out.oramap
Binary file not shown.
Binary file modified mods/cnc/maps/reasonable-doubt.oramap
Binary file not shown.
Binary file modified mods/cnc/maps/riverside-frontline.oramap
Binary file not shown.
Binary file modified mods/cnc/maps/scorched-earth.oramap
Binary file not shown.
Binary file modified mods/cnc/maps/sustain.oramap
Binary file not shown.
Binary file modified mods/cnc/maps/tactical-advance.oramap
Binary file not shown.
2 changes: 1 addition & 1 deletion mods/cnc/maps/the-hot-box/map.yaml
@@ -1,4 +1,4 @@
MapFormat: 11
MapFormat: 12

RequiresMod: cnc

Expand Down
Binary file modified mods/cnc/maps/tiberian-falls.oramap
Binary file not shown.
Binary file modified mods/cnc/maps/tiberian-war.oramap
Binary file not shown.
Binary file modified mods/cnc/maps/tiberium-forest.oramap
Binary file not shown.
Binary file modified mods/cnc/maps/tiberium-garden-2.oramap
Binary file not shown.
Binary file modified mods/cnc/maps/tiberium-rift.oramap
Binary file not shown.
Binary file modified mods/cnc/maps/too-hot.oramap
Binary file not shown.
Binary file modified mods/cnc/maps/trial-of-possession.oramap
Binary file not shown.
Binary file modified mods/cnc/maps/tropic-expanse.oramap
Binary file not shown.
Binary file modified mods/cnc/maps/twin-lakes.oramap
Binary file not shown.
Binary file modified mods/cnc/maps/two-ponds.oramap
Binary file not shown.
Binary file modified mods/cnc/maps/valley-of-gold-6p.oramap
Binary file not shown.
Binary file modified mods/cnc/maps/valley-of-gold.oramap
Binary file not shown.
Binary file modified mods/cnc/maps/vectors-of-battle.oramap
Binary file not shown.
Binary file modified mods/cnc/maps/warchild.oramap
Binary file not shown.
Binary file modified mods/cnc/maps/warkraft.oramap
Binary file not shown.
Binary file modified mods/cnc/maps/x896.oramap
Binary file not shown.
Binary file modified mods/cnc/maps/year-501.oramap
Binary file not shown.
Binary file modified mods/d2k/maps/arakeen.oramap
Binary file not shown.
2 changes: 1 addition & 1 deletion mods/d2k/maps/atreides-01a/map.yaml
@@ -1,4 +1,4 @@
MapFormat: 11
MapFormat: 12

RequiresMod: d2k

Expand Down
2 changes: 1 addition & 1 deletion mods/d2k/maps/atreides-01b/map.yaml
@@ -1,4 +1,4 @@
MapFormat: 11
MapFormat: 12

RequiresMod: d2k

Expand Down
2 changes: 1 addition & 1 deletion mods/d2k/maps/atreides-02a/map.yaml
@@ -1,4 +1,4 @@
MapFormat: 11
MapFormat: 12

RequiresMod: d2k

Expand Down
2 changes: 1 addition & 1 deletion mods/d2k/maps/atreides-02b/map.yaml
@@ -1,4 +1,4 @@
MapFormat: 11
MapFormat: 12

RequiresMod: d2k

Expand Down
2 changes: 1 addition & 1 deletion mods/d2k/maps/atreides-03a/map.yaml
@@ -1,4 +1,4 @@
MapFormat: 11
MapFormat: 12

RequiresMod: d2k

Expand Down
2 changes: 1 addition & 1 deletion mods/d2k/maps/atreides-03b/map.yaml
@@ -1,4 +1,4 @@
MapFormat: 11
MapFormat: 12

RequiresMod: d2k

Expand Down
2 changes: 1 addition & 1 deletion mods/d2k/maps/atreides-04/map.yaml
@@ -1,4 +1,4 @@
MapFormat: 11
MapFormat: 12

RequiresMod: d2k

Expand Down
2 changes: 1 addition & 1 deletion mods/d2k/maps/atreides-05/map.yaml
@@ -1,4 +1,4 @@
MapFormat: 11
MapFormat: 12

RequiresMod: d2k

Expand Down
Binary file modified mods/d2k/maps/battle-for-dune.oramap
Binary file not shown.
Binary file modified mods/d2k/maps/carthag.oramap
Binary file not shown.
Binary file modified mods/d2k/maps/cave-of-birds.oramap
Binary file not shown.
Binary file modified mods/d2k/maps/cave-of-riches.oramap
Binary file not shown.
Binary file modified mods/d2k/maps/chin-rock.oramap
Binary file not shown.
Binary file modified mods/d2k/maps/cliffmaze.oramap
Binary file not shown.
Binary file modified mods/d2k/maps/death-depths.oramap
Binary file not shown.
Binary file modified mods/d2k/maps/desert-twister.oramap
Binary file not shown.
Binary file modified mods/d2k/maps/eyesofthedesert.oramap
Binary file not shown.
Binary file modified mods/d2k/maps/gara-kulon.oramap
Binary file not shown.
Binary file modified mods/d2k/maps/habbanya-erg.oramap
Binary file not shown.
Binary file modified mods/d2k/maps/habbanya-ridge.oramap
Binary file not shown.
Binary file modified mods/d2k/maps/hallecks-ridge.oramap
Binary file not shown.
2 changes: 1 addition & 1 deletion mods/d2k/maps/harkonnen-01a/map.yaml
@@ -1,4 +1,4 @@
MapFormat: 11
MapFormat: 12

RequiresMod: d2k

Expand Down