public void DisplayErrorObject(string error)
        {
            Debug.LogError(error);
            var parsedError = StringSerializationAPI.Deserialize(typeof(FirebaseError), error) as FirebaseError;

            DisplayError(parsedError.message);
        }
Example #2
0
 /// <summary>
 /// Exchanges the Auth Code with the user's Id Token
 /// </summary>
 /// <param name="code"> Auth Code </param>
 /// <param name="callback"> What to do after this is successfully executed </param>
 public static void ExchangeAuthCodeWithIdToken(string code, Action <string> callback)
 {
     RestClient.Post($"https://oauth2.googleapis.com/token?code={code}&client_id={ClientId}&client_secret={ClientSecret}&redirect_uri=urn:ietf:wg:oauth:2.0:oob&grant_type=authorization_code", null).Then(
         response => {
         var data = StringSerializationAPI.Deserialize(typeof(GoogleIdTokenResponse), response.Text) as GoogleIdTokenResponse;
         callback(data.id_token);
     }).Catch(Debug.Log);
 }
Example #3
0
    public static T LoadAction <T>(string path)
    {
        StreamReader streamReader = new StreamReader(GetPath(path));
        string       json         = streamReader.ReadToEnd();

        streamReader.Close();
        T data = (T)StringSerializationAPI.Deserialize(typeof(T), json);

        return(data);
    }
Example #4
0
        public void OnAfterDeserialize()
        {
            string s = serializedType;

            if (!s.StartsWith("\"") && !s.EndsWith("\""))
            {
                s = "\"" + s + "\"";
            }
            type = (Type)StringSerializationAPI.Deserialize(typeof(Type), s);
        }
Example #5
0
        public SliderTree GetSliderTree(string filename)
        {
            try
            {
                return(StringSerializationAPI.Deserialize(typeof(SliderTree), File.ReadAllText(filename)) as SliderTree);
            }
            catch (Exception e)
            {
                Debug.LogError(e.ToString());

                return(null);
            }
        }
Example #6
0
 /// <summary>
 /// Exchanges the Auth Code with the user's Access Token
 /// </summary>
 /// <param name="code"> Auth Code </param>
 /// <param name="callback"> What to do after this is successfully executed </param>
 public static void ExchangeAuthCodeWithIdToken(string code, Action <string> callback)
 {
     RestClient.Post(
         $"https://graph.facebook.com/v5.0/oauth/access_token?code={code}&client_id={ClientId}&client_secret={ClientSecret}&redirect_uri=http://localhost:1234/",
         null).Then(
         response =>
     {
         var data =
             StringSerializationAPI.Deserialize(typeof(FacebookAccessTokenResponse), response.Text) as
             FacebookAccessTokenResponse;
         callback(data.access_token);
     }).Catch(Debug.Log);
 }
Example #7
0
 public void GetUser(Action <User> callback, Action <AggregateException> fallback) =>
 reference.Child($"users/{APIHandler.Instance.authAPI.GetUserId()}").GetValueAsync().ContinueWith(
     task =>
 {
     if (task.IsCanceled || task.IsFaulted)
     {
         fallback(task.Exception);
     }
     else
     {
         callback(StringSerializationAPI.Deserialize(typeof(User), task.Result.GetRawJsonValue()) as User);
     }
 });
    /// Returns a generic object that is serialized to a Resources folder path.
    public static T Load <T> (string resourcesLocalPath)
    {
        // get serialized data from file
        TextAsset serialized = (TextAsset)Resources.Load(resourcesLocalPath, typeof(TextAsset));

        if (serialized == null)
        {
            Debug.LogWarning("No save file found to load: " + GetFullResourcesPath(resourcesLocalPath));
            return(default(T));
        }

        // return deserialized data
        return((T)StringSerializationAPI.Deserialize(typeof(T), serialized.text));
    }
