#region Copyright & License Information /* * Copyright 2007-2014 The OpenRA Developers (see AUTHORS) * This file is part of OpenRA, which is free software. It is made * available to you under the terms of the GNU General Public License * as published by the Free Software Foundation. For more information, * see COPYING. */ #endregion using System; using System.Collections.Generic; using System.Linq; using OpenRA.Graphics; using OpenRA.Network; namespace OpenRA { public class GameInformation { public string MapUid; public string MapTitle; public DateTime StartTimeUtc; // Game end timestamp (when the recoding stopped). public DateTime EndTimeUtc; // Gets the game's duration, from the time the game started until the // replay recording stopped. public TimeSpan Duration { get { return EndTimeUtc > StartTimeUtc ? EndTimeUtc - StartTimeUtc : TimeSpan.Zero; } } public IList Players { get; private set; } public MapPreview MapPreview { get { return Game.modData.MapCache[MapUid]; } } public IEnumerable HumanPlayers { get { return Players.Where(p => p.IsHuman); } } public bool IsSinglePlayer { get { return HumanPlayers.Count() == 1; } } Dictionary playersByRuntime; public GameInformation() { Players = new List(); playersByRuntime = new Dictionary(); } public static GameInformation Deserialize(string data) { try { var info = new GameInformation(); var nodes = MiniYaml.FromString(data); foreach (var node in nodes) { var keyParts = node.Key.Split('@'); switch (keyParts[0]) { case "Root": FieldLoader.Load(info, node.Value); break; case "Player": info.Players.Add(FieldLoader.Load(node.Value)); break; } } return info; } catch (InvalidOperationException) { Log.Write("debug", "GameInformation deserialized invalid MiniYaml:\n{0}".F(data)); throw; } } public string Serialize() { var nodes = new List(); nodes.Add(new MiniYamlNode("Root", FieldSaver.Save(this))); for (var i=0; i public bool IsRandomSpawnPoint; // // Information gathered at a later stage // // The game outcome for this player public WinState Outcome; // The time when this player won or lost the game public DateTime OutcomeTimestampUtc; } } }