Save map generation args in replays/saves instead of full map.
This commit is contained in:
committed by
Gustas Kažukauskas
parent
0d479e7c18
commit
fdb4ce4e0f
@@ -13,7 +13,6 @@ using System;
|
||||
using System.Collections.Frozen;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.FileSystem;
|
||||
using OpenRA.Network;
|
||||
using OpenRA.Primitives;
|
||||
|
||||
@@ -29,7 +28,6 @@ namespace OpenRA
|
||||
|
||||
public string MapUid;
|
||||
public string MapTitle;
|
||||
public string MapData;
|
||||
public int FinalGameTick;
|
||||
|
||||
/// <summary>Game start timestamp (when the recoding started).</summary>
|
||||
@@ -44,24 +42,12 @@ namespace OpenRA
|
||||
public IList<Player> Players { get; }
|
||||
public FrozenSet<int> DisabledSpawnPoints = FrozenSet<int>.Empty;
|
||||
|
||||
public MapPreview MapPreview
|
||||
{
|
||||
get
|
||||
{
|
||||
var preview = Game.ModData.MapCache[MapUid];
|
||||
if (preview.Status != MapStatus.Available && MapData != null)
|
||||
{
|
||||
var package = ZipFileLoader.ReadWriteZipFile.FromBase64String(MapData);
|
||||
preview.UpdateFromMap(package, MapClassification.Generated);
|
||||
}
|
||||
|
||||
return preview;
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<Player> HumanPlayers { get { return Players.Where(p => p.IsHuman); } }
|
||||
public bool IsSinglePlayer => HumanPlayers.Count() == 1;
|
||||
|
||||
[FieldLoader.Ignore]
|
||||
public MapGenerationArgs MapGenerationArgs;
|
||||
|
||||
readonly Dictionary<OpenRA.Player, Player> playersByRuntime;
|
||||
|
||||
public GameInformation()
|
||||
@@ -70,6 +56,15 @@ namespace OpenRA
|
||||
playersByRuntime = [];
|
||||
}
|
||||
|
||||
public MapPreview GetMapPreview(ModData modData)
|
||||
{
|
||||
var preview = modData.MapCache[MapUid];
|
||||
if (preview.Status != MapStatus.Available && MapGenerationArgs != null)
|
||||
modData.MapCache.GenerateMap(modData, MapGenerationArgs);
|
||||
|
||||
return preview;
|
||||
}
|
||||
|
||||
public static GameInformation Deserialize(string data, string path)
|
||||
{
|
||||
try
|
||||
@@ -90,6 +85,10 @@ namespace OpenRA
|
||||
case "Player":
|
||||
info.Players.Add(FieldLoader.Load<Player>(node.Value));
|
||||
break;
|
||||
|
||||
case "MapGenerationArgs":
|
||||
info.MapGenerationArgs = FieldLoader.Load<MapGenerationArgs>(node.Value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,6 +111,9 @@ namespace OpenRA
|
||||
for (var i = 0; i < Players.Count; i++)
|
||||
nodes.Add(new MiniYamlNode($"Player@{i}", FieldSaver.Save(Players[i])));
|
||||
|
||||
if (MapGenerationArgs != null)
|
||||
nodes.Add(new MiniYamlNode("MapGenerationArgs", new MiniYaml("", MiniYaml.FromString(MapGenerationArgs.Serialize(), "MapGenerationArgs"))));
|
||||
|
||||
return nodes.WriteToString();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user