示例#1
0
 public void SetNext(Locomotive loc, Analyze.Route route)
 {
     lock (_manuallyDefinedRoutes)
     {
         if (_manuallyDefinedRoutes.ContainsKey(loc))
         {
             _manuallyDefinedRoutes[loc] = route;
         }
         else
         {
             _manuallyDefinedRoutes.Add(loc, route);
         }
     }
 }
示例#2
0
        private AutoplayRouteThread GetByRoute(Analyze.Route route)
        {
            foreach (var thread in _blockRouteThreads)
            {
                if (thread == null)
                {
                    continue;
                }

                if (thread.Route == route)
                {
                    return(thread);
                }
            }

            return(null);
        }
示例#3
0
        internal int GetLocObjectIdOfRoute(Analyze.Route route, bool destination = false)
        {
            if (!destination)
            {
                var startPoint = route.First();
                if (startPoint != null)
                {
                    var startItem = Ctx.TrackEntity.Track.Get(startPoint.X, startPoint.Y);
                    if (startItem != null)
                    {
                        var locObjectId = startItem.GetLocomotiveObjectId();
                        if (locObjectId != -1)
                        {
                            return(locObjectId);
                        }
                    }
                }
            }
            else
            {
                var endPoint = route.Last();
                if (endPoint != null)
                {
                    var endItem = Ctx.TrackEntity.Track.Get(endPoint.X, endPoint.Y);
                    if (endItem != null)
                    {
                        var locObjectId = endItem.GetLocomotiveObjectId();
                        if (locObjectId != -1)
                        {
                            return(locObjectId);
                        }
                    }
                }
            }

            return(-1);
        }
示例#4
0
        public void SetRoute(Analyze.Route route, bool state)
        {
            if (route == null)
            {
                return;
            }

            var n = route.Count;

            var trackEntity = Ctx.TrackEntity;

            for (int idx = 1; idx < n - 1; ++idx)
            {
                var r = route[idx];
                if (r == null)
                {
                    continue;
                }

                if (trackEntity?.Viewer != null)
                {
                    string themeIcon = null;

                    var trackInfo = trackEntity.Track.Get(r.X, r.Y);
                    if (trackInfo != null)
                    {
                        var themeInfo = Theme?.Get(trackInfo.ThemeId);
                        if (themeInfo != null)
                        {
                            TrackCheckResult     checkResult = null;
                            TrackInformation.S88 s88item     = null;

                            var w        = Ctx.Dispatcher.Weaver;
                            var objItems = w.GetObject(trackInfo);
                            if (objItems != null && objItems.Count > 0)
                            {
                                s88item = objItems[0] as S88;
                                var checkFnc = w.GetCheckFnc(s88item, trackInfo);
                                if (checkFnc != null)
                                {
                                    checkResult = checkFnc();
                                }
                            }

                            if (checkResult == null)
                            {
                                if (state)
                                {
                                    if (Route.HasPoint(route, trackInfo.X, trackInfo.Y))
                                    {
                                        themeIcon = themeInfo.Off.Route;
                                    }
                                    else
                                    {
                                        themeIcon = themeInfo.Off.Default;
                                    }
                                }
                                else
                                {
                                    themeIcon = themeInfo.Off.Default;
                                }
                            }
                            else
                            {
                                bool rS88 = checkResult?.State != null && checkResult.State.Value;

                                if (rS88 && s88item != null)
                                {
                                    if (s88item.IsRouted)
                                    {
                                        themeIcon = themeInfo.Active.Route;
                                    }
                                    else
                                    {
                                        themeIcon = themeInfo.Active.Occ;
                                    }
                                }
                                else
                                {
                                    if (s88item != null && s88item.IsRouted)
                                    {
                                        themeIcon = themeInfo.Off.Route;
                                    }
                                    else
                                    {
                                        if (state && Route.HasPoint(route, trackInfo.X, trackInfo.Y))
                                        {
                                            themeIcon = themeInfo.Off.Route;
                                        }
                                        else
                                        {
                                            themeIcon = themeInfo.Off.Default;
                                        }
                                    }
                                }
                            }
                        }
                    }

                    if (!string.IsNullOrEmpty(themeIcon))
                    {
                        var x           = trackInfo.X;
                        var y           = trackInfo.Y;
                        var themeId     = trackInfo.ThemeId;
                        var orientation = trackInfo.Orientation;
                        var symbol      = themeIcon;

                        var isSwitch = RailwayEssentialCore.Globals.SwitchIds.Contains(themeId);

                        if (r.HasTurn && isSwitch)
                        {
                            var parts = symbol.Split(new[] { '-' }, StringSplitOptions.RemoveEmptyEntries);
                            if (parts.Length == 2)
                            {
                                symbol = parts[0] + "-t-" + parts[1];
                            }
                            else if (parts.Length == 1)
                            {
                                symbol = parts[0] + "-t";
                            }
                        }

                        Ctx.ExecuteJs($"changeSymbol({x}, {y}, {themeId}, \"{orientation}\", \"{symbol}\");");
                    }
                }
            }
        }