Ejemplo n.º 1
0
        internal static void GetProperties(string hash)
        {
            if (knownRoutes == null || !knownRoutes.ContainsKey(hash))
            {
                return;
            }

            RouteProperties routeProperties = knownRoutes[hash];

            for (int i = 0; i < Plugin.CurrentRoute.Stations.Length; i++)
            {
                if (routeProperties.StationNames.Length == Plugin.CurrentRoute.Stations.Length)
                {
                    Plugin.CurrentRoute.Stations[i].Name = routeProperties.StationNames[i];
                }
                if (routeProperties.DepartureTimes.Length == Plugin.CurrentRoute.Stations.Length)
                {
                    Plugin.CurrentRoute.Stations[i].DepartureTime = routeProperties.DepartureTimes[i];
                }
                if (routeProperties.Doors.Length == Plugin.CurrentRoute.Stations.Length)
                {
                    Plugin.CurrentRoute.Stations[i].OpenLeftDoors  = (routeProperties.Doors[i] & DoorStates.Left) != 0;
                    Plugin.CurrentRoute.Stations[i].OpenRightDoors = (routeProperties.Doors[i] & DoorStates.Right) != 0;
                }
            }

            Plugin.CurrentRoute.Comment     = routeProperties.Description;
            Plugin.CurrentOptions.TrainName = routeProperties.DefaultTrain;
        }
Ejemplo n.º 2
0
        internal static void ParsePropertiesNode(XmlNode node, ref Dictionary <string, RouteProperties> routeProperties)
        {
            RouteProperties currentProperties = new RouteProperties();
            string          currentHash       = string.Empty;

            foreach (XmlElement childNode in node.ChildNodes.OfType <XmlElement>())
            {
                switch (childNode.Name)
                {
                case "Hash":
                    currentHash = childNode.InnerText;
                    break;

                case "Description":
                    currentProperties.Description = childNode.InnerText;
                    break;

                case "StationNames":
                    currentProperties.StationNames = childNode.InnerText.Split(',');
                    break;

                case "DefaultTrain":
                    currentProperties.DefaultTrain = childNode.InnerText;
                    break;

                case "DepartureTimes":
                    string[] splitTimes = childNode.InnerText.Split(',');
                    currentProperties.DepartureTimes = new double[splitTimes.Length];
                    for (int i = 0; i < splitTimes.Length; i++)
                    {
                        OpenBveApi.Time.TryParseTime(splitTimes[i], out currentProperties.DepartureTimes[i]);
                    }
                    break;

                case "Doors":
                    string[] splitDoors = childNode.InnerText.Split(',');
                    currentProperties.Doors = new DoorStates[splitDoors.Length];
                    for (int i = 0; i < splitDoors.Length; i++)
                    {
                        if (!Enum.TryParse(splitDoors[i], true, out currentProperties.Doors[i]))
                        {
                            currentProperties.Doors[i] = DoorStates.None;
                        }
                    }
                    break;
                }
            }

            if (!routeProperties.ContainsKey(currentHash))
            {
                routeProperties.Add(currentHash, currentProperties);
            }
            else
            {
                Plugin.CurrentHost.AddMessage(MessageType.Error, false, "The RouteProperties database contains a duplicate entry with hash " + currentHash);
            }
        }