Exemple #1
0
        protected override void Init(MyObjectBuilder_DefinitionBase builder)
        {
            base.Init(builder);

            var gpsBuilder = builder as MyObjectBuilder_GpsCollectionDefinition;

            Positions = new List <MyGpsCoordinate>();
            if (gpsBuilder.Positions != null && gpsBuilder.Positions.Length > 0)
            {
                StringBuilder name   = new StringBuilder();
                Vector3D      coords = Vector3D.Zero;

                StringBuilder additionalData = new StringBuilder();

                foreach (var gpsString in gpsBuilder.Positions)
                {
                    if (MyGpsCollection.ParseOneGPSExtended(gpsString, name, ref coords, additionalData))
                    {
                        MyGpsCoordinate newGps = new MyGpsCoordinate()
                        {
                            Name   = name.ToString(),
                            Coords = coords
                        };

                        var additionalString = additionalData.ToString();
                        if (!string.IsNullOrWhiteSpace(additionalString))
                        {
                            string[] split = additionalString.Split(':');
                            for (int i = 0; i < split.Length / 2; ++i)
                            {
                                string first  = split[2 * i + 0];
                                string second = split[2 * i + 1];

                                if (!string.IsNullOrWhiteSpace(first) && !string.IsNullOrWhiteSpace(second))
                                {
                                    if (newGps.Actions == null)
                                    {
                                        newGps.Actions = new List <MyGpsAction>();
                                    }
                                    newGps.Actions.Add(new MyGpsAction()
                                    {
                                        BlockName = first, ActionId = second
                                    });
                                }
                            }
                        }

                        Positions.Add(newGps);
                    }
                    else
                    {
                        Debug.Fail("Invalid GPS: " + gpsString);
                    }
                }
            }
        }
Exemple #2
0
        protected override void Init(MyObjectBuilder_DefinitionBase builder)
        {
            base.Init(builder);
            MyObjectBuilder_GpsCollectionDefinition definition = builder as MyObjectBuilder_GpsCollectionDefinition;

            this.Positions = new List <MyGpsCoordinate>();
            if ((definition.Positions != null) && (definition.Positions.Length != 0))
            {
                StringBuilder name           = new StringBuilder();
                Vector3D      zero           = Vector3D.Zero;
                StringBuilder additionalData = new StringBuilder();
                string[]      positions      = definition.Positions;
                for (int i = 0; i < positions.Length; i++)
                {
                    if (MyGpsCollection.ParseOneGPSExtended(positions[i], name, ref zero, additionalData))
                    {
                        MyGpsCoordinate item = new MyGpsCoordinate {
                            Name   = name.ToString(),
                            Coords = zero
                        };
                        string str = additionalData.ToString();
                        if (!string.IsNullOrWhiteSpace(str))
                        {
                            char[]   separator = new char[] { ':' };
                            string[] strArray2 = str.Split(separator);
                            for (int j = 0; j < (strArray2.Length / 2); j++)
                            {
                                string str2 = strArray2[2 * j];
                                string str3 = strArray2[(2 * j) + 1];
                                if (!string.IsNullOrWhiteSpace(str2) && !string.IsNullOrWhiteSpace(str3))
                                {
                                    if (item.Actions == null)
                                    {
                                        item.Actions = new List <MyGpsAction>();
                                    }
                                    MyGpsAction action = new MyGpsAction {
                                        BlockName = str2,
                                        ActionId  = str3
                                    };
                                    item.Actions.Add(action);
                                }
                            }
                        }
                        this.Positions.Add(item);
                    }
                }
            }
        }