private void ParseFerryConnections() { var connectionDirectory = Rfs.GetDirectory("def/ferry/connection"); if (connectionDirectory == null) { Log.Msg("Could not read 'def/ferry/connection' dir"); return; } var ferryConnectionFiles = connectionDirectory.GetFiles("sii"); if (ferryConnectionFiles == null) { Log.Msg("Could not read ferry connection files files"); return; } foreach (var ferryConnectionFile in ferryConnectionFiles) { var data = ferryConnectionFile.Entry.Read(); var lines = Encoding.UTF8.GetString(data).Split('\n'); TsFerryConnection conn = null; foreach (var line in lines) { if (line.Contains(":")) { var value = line.Split(':')[1].Trim(); var key = line.Split(':')[0].Trim(); if (conn != null) { if (key.Contains("connection_positions")) { var vector = value.Split('(')[1].Split(')')[0]; var values = vector.Split(','); var x = float.Parse(values[0].Replace('.', ',')); var z = float.Parse(values[2].Replace('.', ',')); conn.AddConnectionPosition(x, z); } } if (line.Contains("ferry_connection")) { var portIds = value.Split('.'); conn = new TsFerryConnection { StartPortToken = ScsHash.StringToToken(portIds[1]), EndPortToken = ScsHash.StringToToken(portIds[2].TrimEnd('{').Trim()) }; } } if (!line.Contains("}") || conn == null) { continue; } ; var existingItem = _ferryConnectionLookup.FirstOrDefault(item => (item.StartPortToken == conn.StartPortToken && item.EndPortToken == conn.EndPortToken) || (item.StartPortToken == conn.EndPortToken && item.EndPortToken == conn.StartPortToken)); // Check if connection already exists if (existingItem == null) { _ferryConnectionLookup.Add(conn); } conn = null; } } }
private void ParseFerryConnections() { var connectionDirectory = Rfs.GetDirectory("def/ferry/connection"); if (connectionDirectory == null) { Log.Msg("Could not read 'def/ferry/connection' dir"); return; } var ferryConnectionFiles = connectionDirectory.GetFiles("sii"); if (ferryConnectionFiles == null) { Log.Msg("Could not read ferry connection files files"); return; } foreach (var ferryConnectionFile in ferryConnectionFiles) { var data = ferryConnectionFile.Entry.Read(); var lines = Encoding.UTF8.GetString(data).Split('\n'); TsFerryConnection conn = null; foreach (var line in lines) { var(validLine, key, value) = SiiHelper.ParseLine(line); if (validLine) { if (conn != null) { if (key.Contains("connection_positions")) { var index = int.Parse(key.Split('[')[1].Split(']')[0]); var vector = value.Split('(')[1].Split(')')[0]; var values = vector.Split(','); var x = float.Parse(values[0], CultureInfo.InvariantCulture); var z = float.Parse(values[2], CultureInfo.InvariantCulture); conn.AddConnectionPosition(index, x, z); } else if (key.Contains("connection_directions")) { var index = int.Parse(key.Split('[')[1].Split(']')[0]); var vector = value.Split('(')[1].Split(')')[0]; var values = vector.Split(','); var x = float.Parse(values[0], CultureInfo.InvariantCulture); var z = float.Parse(values[2], CultureInfo.InvariantCulture); conn.AddRotation(index, Math.Atan2(z, x)); } } if (key == "ferry_connection") { var portIds = value.Split('.'); conn = new TsFerryConnection { StartPortToken = ScsHash.StringToToken(portIds[1]), EndPortToken = ScsHash.StringToToken(portIds[2].TrimEnd('{').Trim()) }; } } if (!line.Contains("}") || conn == null) { continue; } ; var existingItem = _ferryConnectionLookup.FirstOrDefault(item => (item.StartPortToken == conn.StartPortToken && item.EndPortToken == conn.EndPortToken) || (item.StartPortToken == conn.EndPortToken && item.EndPortToken == conn.StartPortToken)); // Check if connection already exists if (existingItem == null) { _ferryConnectionLookup.Add(conn); } conn = null; } } }