public async Task <Unit> Handle(CreateInputDataCommand request, CancellationToken cancellationToken)
            {
                TerraristicWindow terraristicWindow = await _context.TerraristicWindows
                                                      .Include(i => i.SensorBlocks)
                                                      .FirstOrDefaultAsync(t => t.ApiKey.ToString() == request.WindowApiKey, cancellationToken: cancellationToken);

                SensorBlock sensorBlock = terraristicWindow?.SensorBlocks.FirstOrDefault(s => s.Id == request.SensorBlockId);

                if (sensorBlock == null)
                {
                    throw new NotFoundException(nameof(sensorBlock), request.SensorBlockId);
                }

                var inputSensorData = new ReadSensorData
                {
                    CreationDate  = request.CreationDate == DateTime.MinValue ? DateTime.Now : request.CreationDate,
                    SensorBlockId = request.SensorBlockId,
                    Value         = request.Value
                };

                await _context.ReadSensorData.AddAsync(inputSensorData, cancellationToken);

                await _context.SaveChangesAsync(cancellationToken);

                return(Unit.Value);
            }
            public async Task <Unit> Handle(UpsertControlSensorCommand request, CancellationToken cancellationToken)
            {
                SensorBlock sensorBlock = await _context.SensorBlocks
                                          .Include(i => i.ControlSensor)
                                          .FirstOrDefaultAsync(sb => sb.Id == request.SensorBlockId, cancellationToken: cancellationToken);

                if (sensorBlock == null)
                {
                    throw new NotFoundException(nameof(sensorBlock), request.SensorBlockId);
                }

                if (sensorBlock.ControlSensor == null)
                {
                    sensorBlock.ControlSensor = new ControlSensor
                    {
                        SensorBlockId = request.SensorBlockId,
                        State         = request.State,
                        Value         = request.Value
                    };
                }
                else
                {
                    sensorBlock.ControlSensor.State = request.State;
                    sensorBlock.ControlSensor.Value = request.Value;
                }

                await _context.SaveChangesAsync(cancellationToken);

                return(Unit.Value);
            }
 public SensorColliderWrapper(EngineEx engineEx, BlockWrappers.SensorBlockWrapper sensorWrapper, Collider collider)
 {
     this._engineEx  = engineEx;
     this._sensor    = sensorWrapper.BB;
     this._collider  = collider;
     this._forward   = sensorWrapper.Forward;
     this._startPos  = _sensor.sensorPos.position;
     this._targetPos = _collider.ClosestPointOnBounds(this._startPos) - this._startPos;
 }
Beispiel #4
0
            public async Task <int> Handle(CreateSensorCommand request, CancellationToken cancellationToken)
            {
                SensorBlock entity = GetNewSensorBlock(request);

                await _context.SensorBlocks.AddAsync(entity, cancellationToken);

                await _context.SaveChangesAsync(cancellationToken);

                return(entity.Id);
            }
Beispiel #5
0
        public void LoadFrom(Logic modContext, SensorBlock baseObject, GameObject go)
        {
            ModContext = modContext;
            // BasicInfo
            Prefab            = baseObject.Prefab;
            infoType          = baseObject.infoType;
            Rigidbody         = baseObject.Rigidbody;
            noRigidbody       = baseObject.noRigidbody;
            MeshRenderer      = baseObject.MeshRenderer;
            noRigidbody       = baseObject.noRigidbody;
            stripped          = baseObject.stripped;
            NetBlock          = baseObject.NetBlock;
            _hasParentMachine = baseObject._hasParentMachine;
            _parentMachine    = baseObject._parentMachine;
            SimPhysics        = baseObject.SimPhysics;
            isSimulating      = baseObject.isSimulating;
            IsMagnetic        = baseObject.IsMagnetic;
            isDestroyed       = baseObject.isDestroyed;
            ShelterAmount     = baseObject.ShelterAmount;
            offsetDir         = baseObject.offsetDir;

            // SaveableDataHolder

            // BlockBehavior
            VisualController       = baseObject.VisualController;
            VisualController.Block = this;
            BreakOnImpact          = baseObject.BreakOnImpact;
            BlockHealth            = baseObject.BlockHealth;
            myBounds              = baseObject.myBounds;
            fireTag               = baseObject.fireTag;
            iceTag                = baseObject.iceTag;
            blockJoint            = baseObject.blockJoint;
            DestroyOnClient       = baseObject.DestroyOnClient;
            DestroyOnSimulate     = baseObject.DestroyOnSimulate;
            CurrentWindController = baseObject.CurrentWindController;

            var componentsInChildren = baseObject.GetComponentsInChildren <TriggerSetJoint>();

            for (int i = 0; i < componentsInChildren.Length; i++)
            {
                componentsInChildren[i].block = this;
            }

            nonAuto      = baseObject.NonAuto;
            holdToDetect = baseObject.HoldToDetect;
            inverted     = baseObject.Inverted;
            ledColor     = baseObject.ledColor;

            sensorMask   = baseObject.sensorMask;
            sensorPos    = baseObject.sensorPos;
            sphereTop    = baseObject.sphereTop;
            sphereBottom = baseObject.sphereBottom;
            cylinder     = baseObject.cylinder;
        }
Beispiel #6
0
            public async Task<int> Handle(UpdateSensorCommand request, CancellationToken cancellationToken)
            {
                SensorBlock entity = await _context.SensorBlocks
                    .FirstOrDefaultAsync(s => s.Id == request.Id && s.UserId == _currentUserService.UserId, cancellationToken: cancellationToken);

                entity.Name = request.Name;
                entity.Description = request.Description;

                await _context.SaveChangesAsync(cancellationToken);

                return entity.Id;
            }
            public async Task <Unit> Handle(DeleteAllSensorReadData request, CancellationToken cancellationToken)
            {
                SensorBlock sensorBlock = await _context.SensorBlocks
                                          .Include(i => i.ReadSensorData)
                                          .FirstOrDefaultAsync(s => s.UserId == _currentUserService.UserId && s.Id == request.SensorBlockId, cancellationToken: cancellationToken);

                if (sensorBlock == null)
                {
                    throw new NotFoundException(nameof(sensorBlock), request.SensorBlockId);
                }

                _context.ReadSensorData.RemoveRange(sensorBlock.Reads);
                await _context.SaveChangesAsync(cancellationToken);

                return(Unit.Value);
            }
Beispiel #8
0
            private SensorBlock GetNewSensorBlock(CreateSensorCommand request)
            {
                SensorBlock sensorBlock = new SensorBlock
                {
                    Name           = request.Name,
                    Description    = request.Description,
                    UserId         = _currentUserService.UserId,
                    ParentWindowId = request.WindowId,
                    SensorKindId   = request.SensorKindId,
                    Type           = request.Type
                };

                UpdateSensorBlockTypeDependOnKind(request, sensorBlock);

                return(sensorBlock);
            }
Beispiel #9
0
 private static void UpdateSensorBlockTypeDependOnKind(CreateSensorCommand request, SensorBlock entity)
 {
     if (request.Type == SensorTypeEnum.Control)
     {
         entity.ControlSensor = new ControlSensor
         {
             Value = "",
             State = false
         };
     }
 }