private void UpdatePlayer(BlobDto playerDto, int worldSize)
 {
     if (_playersObjects.ContainsKey(playerDto.Id))
     {
         _playersObjects[playerDto.Id].UpdatePlayer(playerDto, worldSize);
     }
 }
 private void UpdateFood(BlobDto foodDto, int worldSize)
 {
     if (_foodObjects.ContainsKey(foodDto.Id))
     {
         _foodObjects[foodDto.Id].UpdateFood(foodDto, worldSize);
     }
 }
        private void AddNewPlayer(BlobDto player, int worldSize)
        {
            var positionAndScale = PlayerPrefab.BlobPositioning.GetBlobPositionAndScale(player, worldSize);
            var playerObject     = (Player)Instantiate(PlayerPrefab, positionAndScale.Position, Quaternion.identity);

            playerObject.transform.localScale = positionAndScale.Scale;

            float h, s, v;

            Color playerColor;

            if (_usedPlayerColorsByPlayerName.ContainsKey(player.Name))
            {
                playerColor = _usedPlayerColorsByPlayerName[player.Name];
            }
            else
            {
                playerColor = PlayerColors.Count > _usedPlayerColorsByPlayerName.Count
                                  ? PlayerColors.First(p => !_usedPlayerColorsByPlayerName.ContainsValue(p))
                                  : PlayerColors.ElementAt(player.Id % PlayerColors.Count);
                _usedPlayerColorsByPlayerName.Add(player.Name, playerColor);
                _eventAggregator.Publish(new PlayerColorAssignedEvent(player.Name, playerColor));
            }

            Color.RGBToHSV(playerColor, out h, out s, out v);
            var innerCircleColor = Color.HSVToRGB(h * 0.9f, s, v);
            var borderColor      = Color.HSVToRGB(h, s, v);

            playerObject.UpdatePlayer(player, worldSize, innerCircleColor, borderColor);
            SavePlayer(playerObject, player);
        }
Esempio n. 4
0
        public void UpdatePlayer(BlobDto playerBlobDto, int worldSize, Color mainColor, Color borderColor)
        {
            UpdatePlayer(playerBlobDto, worldSize);

            InnerCircleRenderer.material.color = mainColor;
            BorderRenderer.material.color      = borderColor;
        }
Esempio n. 5
0
 public void UpdateFood(BlobDto fooBlobDto, int worldSize, Color?color = null)
 {
     if (color != null && Renderer.material.color != color)
     {
         Renderer.material.color = color.Value;
     }
 }
Esempio n. 6
0
        private void AddNewVirus(BlobDto virus, int worldSize)
        {
            var positionAndScale = VirusPrefab.BlobPositioning.GetBlobPositionAndScale(virus, worldSize);
            var virusObject      = (Virus)Instantiate(VirusPrefab, positionAndScale.Position, Quaternion.identity);

            virusObject.transform.localScale = positionAndScale.Scale;
            SaveVirus(virusObject, virus);
        }
    private void SetBlobData(GameObject blob, BlobDto blobDto, int worldSize)
    {
        var scale  = worldSize / 4.5f;
        var radius = (float)(blobDto.Radius / scale);

        blob.transform.localScale = new Vector3(radius, radius, blobDto.Type == BlobType.Virus ? radius : radius * 0.25f);
        blob.transform.position   = new Vector2((float)blobDto.Position.X / scale, (float)blobDto.Position.Y / scale);
    }
Esempio n. 8
0
        public void SaveBlobData(BlobDto dto)
        {
            Directory.CreateDirectory(_blobsFolderPath);
            string filePath = Path.Combine(_blobsFolderPath, dto.FullName);
            var    file     = new FileStream(filePath, FileMode.OpenOrCreate);

            dto.Data.CopyTo(file);
            file.Close();
        }
Esempio n. 9
0
        /// <summary>
        /// Updates the given files path to the new path specified, path should have leading and trailing forward slashes (ex /temp/)
        /// </summary>
        /// <param name="file"></param>
        /// <param name="path"></param>
        /// <returns></returns>
        public async Task <BlobDto> MoveFile(BlobDto file, string path)
        {
            string newPath = $"{path}{file.Name}{Path.GetExtension(file.Path)}";

            file.DateModified = DateTime.UtcNow;

            await UpdateFilePath(file.Path, newPath);

            return(file);
        }
Esempio n. 10
0
        private void SaveVirus(Virus virusObject, BlobDto virus)
        {
            var id = virus.Id;

            if (_virusObjects.ContainsKey(id))
            {
                RemoveVirus(virus);
            }

            _virusObjects.Add(id, virusObject);
        }
        private void SavePlayer(Player playerObject, BlobDto player)
        {
            var id = player.Id;

            if (_playersObjects.ContainsKey(id))
            {
                RemovePlayer(player);
            }

            _playersObjects.Add(id, playerObject);
        }
        private void SaveFood(Food foodObject, BlobDto food)
        {
            var id = food.Id;

            if (_foodObjects.ContainsKey(id))
            {
                RemoveFood(food);
            }

            _foodObjects.Add(id, foodObject);
        }
        private void RemovePlayer(BlobDto playerDto)
        {
            var id = playerDto.Id;

            if (_playersObjects.ContainsKey(id))
            {
                var playerObject = _playersObjects[id];
                Destroy(playerObject.gameObject);
            }

            _playersObjects.Remove(id);
        }
        private void RemoveFood(BlobDto food)
        {
            var id = food.Id;

            if (_foodObjects.ContainsKey(id))
            {
                var foodObject = _foodObjects[id];
                Destroy(foodObject.gameObject);
            }

            _foodObjects.Remove(id);
        }
