Exemplo n.º 1
0
        /// <summary>
        /// Add a node to this storm.
        ///
        /// STM is temporary until globalstate is ported over
        ///
        /// create NodeInformation class later
        /// </summary>
        public void AddNode(int Intensity, StormType2 Type, Point Pos, int Pressure) // String in this case bad but swnabhfabg
        {
            Node NewNode = new Node();

            // Determine intensity.
            NewNode.Intensity = Intensity;

            // Get node type.
            NewNode.NodeType = Type;

            // Get id.
            NewNode.Id = NodeList.Count;

            if (Pressure < 0)
            {
                Error.Throw("Warning", "Pressure cannot be less than zero!", ErrorSeverity.Warning, 400);
            }
            else
            {
                NewNode.Pressure = Pressure;
            }

            // Set node position.

            RelativePositionConverter RPC = new RelativePositionConverter();
            RelativePosition          RP  = (RelativePosition)RPC.ConvertBack(Pos, typeof(RelativePosition), null, null);

            NewNode.Position = RP;

            Logging.Log($"Adding node");
            // Add.
            NodeList.Add(NewNode);
        }
Exemplo n.º 2
0
        private List <StormType2> Load_Manual()
        {
            try
            {
                List <StormType2> ST2List = new List <StormType2>();

                XmlDocument XD = new XmlDocument();

                // V2.1: settings
                XD.Load(@"Data\StormTypes.xml");

                XmlNode XRoot = XD.FirstChild;

                if (XRoot.Name.Contains("#"))
                {
                    if (XRoot.NextSibling == null)
                    {
                        Error.Throw("Fatal Error!", "StormTypes.xml is malformed - your Track Maker installation is corrupted and you must reinstall.", ErrorSeverity.FatalError, 171);
                        return(null);
                    }
                    else
                    {
                        XRoot = XRoot.NextSibling;
                    }
                }

                if (!XRoot.HasChildNodes)
                {
                    Error.Throw("Fatal Error!", "StormTypes.xml is malformed - your Track Maker installation is corrupted and you must reinstall.", ErrorSeverity.FatalError, 162);
                    return(null);
                }
                else
                {
                    XmlNodeList CNodes = XRoot.ChildNodes;

                    foreach (XmlNode HStormType in CNodes)
                    {
                        switch (HStormType.Name)
                        {
                        // The root node for a storm type.
                        case "StormType":

                            StormType2 ST2 = new StormType2();

                            if (!HStormType.HasChildNodes)
                            {
                                Error.Throw("Fatal Error!", "StormTypes.xml is malformed - your Track Maker installation is corrupted and you must reinstall.", ErrorSeverity.FatalError, 163);
                                return(null);
                            }
                            else
                            {
                                XmlNodeList GCNodes = HStormType.ChildNodes;

                                foreach (XmlNode HStormInfo in GCNodes)
                                {
                                    switch (HStormInfo.Name)
                                    {
                                    case "Abbreviation":
                                        ST2.Abbreviation = HStormInfo.InnerText;
                                        continue;

                                    // Best-Track abbreviations
                                    case "BTAbbreviations":
                                        if (!HStormInfo.HasChildNodes)
                                        {
                                            Error.Throw("Fatal Error!", "StormTypes.xml is malformed - your Track Maker installation is corrupted and you must reinstall.", ErrorSeverity.FatalError, 166);
                                            return(null);
                                        }
                                        else
                                        {
                                            XmlNodeList BTAbbreviationXMLNodes = HStormInfo.ChildNodes;

                                            foreach (XmlNode BTAbbreviationXMLNode in BTAbbreviationXMLNodes)
                                            {
                                                switch (BTAbbreviationXMLNode.Name)
                                                {
                                                case "Abbreviation":
                                                    // reduces code complexity by eliminating the need for error checking in this instance
                                                    ST2.BTAbbreviations.Add(BTAbbreviationXMLNode.InnerText);
                                                    continue;
                                                }
                                            }
                                        }
                                        continue;

                                    case "ForceColour":
                                        ST2.ForceColour  = true;
                                        ST2.ForcedColour = HStormInfo.InnerText.SplitARGB();
                                        continue;

                                    case "ForceSize":
                                        ST2.ForceSize  = true;
                                        ST2.ForcedSize = HStormInfo.InnerText.SplitXY();
                                        continue;

                                    case "Name":
                                        ST2.Name = HStormInfo.InnerText;
                                        continue;

                                    case "Shape":

                                        if (!HStormInfo.HasChildNodes)
                                        {
                                            Error.Throw("Fatal Error!", "StormTypes.xml is malformed - your Track Maker installation is corrupted and you must reinstall.", ErrorSeverity.FatalError, 163);
                                            return(null);
                                        }
                                        else
                                        {
                                            XmlNodeList ShapeData = HStormInfo.ChildNodes;

                                            foreach (XmlNode ShapeDataNode in ShapeData)
                                            {
                                                switch (ShapeDataNode.Name)
                                                {
                                                case "PresetShape":
                                                    ST2.UsePresetShape = true;
                                                    ST2.PresetShape    = (StormShape)Enum.Parse(typeof(StormShape), ShapeDataNode.InnerText);
                                                    continue;

                                                case "IsFilled":             //v512
                                                    ST2.Shape.IsFilled = Convert.ToBoolean(ShapeDataNode.InnerText);
                                                    continue;

                                                case "VertexPoints":
                                                    // we already initialise the shape so no need to redo it
                                                    Shape Shp = ST2.Shape;
                                                    if (!ShapeDataNode.HasChildNodes)
                                                    {
                                                        Error.Throw("Fatal Error!", "StormTypes.xml is malformed - your Track Maker installation is corrupted and you must reinstall.", ErrorSeverity.FatalError, 164);
                                                        return(null);
                                                    }
                                                    else
                                                    {
                                                        XmlNodeList PolygonDataNodes = ShapeDataNode.ChildNodes;
                                                        Polygon     Poly             = new Polygon();

                                                        foreach (XmlNode PolygonDataNode in PolygonDataNodes)
                                                        {
                                                            switch (PolygonDataNode.Name)
                                                            {
                                                            case "VertexPosition":
                                                                // god
                                                                Poly.Points.Add(PolygonDataNode.InnerText.SplitXY());

                                                                continue;
                                                            }
                                                        }

                                                        Shp.VPoints = Poly;
                                                    }

                                                    continue;
                                                }
                                            }
                                        }

                                        continue;
                                    }
                                }
                            }

                            Logging.Log($"Successfully loaded storm type with name {ST2.Name}");
                            ST2List.Add(ST2);

                            continue;
                        }
                    }
                }

                return(ST2List);
            }
            catch (FileNotFoundException)
            {
                Error.Throw("Fatal Error!", "Cannot load StormTypes.xml - your Track Maker installation is corrupted and you must reinstall.", ErrorSeverity.FatalError, 160);
                return(null);
            }
            catch (XmlException)
            {
                Error.Throw("Fatal Error!", "StormTypes.xml is malformed - your Track Maker installation is corrupted and you must reinstall!", ErrorSeverity.FatalError, 161);
                return(null);
            }
        }