Example #9
0
    public static List <T> LoadAction_list <T>(string path)
    {
        StreamReader streamReader = new StreamReader(GetPath(path));
        var          json         = streamReader.ReadToEnd();
        //var data = JsonUtility.FromJson<ListSaveData<T>>(json);
        var data   = (ListSaveData <T>)StringSerializationAPI.Deserialize(typeof(ListSaveData <T>), json);
        var result = new List <T>();

        foreach (var d in data.saveList)
        {
            result.Add(d);
        }
        return(result);
    }
 public void JoinQueue(string playerId, Action <string> onGameFound, Action <AggregateException> fallback) =>
 DatabaseAPI.PostObject($"matchmaking/{playerId}", "placeholder",
                        () => queueListener = DatabaseAPI.ListenForValueChanged($"matchmaking/{playerId}",
                                                                                args =>
 {
     var gameId =
         StringSerializationAPI.Deserialize(typeof(string), args.Snapshot.GetRawJsonValue()) as
         string;
     if (gameId == "placeholder")
     {
         return;
     }
     LeaveQueue(playerId, () => onGameFound(
                    gameId), fallback);
 }, fallback), fallback);
Example #11
0
    public void ListenForMessages(Action <Message> callback, Action <AggregateException> fallback, string key)
    {
        void CurrentListener(object o, ChildChangedEventArgs args)
        {
            if (args.DatabaseError != null)
            {
                fallback(new AggregateException(new Exception(args.DatabaseError.Message)));
            }
            else
            {
                callback(StringSerializationAPI.Deserialize(typeof(Message), args.Snapshot.GetRawJsonValue()) as Message);
            }
        }

        reference.Child("messages").Child(key).ChildAdded += CurrentListener;
    }
Example #12
0
    //public void PostMessage(Message message, Action callback, Action<AggregateException> fallback)
    //{
    //    var messageJSON = StringSerializationAPI.Serialize(typeof(Message), message);
    //    reference.Child("messages").Push().SetRawJsonValueAsync(messageJSON).ContinueWith(task =>
    //    {
    //        if (task.IsCanceled || task.IsFaulted)
    //            fallback(task.Exception);
    //        else
    //            callback();
    //    });
    //}

    //public void EditMessage(string messageId, string newText, Action callback, Action<AggregateException> fallback)
    //{
    //    var messageJSON = StringSerializationAPI.Serialize(typeof(string), newText);
    //    reference.Child($"messages/{messageId}/text").SetRawJsonValueAsync(messageJSON).ContinueWith(task =>
    //    {
    //        if (task.IsCanceled || task.IsFaulted)
    //            fallback(task.Exception);
    //        else
    //            callback();
    //    });
    //}

    //public void DeleteMessage(string messageId, Action callback, Action<AggregateException> fallback)
    //{
    //    reference.Child($"messages/{messageId}").SetRawJsonValueAsync(null).ContinueWith(task =>
    //    {
    //        if (task.IsCanceled || task.IsFaulted)
    //            fallback(task.Exception);
    //        else
    //            callback();
    //    });
    //}

    public void ListenForUnfold(Action <UnfoldData> callback, Action <AggregateException> fallback)
    {
        void CurrentListener(object o, ChildChangedEventArgs args)
        {
            if (args.DatabaseError != null)
            {
                fallback(new AggregateException(new Exception(args.DatabaseError.Message)));
            }
            else
            {
                callback(StringSerializationAPI.Deserialize(typeof(UnfoldData), args.Snapshot.GetRawJsonValue()) as UnfoldData);
            }
        }

        newMessageListener = CurrentListener;
        reference.Child("worlds/world_1234/pieces").ChildAdded += newMessageListener;
    }
Example #13
0
 public void ListenForMoves(Action <Move> onNewMove)
 {
     moveListener = DatabaseAPI.ListenForValueChanged(
         $"games/{currentGameInfo.gameId}/move",
         args =>
     {
         if (!args.Snapshot.Exists)
         {
             return;
         }
         var move = StringSerializationAPI.Deserialize(typeof(Move), args.Snapshot.GetRawJsonValue()) as Move;
         if (move.userId == MainManager.Instance.currentUserId)
         {
             return;
         }
         onNewMove(move);
     },
         exc => Debug.Log("!!!Fallback subscribe for move!!!"));
 }
