Esempio n. 1
0
    public static void LoadGamesFromFile()
    {
        var file        = Resources.Load <TextAsset>("testgames");
        var loadedGames = JsonHelper.ArrayFromJson <BPGame>(file.text);

        games.AddRange(loadedGames);
    }
    public void GetLeaderboard(Action <List <ScoreData> > onSucces)
    {
        RequestHelper request = new RequestHelper
        {
            Uri  = "http://localhost:3000/leaderboard/list",
            Body = new Token
            {
                token = token,
            }
        };

        request.Headers.Add("x-access-token", token);

        RestClient.Get <Response>(request).Then((res) =>
        {
            if (res.code == "1")
            {
                List <ScoreData> scores = JsonHelper.ArrayFromJson <ScoreData>(res.message).ToList();

                onSucces(scores);
            }

            MenuController.Instance.SetLeaderboardErrorMessage(res.message);


            RestClient.CleanDefaultHeaders();
        }).Catch((err) =>
        {
            RestClient.CleanDefaultHeaders();
            MenuController.Instance.SetLeaderboardErrorMessage(err.Message);

            Debug.Log(err.Message);
        });
    }
Esempio n. 3
0
        private void OnGetCharactersCallback(long statusCode, string json)
        {
            var characters = GetSampleCharacterData();

            // Hack: "[]"
            if (json != "[]")
            {
                CharacterData[] characterData;

                // NOTE: Unity json allows getting "Items" only (from dummy api)
                if (json.Contains("Items"))
                {
                    characterData = JsonHelper.FromJsonString <CharacterData>(json);
                }
                else
                {
                    characterData = JsonHelper.ArrayFromJson <CharacterData>(json);
                }

                if (characterData != null && characterData.Length != 0)
                {
                    // Replaces sample character with existing characters
                    foreach (var character in characterData)
                    {
                        var index = character.index;

                        characters[index].id            = character.id;
                        characters[index].charactername = character.charactername;
                        characters[index].classindex    = character.classindex;
                    }
                }
            }

            // Create samples and/or existing characters
            foreach (var character in characters)
            {
                var id                 = character.id;
                var name               = character.charactername;
                var index              = (UICharacterIndex)character.index;
                var classindex         = (UICharacterClass)character.classindex;
                var uiCharacterDetails =
                    new UICharacterDetails(id, name, index, classindex);

                onCharacterReceivedListener.OnCharacterReceived(uiCharacterDetails);
            }

            onCharacterReceivedListener.OnAfterCharacterReceived();
        }
Esempio n. 4
0
        private void OnGetGamesCallback(long statusCode, string json)
        {
            if (statusCode == 200) // Ok
            {
                var gameData = JsonHelper.ArrayFromJson <GameData>(json);
                if (gameData.Length != 0)
                {
                    var uiGameData =
                        gameData.Select((x) => new UIGameServerButtonData(
                                            x.name,
                                            x.protocol,
                                            x.url));

                    onGameServerReceivedListener.OnGameServerReceived(uiGameData);
                }
            }
        }
Esempio n. 5
0
        private void TestUserProfiles()
        {
            UserDataService userDataService = new UserDataService();

            var core = Service.Get <Core>();

            if (core != null)
            {
                core.GameStartCoroutine(userDataService.GetData((string data) =>
                {
                    if (!string.IsNullOrEmpty(data))
                    {
                        UserData[] userData = JsonHelper.ArrayFromJson <UserData>(data);
                        if (userData != null && userData.Length > 0)
                        {
                        }
                    }
                }));
            }
        }
