예제 #1
0
 /// <summary>
 /// Requested direction value has changed.
 /// Forward to command station.
 /// </summary>
 private void OnRequestedDirectionChanged(LocDirection value)
 {
     if (commandStation != null)
     {
         commandStation.SendLocSpeedAndDirection(this);
     }
 }
예제 #2
0
            /// <summary>
            /// Default ctor
            /// </summary>
            public Item(ILocState loc, IBlockState block, BlockSide currentBlockEnterSide, LocDirection direction)
            {
                this.loc   = loc;
                this.block = block;
                this.currentBlockEnterSide = currentBlockEnterSide;
                this.direction             = direction;
                Checked = true;
                Text    = loc.Description;
                var facingText = (currentBlockEnterSide.Invert() == BlockSide.Front) ? Strings.FacingFrontOfBlock : Strings.FacingBackOfBlock;

                SubItems.Add(string.Format(Strings.XFacingY, block.Description, facingText));
                SubItems.Add(direction == LocDirection.Forward ? "Forward" : "Reverse");
            }
예제 #3
0
        /// <summary>
        /// Load the current block state of the given loc.
        /// </summary>
        /// <returns>True if the state was loaded properly.</returns>
        public bool TryGetLocState(IRailwayState railwayState, ILocState loc, out IBlockState currentBlock, out BlockSide currentBlockEnterSide, out LocDirection currentDirection)
        {
            currentBlock          = null;
            currentBlockEnterSide = BlockSide.Back;
            currentDirection      = LocDirection.Forward;

            // Read assignment
            using (var key = Registry.CurrentUser.OpenSubKey(GetKey(loc)))
            {
                if (key == null)
                {
                    return(false);
                }
                var blockId = key.GetValue(CurrentBlock) as string;
                if (string.IsNullOrEmpty(blockId))
                {
                    return(false);
                }
                var currentBlockState = railwayState.BlockStates.FirstOrDefault(x => x.EntityId == blockId);
                if (currentBlockState == null)
                {
                    return(false);
                }
                currentBlock = currentBlockState;
                var enterSide = key.GetValue(CurrentBlockEnterSide);
                if (!(enterSide is int))
                {
                    return(false);
                }
                currentBlockEnterSide = ((int)enterSide == 0) ? BlockSide.Back : BlockSide.Front;
                var direction = key.GetValue(CurrentDirection);
                if (!(direction is int))
                {
                    direction = 0;
                }
                currentDirection = ((int)direction == 0) ? LocDirection.Forward : LocDirection.Reverse;
                return(true);
            }
        }
예제 #4
0
 /// <summary>
 /// Save the current block state of the given loc.
 /// </summary>
 public void SetLocState(IRailwayState railwayState, ILocState loc, IBlockState currentBlock, BlockSide currentBlockEnterSide, LocDirection currentDirection)
 {
     // Write assignment
     using (var key = Registry.CurrentUser.CreateSubKey(GetKey(loc)))
     {
         key.SetValue(CurrentBlock, (currentBlock != null) ? currentBlock.EntityId : string.Empty);
         key.SetValue(CurrentBlockEnterSide, (currentBlockEnterSide == BlockSide.Back) ? 0 : 1);
         key.SetValue(CurrentDirection, (currentDirection == LocDirection.Forward) ? 0 : 1);
     }
 }
예제 #5
0
 public static Location LocationDir(LocDirection direction, Location baselocation)
 {
     switch (direction)
     {
         case LocDirection.Up:
             return new Location(baselocation.X, baselocation.Y - 1, baselocation.Z);
         case LocDirection.Down:
             return new Location(baselocation.X, baselocation.Y + 1, baselocation.Z);
         case LocDirection.Right:
             return new Location(baselocation.X + 1, baselocation.Y, baselocation.Z);
         case LocDirection.Left:
             return new Location(baselocation.X - 1, baselocation.Y, baselocation.Z);
     }
     return new Location();
 }
예제 #6
0
 /// <summary>
 /// Gets the inverted direction.
 /// </summary>
 public static LocDirection Invert(this LocDirection value)
 {
     return((value == LocDirection.Forward) ? LocDirection.Reverse : LocDirection.Forward);
 }