コード例 #1
0
ファイル: MessageParser.cs プロジェクト: IanEscober/WasteMan
        private static GarbageBin ProccesLidState(this GarbageBin bin, string lidState)
        {
            switch (lidState)
            {
            case nameof(LidStates.Closed):
            {
                bin.LidSate = LidStates.Closed;
                break;
            }

            case nameof(LidStates.Open):
            {
                bin.LidSate = LidStates.Open;
                break;
            }

            case nameof(LidStates.Overflow):
            {
                bin.LidSate = LidStates.Overflow;
                break;
            }

            case nameof(LidStates.Partial):
            {
                bin.LidSate = LidStates.Partial;
                break;
            }

            default:
                throw new Exception("Cannot Identify Lid State");
            }

            bin.LidStateTimeStamp = DateTime.Now.TimeOfDay.RoundToNearestSecond();
            return(bin);
        }
コード例 #2
0
ファイル: MessageParser.cs プロジェクト: IanEscober/WasteMan
        public static GarbageBin ToGarbageBin(this MqttApplicationMessageReceivedEventArgs e)
        {
            var(name, sensor) = e.ApplicationMessage.ToTopic();
            var payload = e.ApplicationMessage.ConvertPayloadToString();
            var bin     = new GarbageBin {
                Name = name
            };

            switch (sensor)
            {
            case nameof(Sensor.UltraGyro):
            {
                var(level, lidState) = payload.ToUltraGyro();
                bin
                .ProccesLidState(lidState)
                .ProcessLevel(level)
                .ProcessStatus();
                break;
            }

            case nameof(Sensor.GPS):
            {
                bin.Location = payload.ToCoordinate();
                break;
            }
            }

            return(bin);
        }
コード例 #3
0
ファイル: MessageParser.cs プロジェクト: IanEscober/WasteMan
 private static GarbageBin ProcessStatus(this GarbageBin bin)
 {
     bin.Status = bin.LidSate.IsLidStateValid()
         ? new Dictionary <TimeSpan, float> {
         { DateTime.Now.TimeOfDay.RoundToNearestSecond(), bin.Level }
     }
         : null;
     return(bin);
 }
コード例 #4
0
ファイル: MQTTnetWrapper.cs プロジェクト: IanEscober/WasteMan
        private async Task <GarbageBin> DoLinking(GarbageBin bin)
        {
            var prevBin = await _garbageBinCacheRepository.GetAsync(bin.Name);

            if (prevBin is null)
            {
                return(bin);
            }
            return(bin.Link(prevBin));
        }
コード例 #5
0
        public async Task SetAsync(GarbageBin bin)
        {
            using (var cache = _cacheClientFactory.Create())
            {
                if (await ExistAsync(bin.Name))
                {
                    var prevBin = await GetAsync(bin.Name);

                    bin.Link(prevBin);
                }

                _ = cache.HashSetAsync(nameof(HashKey.GarbageBins), bin.Name, Mapper.Map <GarbageBin, GarbageBinCacheDto>(bin));
            }
        }
コード例 #6
0
 // Interact with Garbage Bin
 void OnGarbageBinInteracted(GarbageBin bin)
 {
     if (ingredientsPicked.Count > 0)
     {
         ingredientsPicked.RemoveAt(ingredientsPicked.Count - 1);
         player.score -= 5;
     }
     foreach (Ingredient ing in ingredientsDeliveryPicked)
     {
         player.score -= 10;
     }
     ingredientsDeliveryPicked.Clear();
     UpdateScoreText();
     UpdateHUDText();
 }
コード例 #7
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.tag == Defines.Tag_Garbage)
        {
            if (IsEmptySlot())
            {
                PickUpGarbage(collision.transform);
                AudioManager.Instance.PlaySound(Defines.Audio_Grab);
            }
        }

        if (!IsEmptySlot() && collision.tag == Defines.Tag_GarbageBin)
        {
            curGarbage.RecycleGarbage();
            cursorImage.sprite = CursorController.Instance.Sprites_Cursor[1];

            //判断垃圾类型和垃圾桶类型是否吻合
            GarbageBin bin = collision.GetComponent <GarbageBin>();
            if (curGarbage.type == bin.type)
            {
                //吻合,显示正确表情图标
                PhizController.Instance.CreateGood(collision.transform);
                //增加分数
                DataManager.Instance.AddScore(10);
                //播放音效
                AudioManager.Instance.PlaySound(Defines.Audio_Right);
            }
            else
            {
                //不吻合,显示错误表情图标
                PhizController.Instance.CreateBad(collision.transform);
                //播放音效
                AudioManager.Instance.PlaySound(Defines.Audio_Wrong);
            }
            curGarbage = null;
        }
    }
コード例 #8
0
 private void OnReceiveMessage(GarbageBin bin) =>
 _hubContext.Clients.All.SendAsync(nameof(OnReceiveMessage), Mapper.Map <GarbageBinDto>(bin));
コード例 #9
0
ファイル: MessageParser.cs プロジェクト: IanEscober/WasteMan
 private static GarbageBin ProcessLevel(this GarbageBin bin, string level)
 {
     float.TryParse(level, out var resLevel);
     bin.Level = resLevel.IsLevelValid() ? resLevel : throw new ArgumentOutOfRangeException("Level");
     return(bin);
 }