internal StellarSystem(StellarObject type, double mass, Vector2 position, Feature feature) { this._type = type; this._mass = mass; this._position = position; this._feature = feature; }
public static StellarObject FindName(StellarObject mergeFrom, StellarObject mergeTo) { if (mergeFrom.GetType() == mergeTo.GetType()) { foreach (var measure in mergeFrom.names) { foreach (var toMeasure in mergeTo.names) { if (measure.MeasurementValue == toMeasure.MeasurementValue) { return(mergeTo); } } } } foreach (StellarObject m in mergeTo.children) { var result = FindName(mergeFrom, m); if (result != null) { return(result); } } return(null); }
public static bool Merge(StellarObject mergeFrom, StellarObject mergeTo) { StellarObject stellar = FindName(mergeFrom, mergeTo); if (stellar == null) { return(false); } foreach (var m in mergeFrom.measurements) { mergeTo.AddMeasurement(m); } foreach (var child in mergeFrom.children) { int index; if ((index = stellar.children.IndexOf(child)) != -1) { foreach (var m in child.measurements) { stellar.children [index].AddMeasurement(m); } } else { stellar.AddChild(child); } } return(true); }
public void Setup(string name, PlanetSquare squareTemplate, int size, float orbitDist, float orbitAlpha, float gravIntensity, float atmDensity, int atmPercentRange, int heightPercentRange) { this.name = name; this.planetName = name; this.maxSubDegree = size; this.squareTemplate = squareTemplate.gameObject; MaterialPosition matPos = this.GetComponent <MaterialPosition> (); matPos.TargetMat = this.squareTemplate.GetComponent <Renderer> ().sharedMaterial; StellarObject sO = this.GetComponent <StellarObject> (); sO.truePos = Quaternion.AngleAxis(orbitAlpha, Vector3.up) * Vector3.forward * (orbitDist); this.gravIntensity = gravIntensity; this.atmDensity = atmDensity; this.atmRangePerCent = atmPercentRange; this.heightRangePerCent = heightPercentRange; }
public DeserializeTest(string filename) { XMLDeserializer xml = new XMLDeserializer(filename, true); StellarObject obj = xml.ParseXML(); printMeasurements(obj); Serializer.writeToXML("test2.xml", (SolarSystem)obj); }
private void CreateNewStellarObject(ExponentialNotation mass, ExponentialNotation radius, string name, Vector3 startingPosition) { GameObject newInstance = GameObject.Instantiate(stellarObject_BasePrefab, startingPosition, Quaternion.identity); newInstance.name = name; StellarObject newStellarObject = newInstance.GetComponentInChildren <StellarObject>(); newStellarObject.Initialize(mass, radius); stellarObjects.Add(newInstance); }
public MainWindow() { InitializeComponent(); StellarObject Earth = new StellarObject() { Mass = 100, RepresentedAs = EarthStelarObject }; StellarObject Moon = new StellarObject() { Mass = 10, RepresentedAs = MoonStelarObject }; StartGravity(new StellarObject[] { Earth, Moon }); }
public void CheckParseXML() { XMLDeserializer deserializer = new XMLDeserializer(filePath); StellarObject generated = deserializer.ParseXML(); Assert.AreEqual(true, generated.measurements.ContainsKey("magB")); Assert.AreEqual(5.74, (double)generated.measurements["magB"].getValue().value); Assert.AreEqual(0.02, (double)generated.measurements["magB"].getValue().errorPlus); Assert.AreEqual(0.03, (double)generated.measurements["magB"].getValue().errorMinus); Assert.AreEqual(true, generated.measurements.ContainsKey("magJ")); Assert.AreEqual(2.943, (double)generated.measurements["magJ"].getValue().value); Assert.AreEqual(true, generated.measurements.ContainsKey("spectraltype")); Assert.AreEqual("G8 III", (string)generated.measurements["spectraltype"].getValue().value); }
public StellarObject ParseXML(XmlNode node = null, StellarObject root = null) { if (node == null) { node = doc.FirstChild; root = new SolarSystem(); //Console.WriteLine ("firstChild = " + node.Name); } foreach (XmlNode child in node.ChildNodes) { //Console.WriteLine ("node: " + node.Name + "\tchild: " + child.Name + "\tvalue: " + child.InnerText); switch (child.Name) { case "binary": { Binary binary = new Binary(); root.AddChild(ParseXML(child, binary)); break; } case "star": { Star star = new Star(); root.AddChild(ParseXML(child, star)); break; } case "planet": { Planet planet = new Planet(); root.AddChild(ParseXML(child, planet)); break; } default: { Measurement measure = CreateMeasurement(child); //Console.WriteLine ("Addind measurement: " + measure.MeasurementName); root.AddMeasurement(measure); break; } } } return(root); }
public void CheckWriteToXML() { // Create new XML file Serializer.writeToXML(filePathOut, solarSystem); // Compare it with an XML file known to have the same contents as the variable solarSystem XMLDeserializer deserializer = new XMLDeserializer(filePathIn); StellarObject generated = deserializer.ParseXML(); Assert.AreEqual(true, generated.measurements.ContainsKey("magB")); Assert.AreEqual(5.74, (double)generated.measurements["magB"].getValue().value); Assert.AreEqual(0.02, (double)generated.measurements["magB"].getValue().errorPlus); Assert.AreEqual(0.03, (double)generated.measurements["magB"].getValue().errorMinus); Assert.AreEqual(true, generated.measurements.ContainsKey("magJ")); Assert.AreEqual(2.943, (double)generated.measurements["magJ"].getValue().value); Assert.AreEqual(true, generated.measurements.ContainsKey("spectraltype")); Assert.AreEqual("G8 III", (string)generated.measurements["spectraltype"].getValue().value); }
private void printMeasurements(StellarObject obj) { Console.WriteLine("NEW STELLAR OBJECT"); foreach (Measurement entry in obj.names) { Console.WriteLine("Name: " + entry.MeasurementValue); } foreach (Measurement entry in obj.measurements) { Console.WriteLine("MeasureName: " + entry.MeasurementName + "\tMeasureValue: " + entry.MeasurementValue); } foreach (StellarObject entry in obj.children) { printMeasurements(entry); } }
public static void TestMerge() { XMLDeserializer sys1Desrializer = new XMLDeserializer("16 Cygni.xml", true); StellarObject sys1 = sys1Desrializer.ParseXML(); Star star1 = new Star(); star1.AddMeasurement("name", "Gliese 765.1 B"); Planet planet1 = new Planet(); planet1.AddMeasurement("name", "16 Cygni B b"); planet1.AddMeasurement("list", "weird planets"); planet1.AddMeasurement("description", "ayy lmao"); planet1.AddMeasurement("discoverymethod", "IDK"); star1.AddChild(planet1); Console.WriteLine(sys1.XMLTag(new System.Xml.XmlDocument()).OuterXml); Merge(star1, sys1); Console.Write('\n'); Console.WriteLine(sys1.XMLTag(new System.Xml.XmlDocument()).OuterXml); }
public async Task updateWorker() { while (updateList.Count != 0) { token.ThrowIfCancellationRequested(); List <StellarObject> system = dequeueUpdate(); StellarObject update = system[0]; Task <String> xmlTask = rm.getFile("systems/" + update.names[0].MeasurementValue + ".xml"); //List<String> lastUpdates = new List<string>(); token.ThrowIfCancellationRequested(); try { String xml = await xmlTask; if (xml != null) { Console.WriteLine("Found existing system: {0} in OEC. Proceed with update.", update.names[0].MeasurementValue); Logger.WriteLine("Found existing system: {0} in OEC. Proceed with update.", update.names[0].MeasurementValue); XMLDeserializer xmld = new XMLDeserializer(xml, false); StellarObject original = xmld.ParseXML(); if (!needUpdate(original.getLastUpdate(), system)) { Console.WriteLine("Appears that system: {0} does not to be updated continuing.", update.names[0].MeasurementValue); Logger.WriteLine("Appears that system: {0} does not to be updated continuing.", update.names[0].MeasurementValue); continue; } String sources = ""; foreach (StellarObject planet in system) { PlanetMerger.Merge(planet, original); sources += String.Format("[{0}]({1})\n", planet.children[0].names[0].MeasurementValue, planet.Source); } original.isNew = false; original.Source = sources; commitQueue.Enqueue(original); } else { Console.WriteLine("Could not find existing system: {0} in OEC. Proceed with addition.", update.names[0].MeasurementValue); Logger.WriteLine("Could not find existing system: {0} in OEC. Proceed with addition.", update.names[0].MeasurementValue); StellarObject baseSys = system[0]; system.Remove(baseSys); String sources = ""; sources += String.Format("[{0}]({1})\n", baseSys.children[0].names[0].MeasurementValue, baseSys.Source); foreach (StellarObject otherPlanet in system) { PlanetMerger.Merge(otherPlanet, baseSys); sources += String.Format("[{0}]({1})\n", otherPlanet.children[0].names[0].MeasurementValue, otherPlanet.Source); } baseSys.isNew = true; baseSys.Source = sources; commitQueue.Enqueue(baseSys); } } catch (Exception ex) { Console.WriteLine("Failed to create update: " + ex.Message); Console.WriteLine(ex.StackTrace); Logger.WriteLine("Failed to create update: " + ex.Message); Logger.WriteLine(ex.StackTrace); } } Interlocked.Add(ref finished, 1); }