Esempio n. 6
0
 // called zero
 void Awake()
 {
     StartCoroutine(ServerAPI.getUserInfo(1, (_userInfo) =>
     {
         // "id": "1",
         // "Family": "\u0418\u0432\u0430\u043d\u043e\u0432",
         // "Name": "\u0418\u0432\u0430\u043d",
         // "Father": "\u0418\u0432\u0430\u043d\u043e\u0432\u0438\u0447",
         // "UserName": "******",
         // "Password": "******",
         // "Role": "\u0410\u0434\u043c\u0438\u043d\u0438\u0441\u0442\u0440\u0430\u0442\u043e\u0440",
         // "idGroup": "0",
         // "Telefon": "9171111111",
         // "DateBD": "2000-08-14"
         //You can now use the v_UserToken variable
         var _users       = JsonHelper.ArrayFromJson <User>(_userInfo);
         this._fio.text   = $"{_users[0].Family} {_users[0].Name} {_users[0].Father}";
         this._age.text   = _users[0].Ages;
         this._cubes.text = _users[0].NameGroup;
     }));
 }
Esempio n. 7
0
    // Processes the data received from the cloud.
    public void HandleDriveResponse(Drive.DataContainer dataContainer)
    {
        if (dataContainer.QueryType == Drive.QueryType.getTable)
        {
            string rawJSon = dataContainer.payload;
            //Debug.Log(rawJSon);
            // Check if the type is correct.
            if (string.Compare(dataContainer.objType, tabName) == 0)
            {
                // Parse from json to the desired object type.
                // PlayerInfo[] players = JsonHelper.ArrayFromJson<PlayerInfo>(rawJSon);
                DialogueInfo[] dialogueInfo = JsonHelper.ArrayFromJson <DialogueInfo>(rawJSon);
                print(dialogueInfo[dialogueInfo.Length - 1].text);

                var newDialogue = dialogueInfo[dialogueInfo.Length - 1].text;

                if (!_currentDialogueText.Equals(newDialogue))
                {
                    _currentDialogueText = newDialogue;
                    TextParser.UpdateText(_currentDialogueText);
                }
            }
        }
    }
Esempio n. 8
0
 private void Completed(string jsonResult)
 {
     IsDone = true;
     OnComplete?.Invoke(JsonHelper.ArrayFromJson <T>(jsonResult).ToList());
 }
Esempio n. 9
0
    public void LoadData()
    {
        DateTime startTime = DateTime.Now;

        lastStatus = "Starting large database read...";
        print("*** Starting database read...");
        //FirebaseDatabase.DefaultInstance.GetReferenceFromUrl(DATA_URL).Child(spreadsheetID).GetValueAsync()

        databaseReference.Child(spreadsheetID).GetValueAsync()
        .ContinueWith((task => {
            if (task.IsCanceled)
            {
                Firebase.FirebaseException e =
                    task.Exception.Flatten().InnerExceptions[0] as Firebase.FirebaseException;

                GetErrorMessage((AuthError)e.ErrorCode);

                return;
            }

            if (task.IsFaulted)
            {
                Firebase.FirebaseException e =
                    task.Exception.Flatten().InnerExceptions[0] as Firebase.FirebaseException;

                GetErrorMessage((AuthError)e.ErrorCode);

                return;
            }

            if (task.IsCompleted)
            {
                print("in LoadData(), task.IsCompleted.");
                lastStatus = "in LoadData(), task.IsCompleted.";
                DataSnapshot snapshot = task.Result;             //task.Result;

                string photoData = snapshot.GetRawJsonValue();
                //print("photoData = " + photoData);

                // Parse from json to the desired object type.
                PhotoData[] photos = JsonHelper.ArrayFromJson <PhotoData>(photoData);
                photosTable = photos;             // allPhotos is public array of all the photo info

                //int rowCount = 0;

                //foreach (var child in snapshot.Children)
                //{

                //    string t = child.GetRawJsonValue();
                //    rowCount++;
                //    PhotoData extractedData = JsonUtility.FromJson<PhotoData>(t);
                //    if(rowCount < 10)
                //    {
                //        print("row " + rowCount + " t: " + t);
                //        print("photoUID: " + extractedData.Photo_uid + ", size: " + extractedData.Size + ", location: " + extractedData.Location);
                //        print("extractedData = " + extractedData);
                //    }

                //}
                lastStatus = "allPhotos.Length = " + photosTable.Length;
                print("allPhotos.Length = " + photosTable.Length);
                TimeElapsed(startTime);
            }
        }));
    }