// generates a json file that will be loaded in by galaxygencore to instantiate the star chart. static void Main(string[] args) { int numberOfSystems = 1; if (args.Length == 1) { int.TryParse(args[0], out numberOfSystems); } Console.Out.WriteLine("Creating galaxy with {0} Solarsystems...", numberOfSystems.ToString()); GalaxyCreator gc = new GalaxyCreator(); ScGalaxy gal = gc.GenerateGalaxy(numberOfSystems); GeneralJsonSerializer.SerializeAndSave(gal, Globals.GALAXY_CORE_DB); Console.Out.WriteLine("Json saved as {0}", Globals.GALAXY_CORE_DB); }
public static void SerializeAndSave(ScGalaxy gal) { JsonSerializer jsSer = new JsonSerializer(); jsSer.PreserveReferencesHandling = PreserveReferencesHandling.Objects; jsSer.Formatting = Formatting.None; jsSer.NullValueHandling = NullValueHandling.Ignore; using (FileStream stream = new FileStream(Globals.GALAXY_CORE_DB, FileMode.Create, FileAccess.Write)) { using (GZipStream gzip = new GZipStream(stream, CompressionMode.Compress)) { using (StreamWriter sw = new StreamWriter(gzip)) { using (JsonWriter jsWriter = new JsonTextWriter(sw)) { jsSer.Serialize(jsWriter, gal); } } } } }
public ScGalaxy GenerateGalaxy(int numberOfSystems) { Random _rand = new Random(); ScGalaxy gal = new ScGalaxy(); gal.SolarSystems = new HashSet <ScSolarSystem>(); if (numberOfSystems == 1) { ScSolarSystem ss = new ScSolarSystem(); ss.Planets = new HashSet <ScPlanet>(); ss.Name = "Sol"; //ss.Planets.Add(getPlanet("Mercury", 57.9, 87.96)); //ss.Planets.Add(getPlanet("Venus", 108.2, 224.68)); ss.Planets.Add(getPlanet("Earth", 149.6, 365.26)); ss.Planets.Add(getPlanet("Mars", 227.9, 686.98)); //ss.Planets.Add(getPlanet("Jupiter", 778.3, 4332.7)); //ss.Planets.Add(getPlanet("Saturn", 1427, 10759.1)); //ss.Planets.Add(getPlanet("Uranus", 2871, 30707.4)); //ss.Planets.Add(getPlanet("Neptune", 4497.1, 60198.5)); gal.SolarSystems.Add(ss); } else { for (int i = 0; i < numberOfSystems; i++) { ScSolarSystem ss = new ScSolarSystem(); ss.Planets = new HashSet <ScPlanet>(); ss.Name = "SolarSystem" + i.ToString(); ss.Planets.Add(getPlanet("P1", _rand.Next(100), _rand.Next(100) + 100)); ss.Planets.Add(getPlanet("P2", _rand.Next(200) + 100, _rand.Next(100) + 500)); ss.Planets.Add(getPlanet("P3", _rand.Next(200) + 300, _rand.Next(100) + 1000)); ss.Planets.Add(getPlanet("P4", _rand.Next(500) + 500, _rand.Next(100) + 4000)); gal.SolarSystems.Add(ss); } } return(gal); }