internal void Serialize(ResourceManager resourceManager, TextWriter writer, string mediaType, SectorSerializeOptions options) { WorldCollection worlds = GetWorlds(resourceManager); // TODO: less hacky T5 support bool isT5 = (mediaType == "TabDelimited" || mediaType == "SecondSurvey"); if (mediaType == "TabDelimited") { worlds?.Serialize(writer, mediaType, options); return; } if (options.includeMetadata) { // Header // writer.WriteLine("# Generated by https://travellermap.com"); writer.WriteLine("# " + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:sszzz", DateTimeFormatInfo.InvariantInfo)); writer.WriteLine(); writer.WriteLine($"# {Names[0]}"); writer.WriteLine($"# {X},{Y}"); writer.WriteLine(); foreach (var name in Names) { if (name.Lang != null) { writer.WriteLine($"# Name: {name.Text} ({name.Lang})"); } else { writer.WriteLine($"# Name: {name}"); } } writer.WriteLine(); writer.WriteLine($"# Milieu: {CanonicalMilieu}"); if (Credits != null) { string stripped = Regex.Replace(Credits, "<.*?>", ""); stripped = Regex.Replace(stripped, @"\s+", " "); stripped = stripped.Trim(); writer.WriteLine(); writer.WriteLine($"# Credits: {stripped}"); } if (DataFile != null) { writer.WriteLine(); if (DataFile.Author != null) { writer.WriteLine($"# Author: {DataFile.Author}"); } if (DataFile.Publisher != null) { writer.WriteLine($"# Publisher: {DataFile.Publisher}"); } if (DataFile.Copyright != null) { writer.WriteLine($"# Copyright: {DataFile.Copyright}"); } if (DataFile.Source != null) { writer.WriteLine($"# Source: {DataFile.Source}"); } if (DataFile.Ref != null) { writer.WriteLine($"# Ref: {DataFile.Ref}"); } } writer.WriteLine(); for (int i = 0; i < 16; ++i) { char c = (char)('A' + i); Subsector ss = Subsector(c); writer.WriteLine($"# Subsector {c}: {ss?.Name ?? ""}"); } writer.WriteLine(); } if (worlds == null) { if (options.includeMetadata) { writer.WriteLine("# No world data available"); } return; } // Allegiances if (options.includeMetadata) { // Use codes as present in the data, to match the worlds foreach (string code in worlds.AllegianceCodes().OrderBy(s => s)) { var alleg = GetAllegianceFromCode(code); if (alleg != null) { var a = isT5 ? code : SecondSurvey.T5AllegianceCodeToLegacyCode(code); writer.WriteLine($"# Alleg: {a}: \"{alleg.Name}\""); } } writer.WriteLine(); } // Worlds worlds.Serialize(writer, mediaType, options); }
internal void Serialize(ResourceManager resourceManager, TextWriter writer, string mediaType, bool includeMetadata = true, bool includeHeader = true, bool sscoords = false, WorldFilter filter = null) { WorldCollection worlds = GetWorlds(resourceManager); // TODO: less hacky T5 support bool isT5 = (mediaType == "TabDelimited" || mediaType == "SecondSurvey"); if (mediaType == "TabDelimited") { if (worlds != null) { worlds.Serialize(writer, mediaType, includeHeader: includeHeader, filter: filter); } return; } if (includeMetadata) { // Header // writer.WriteLine("# Generated by http://travellermap.com"); writer.WriteLine("# " + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:sszzz", DateTimeFormatInfo.InvariantInfo)); writer.WriteLine(); writer.WriteLine("# {0}", Names[0]); writer.WriteLine("# {0},{1}", X, Y); writer.WriteLine(); foreach (var name in Names) { if (name.Lang != null) { writer.WriteLine("# Name: {0} ({1})", name.Text, name.Lang); } else { writer.WriteLine("# Name: {0}", name); } } if (Credits != null) { string stripped = Regex.Replace(Credits, "<.*?>", ""); stripped = Regex.Replace(stripped, @"\s+", " "); stripped = stripped.Trim(); writer.WriteLine(); writer.WriteLine("# Credits: {0}", stripped); } if (DataFile != null) { writer.WriteLine(); if (DataFile.Milieu != null) { writer.WriteLine("# Milieu: {0}", DataFile.Milieu); } writer.WriteLine(); if (DataFile.Author != null) { writer.WriteLine("# Author: {0}", DataFile.Author); } if (DataFile.Publisher != null) { writer.WriteLine("# Publisher: {0}", DataFile.Publisher); } if (DataFile.Copyright != null) { writer.WriteLine("# Copyright: {0}", DataFile.Copyright); } if (DataFile.Source != null) { writer.WriteLine("# Source: {0}", DataFile.Source); } if (DataFile.Ref != null) { writer.WriteLine("# Ref: {0}", DataFile.Ref); } } writer.WriteLine(); for (int i = 0; i < 16; ++i) { char c = (char)('A' + i); Subsector ss = Subsector(c); writer.WriteLine("# Subsector {0}: {1}", c, ss?.Name ?? ""); } writer.WriteLine(); } if (worlds == null) { if (includeMetadata) { writer.WriteLine("# No world data available"); } return; } // Allegiances if (includeMetadata) { // Use codes as present in the data, to match the worlds foreach (string code in worlds.AllegianceCodes().OrderBy(s => s)) { var alleg = GetAllegianceFromCode(code); if (alleg != null) { writer.WriteLine("# Alleg: {0}: \"{1}\"", isT5 ? code : SecondSurvey.T5AllegianceCodeToLegacyCode(code), alleg.Name); } } writer.WriteLine(); } // Worlds worlds.Serialize(writer, mediaType, includeHeader: includeHeader, sscoords: sscoords, filter: filter); }
public void Serialize(ResourceManager resourceManager, TextWriter writer, string mediaType, bool includeMetadata = true, bool includeHeader = true, WorldFilter filter = null) { WorldCollection worlds = GetWorlds(resourceManager); // TODO: less hacky T5 support if (mediaType == "TabDelimited") { if (worlds != null) { worlds.Serialize(writer, mediaType, includeHeader, filter); } return; } if (includeMetadata) { // Header // writer.WriteLine("# Generated by http://www.travellermap.com"); writer.WriteLine("# " + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:sszzz", DateTimeFormatInfo.InvariantInfo)); writer.WriteLine(); writer.WriteLine("# {0}", this.Names[0]); writer.WriteLine("# {0},{1}", this.X, this.Y); writer.WriteLine(); foreach (var name in Names) { if (name.Lang != null) { writer.WriteLine("# Name: {0} ({1})", name.Text, name.Lang); } else { writer.WriteLine("# Name: {0}", name); } } if (Credits != null) { string stripped = Regex.Replace(Credits, "<.*?>", ""); stripped = Regex.Replace(stripped, @"\s+", " "); stripped = stripped.Trim(); writer.WriteLine(); writer.WriteLine("# Credits: {0}", stripped); } if (DataFile != null) { writer.WriteLine(); if (DataFile.Era != null) { writer.WriteLine("# Era: {0}", DataFile.Era); } writer.WriteLine(); if (DataFile.Author != null) { writer.WriteLine("# Author: {0}", DataFile.Author); } if (DataFile.Publisher != null) { writer.WriteLine("# Publisher: {0}", DataFile.Publisher); } if (DataFile.Copyright != null) { writer.WriteLine("# Copyright: {0}", DataFile.Copyright); } if (DataFile.Source != null) { writer.WriteLine("# Source: {0}", DataFile.Source); } if (DataFile.Ref != null) { writer.WriteLine("# Ref: {0}", DataFile.Ref); } } writer.WriteLine(); for (int i = 0; i < 16; ++i) { char c = (char)('A' + i); Subsector ss = this[c]; writer.WriteLine("# Subsector {0}: {1}", c, (ss != null ? ss.Name : "")); } writer.WriteLine(); } if (worlds == null) { if (includeMetadata) { writer.WriteLine("# No world data available"); } return; } // Allegiances if (includeMetadata) { Dictionary <string, Allegiance> allegiances = new Dictionary <string, Allegiance>(); // TODO: Factor this logic out for MSEC/SectorMetaData serializers to use foreach (Allegiance alleg in worlds .Select(world => world.Allegiance) .Where(code => !allegiances.ContainsKey(code)) .Select(code => GetAllegiance(code)) .Where(alleg => alleg != null) .Distinct() .OrderBy(alleg => alleg.Code)) { writer.WriteLine("# Alleg: {0}: \"{1}\"", alleg.Code, alleg.Name); } writer.WriteLine(); } // Worlds worlds.Serialize(writer, mediaType, includeHeader, filter); }