Esempio n. 15
0
        private void RemoveVirus(BlobDto virus)
        {
            var id = virus.Id;

            if (_virusObjects.ContainsKey(id))
            {
                var virusObject = _virusObjects[id];
                Destroy(virusObject.gameObject);
            }

            _virusObjects.Remove(id);
        }
        public PositionScaleTuple GetBlobPositionAndScale(BlobDto blob, int worldSize)
        {
            var radius      = (float)(blob.Radius / worldSize) * BlobScaleFactor;
            var xPosition   = (float)blob.Position.X / worldSize;
            var yPosition   = (float)blob.Position.Y / worldSize;
            var newScale    = new Vector3(radius, radius, 1.0f);
            var newPosition = new Vector2(xPosition, yPosition);

            return(new PositionScaleTuple {
                Position = newPosition, Scale = newScale
            });
        }
        private void AddNewFood(BlobDto food, int worldSize)
        {
            var positionAndScale = FoodPrefab.BlobPositioning.GetBlobPositionAndScale(food, worldSize);
            var foodObject       = (Food)Instantiate(FoodPrefab, positionAndScale.Position, Quaternion.identity);

            foodObject.transform.localScale = positionAndScale.Scale;

            var colorIndex = _random.Next(0, FoodColors.Count - 1);
            var foodColor  = FoodColors[colorIndex];

            foodObject.UpdateFood(food, worldSize, foodColor);
            SaveFood(foodObject, food);
        }
Esempio n. 18
0
        /// <summary>
        /// Renames the given file
        /// </summary>
        /// <param name="file"></param>
        /// <param name="newName"></param>
        /// <returns></returns>
        public async Task <BlobDto> RenameFile(BlobDto file, string newName)
        {
            string oldPath = file.Path;
            string newPath = oldPath.Replace($"{file.Name}{Path.GetExtension(file.Path)}", newName);

            var blob = await UpdateFilePath(oldPath, newPath);

            blob.Metadata.Add("FileName", Path.GetFileNameWithoutExtension(newName));
            await blob.SetMetadataAsync();

            file.Name        = newName;
            file.StoragePath = blob.Uri.ToString();

            return(file);
        }
Esempio n. 19
0
        public void UpdatePlayer(BlobDto playerBlobDto, int worldSize)
        {
            PlayerBlobDto = playerBlobDto;
            _worldSize    = worldSize;

            var playerName = PlayerBlobDto.Name;

            playerName = playerName.Substring(0, Math.Min(playerName.Length, 10));
            if (TextMesh.text == playerName)
            {
                return;
            }

            TextMesh.characterSize = TextScaleA * (float)Math.Pow(playerName.Length, 2) + TextScaleB * playerName.Length + TextScaleC;
            TextMesh.text          = playerName;
        }
Esempio n. 20
0
        /// <summary>
        /// Replaces a files content and takes a snapshot if take snapshots is enabled
        /// </summary>
        /// <param name="file"></param>
        /// <param name="postedFile"></param>
        /// <returns></returns>
        public async Task <BlobDto> ReplaceFile(BlobDto file, Stream postedFile)
        {
            CloudBlockBlob blob = await GetBlob(file.Path);

            if (_storageOptions.TakeSnapshots)
            {
                await blob.CreateSnapshotAsync();
            }

            await blob.UploadFromStreamAsync(postedFile);

            await blob.FetchAttributesAsync();

            file.FileSize     = blob.Properties.Length;
            file.DateModified = DateTime.UtcNow;

            return(file);
        }
Esempio n. 21
0
        /// <summary>
        /// Moves a folder with its contents to the path given
        /// </summary>
        /// <param name="folder"></param>
        /// <param name="path"></param>
        /// <returns></returns>
        public async Task <BlobDto> MoveFolder(BlobDto folder, string path)
        {
            var container = await GetContainer();

            if (path[path.Length - 1] != '/')
            {
                path = path + "/";
            }

            string newPath = $"{path}{folder.Name}";

            var sourceBlobDir = container.GetDirectoryReference(folder.Path);
            var destBlobDir   = container.GetDirectoryReference(newPath);

            TransferManager.Configurations.ParallelOperations = 64;
            // Setup the transfer context and track the upoload progress
            DirectoryTransferContext context = new DirectoryTransferContext
            {
                ProgressHandler = new Progress <TransferStatus>((progress) =>
                {
                    Console.WriteLine("Bytes uploaded: {0}", progress.BytesTransferred);
                })
            };

            var copyDirOptions = new CopyDirectoryOptions
            {
                Recursive        = true,
                IncludeSnapshots = true
            };

            await TransferManager.CopyDirectoryAsync(sourceBlobDir, destBlobDir, true, copyDirOptions, context);

            await DeleteFile(folder.Path);

            folder.Path         = newPath;
            folder.StoragePath  = destBlobDir.Uri.ToString();
            folder.DateModified = DateTime.UtcNow;

            return(folder);
        }
 public BlobToUpdate(BlobDto blob, BlobEventType eventType, int worldSize)
 {
     Blob      = blob;
     EventType = eventType;
     WorldSize = worldSize;
 }
Esempio n. 23
0
 /// <summary>
 /// Indicates if the current blog is a file
 /// </summary>
 /// <param name="item"></param>
 /// <returns></returns>
 public bool IsFile(BlobDto item)
 {
     return(item.BlobType == BlobType.File);
 }
Esempio n. 24
0
 /// <summary>
 /// indicates if the current blob is a folder
 /// </summary>
 /// <param name="item"></param>
 /// <returns></returns>
 public bool IsFolder(BlobDto item)
 {
     return(item.BlobType == BlobType.Folder);
 }