public static PlayerExtraOptions FromMessage(string message) { var parts = message.Split(MESSAGE_SEPARATOR); if (parts.Length < 2) { throw new Exception(INVALID_OPTIONS_MESSAGE); } var boolParts = parts[0].ToCharArray(); if (boolParts.Length < 5) { throw new Exception(INVALID_OPTIONS_MESSAGE); } return(new PlayerExtraOptions { IsForceRandomSides = boolParts[0] == '1', IsForceRandomColors = boolParts[1] == '1', IsForceRandomTeams = boolParts[2] == '1', IsForceRandomStarts = boolParts[3] == '1', IsUseTeamStartMappings = boolParts[4] == '1', TeamStartMappings = TeamStartMapping.FromListString(parts[1]) }); }
private void GetTeamStartMappingPresets(IniSection section) { TeamStartMappingPresets = new List <TeamStartMappingPreset>(); for (int i = 0; ; i++) { try { var teamStartMappingPreset = section.GetStringValue($"TeamStartMapping{i}", string.Empty); if (string.IsNullOrEmpty(teamStartMappingPreset)) { return; // mapping not found } var teamStartMappingPresetName = section.GetStringValue($"TeamStartMapping{i}Name", string.Empty); if (string.IsNullOrEmpty(teamStartMappingPresetName)) { continue; // mapping found, but no name specified } TeamStartMappingPresets.Add(new TeamStartMappingPreset() { Name = teamStartMappingPresetName, TeamStartMappings = TeamStartMapping.FromListString(teamStartMappingPreset) }); } catch (Exception e) { Logger.Log($"Unable to parse team start mappings. Map: \"{Name}\", Error: {e.Message}"); TeamStartMappingPresets = new List <TeamStartMappingPreset>(); } } }
public override string ToString() { var stringBuilder = new StringBuilder(); stringBuilder.Append(IsForceRandomSides ? "1" : "0"); stringBuilder.Append(IsForceRandomColors ? "1" : "0"); stringBuilder.Append(IsForceRandomTeams ? "1" : "0"); stringBuilder.Append(IsForceRandomStarts ? "1" : "0"); stringBuilder.Append(IsUseTeamStartMappings ? "1" : "0"); stringBuilder.Append(MESSAGE_SEPARATOR); stringBuilder.Append(TeamStartMapping.ToListString(TeamStartMappings)); return(stringBuilder.ToString()); }