Save and restore viewport position / selection / control groups.

This commit is contained in:
Paul Chote
2019-04-13 17:10:46 +00:00
committed by reaperrr
parent de9649df27
commit 492b5aec82
7 changed files with 95 additions and 0 deletions

View File

@@ -200,5 +200,42 @@ namespace OpenRA
.Select(g => (int?)g.Key)
.FirstOrDefault();
}
public List<MiniYamlNode> Serialize()
{
var groups = controlGroups
.Where(cg => cg.Value.Any())
.Select(cg => new MiniYamlNode(cg.Key.ToString(),
FieldSaver.FormatValue(cg.Value.Select(a => a.ActorID).ToArray())))
.ToList();
return new List<MiniYamlNode>()
{
new MiniYamlNode("Selection", FieldSaver.FormatValue(Actors.Select(a => a.ActorID).ToArray())),
new MiniYamlNode("Groups", new MiniYaml("", groups))
};
}
public void Deserialize(World world, List<MiniYamlNode> data)
{
var selectionNode = data.FirstOrDefault(n => n.Key == "Selection");
if (selectionNode != null)
{
var selected = FieldLoader.GetValue<uint[]>("Selection", selectionNode.Value.Value)
.Select(a => world.GetActorById(a));
Combine(world, selected, false, false);
}
var groupsNode = data.FirstOrDefault(n => n.Key == "Groups");
if (groupsNode != null)
{
foreach (var n in groupsNode.Value.Nodes)
{
var group = FieldLoader.GetValue<uint[]>(n.Key, n.Value.Value)
.Select(a => world.GetActorById(a));
controlGroups[int.Parse(n.Key)].AddRange(group);
}
}
}
}
}