public LogBaronOrPirate(string serialized, ILogParserHelper parseHelper) { Deserialize(serialized); StartTile = parseHelper.GetTile(StartTileIndex, GameIndex); TargetTile = parseHelper.GetTile(TargetTileIndex, GameIndex); SourcePlayer = parseHelper.GetPlayerData(SourcePlayerIndex); if (TargetPlayerIndex != -1) { TargetPlayer = parseHelper.GetPlayerData(TargetPlayerIndex); } }
private void ParsePlayer(string player, ILogParserHelper parseHelper) { // // should be in the form of "Joe.0.BottomRight // string[] tokens = player.Split(new char[] { '.' }, StringSplitOptions.RemoveEmptyEntries); if (tokens.Length == 0) { // this is a normal occurance when there isn't a player, like the beginning of the game return; } if (Int32.TryParse(tokens[1], out int index)) { PlayerData = parseHelper.GetPlayerData(index); if (tokens.Length > 2) { if (Enum.TryParse <PlayerPosition>(tokens[2], out PlayerPosition pos)) { PlayerData.PlayerPosition = pos; } else { this.TraceMessage($"No player Position in PlayerData: {PlayerData}"); } } } }
public void Deserialize(string s, ILogParserHelper logParser, string keySep = "/", string listSep = ",") { Reset(); string[] tokens = s.Split(keySep.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); if (tokens.Count() < 1) { return; } foreach (string token in tokens) { // 5=1,2,3 string[] ts = token.Split(new char[] { '=', listSep.ToCharArray()[0] }, StringSplitOptions.RemoveEmptyEntries); int roadCount = Int32.Parse(ts[0]); List <PlayerModel> list = new List <PlayerModel>(); for (int i = 1; i < ts.Count(); i++) // yes 1, ts[0] is the roadCount { int playerIndex = Int32.Parse(ts[i]); PlayerModel player = logParser.GetPlayerData(playerIndex); list.Add(player); } raceDictionary[roadCount.ToString()] = list; } }