Ejemplo n.º 1
0
        private void UpdateValue(string chapter, int level, Vector2Int pos, int used)
        {
            string key = $"{pos.x}:{pos.y}";

            FireBaseDatabase.Database.Child(FireBaseSavePaths.HeatMapLocation(chapter, level)).RunTransaction(mutableData =>
            {
                List <object> storedData = mutableData.Value as List <object>;

                if (storedData == null)
                {
                    storedData = new List <object>();
                }

                int newUses = used;

                foreach (var child in storedData)
                {
                    var parsedChild = child as Dictionary <string, object>;
                    if (parsedChild == null)
                    {
                        continue;
                    }

                    if (!parsedChild.ContainsKey("Key"))
                    {
                        continue;
                    }
                    if (parsedChild["Key"].ToString() != key)
                    {
                        continue;
                    }

                    if (!parsedChild.ContainsKey("Uses"))
                    {
                        continue;
                    }
                    string data = parsedChild["Uses"].ToString();

                    int childValue = int.Parse(data);
                    newUses       += childValue;

                    storedData.Remove(child);

                    break;
                }

                Dictionary <string, object> newMap = new Dictionary <string, object>();
                newMap["Key"]  = key;
                newMap["Uses"] = newUses;
                storedData.Add(newMap);
                mutableData.Value = storedData;
                return(TransactionResult.Success(mutableData));
            }

                                                                                                              );
        }
Ejemplo n.º 2
0
        public void GetHeatmapAsync(string chapter, int level)
        {
            try
            {
                FireBaseDatabase.Database.Child(FireBaseSavePaths.HeatMapLocation(chapter, level))
                .GetValueAsync().ContinueWith(task =>
                {
                    if (task.IsFaulted)
                    {
                    }
                    else if (task.IsCompleted)
                    {
                        try
                        {
                            DataSnapshot snapshot = task.Result;
                            var result            = new Dictionary <string, int>();

                            var list = snapshot.Value as List <object>;
                            foreach (var item in list)
                            {
                                var parsedChild = item as Dictionary <string, object>;

                                var key  = parsedChild["Key"].ToString();
                                var uses = parsedChild["Uses"].ToString();

                                int childValue = int.Parse(uses);

                                result.Add(key, childValue);
                            }

                            HeatmapLoaded?.Invoke(result);
                        }
                        catch (Exception ex)
                        {
                            Debug.LogError(ex);
                        }
                    }
                });
            }
            catch { }
        }