Example #14
0
    public static void ExchangeAuthCodeWithIDToken(string code, Action <string> callback)
    {
        Debug.Log("step 1");
        string requestUrl = $"https://oauth2.googleapis.com/token" +
                            $"?client_id={ClientId}" +
                            $"&client_secret={ClientSecret}" +
                            $"&code={code}" +
                            $"&grant_type=authorization_code" +
                            $"&redirect_uri=urn:ietf:wg:oauth:2.0:oob";

        RestClient.Post(requestUrl, null)
        .Then(
            onResolved: response =>
        {
            Debug.Log("step 2");
            var data = StringSerializationAPI.Deserialize(typeof(GoogleIDToken), response.Text) as GoogleIDToken;
            callback(data.id_token);
        });
    }
Example #15
0
    public void ListenForEditedMessages(Action <string, string> callback, Action <AggregateException> fallback)
    {
        void CurrentListener(object o, ChildChangedEventArgs args)
        {
            if (args.DatabaseError != null)
            {
                fallback(new AggregateException(new Exception(args.DatabaseError.Message)));
            }
            else
            {
                callback(args.Snapshot.Key,
                         StringSerializationAPI.Deserialize(typeof(string), args.Snapshot.Child("text").GetRawJsonValue()) as
                         string);
            }
        }

        editedMessageListener = CurrentListener;

        reference.Child("messages").ChildChanged += editedMessageListener;
    }
Example #16
0
        // private readonly Dictionary<string, KeyValuePair<DatabaseReference, EventHandler<ChildChangedEventArgs>>>
        //     moveListeners =
        //         new Dictionary<string, KeyValuePair<DatabaseReference, EventHandler<ChildChangedEventArgs>>>();

        public void GetCurrentGameInfo(string gameId, string localPlayerId, Action <GameInfo> callback,
                                       Action <AggregateException> fallback)
        {
            currentGameInfoListener =
                DatabaseAPI.ListenForValueChanged($"games/{gameId}/gameInfo", args =>
            {
                if (!args.Snapshot.Exists)
                {
                    return;
                }

                var gameInfo =
                    StringSerializationAPI.Deserialize(typeof(GameInfo), args.Snapshot.GetRawJsonValue()) as
                    GameInfo;
                currentGameInfo = gameInfo;
                currentGameInfo.localPlayerId = localPlayerId;
                DatabaseAPI.StopListeningForValueChanged(currentGameInfoListener);
                callback(currentGameInfo);
            }, fallback);
        }
Example #17
0
        // Loads and returns the recipe with given name as parameter
        public static Recipe LoadRecipe(string recipeName)
        {
            BinaryFormatter bf = new BinaryFormatter();
            FileStream      file;

            if (File.Exists(Application.dataPath + "/Recipes/" + recipeName + ".vrcr"))
            {
                file = File.OpenRead(Application.dataPath + "/Recipes/" + recipeName + ".vrcr");
            }
            else
            {
                return(null);
            }

            Recipe loadedRecipe = (Recipe)StringSerializationAPI.Deserialize(typeof(Recipe), (string)bf.Deserialize(file));

            file.Close();

            return(loadedRecipe);
        }
Example #18
0
        public void DisplayUserInfo(string user)
        {
            var parsedUser = StringSerializationAPI.Deserialize(typeof(FirebaseUser), user) as FirebaseUser;

            DisplayData($"Email: {parsedUser.email}, UserId: {parsedUser.uid}, EmailVerified: {parsedUser.isEmailVerified}");
        }
    public static T FromJson_full <T>(string json)
    {
        var data = (T)StringSerializationAPI.Deserialize(typeof(T), json);

        return(data);
    }