Beispiel #1
0
        public static void Get(Objects.User user, Action <Objects.User> callback)
        {
            var parameters = new Dictionary <string, string>();

            if (user.Name != null && user.Name != string.Empty)
            {
                parameters.Add("username", user.Name.ToLower());
            }
            else if (user.ID != 0)
            {
                parameters.Add("user_id", user.ID.ToString());
            }

            Core.Request.Get(Constants.API_USERS_FETCH, parameters, (Core.Response response) => {
                if (response.success)
                {
                    user.BulkUpdate(response.json["users"][0].AsObject);
                }
                else
                {
                    user = null;
                }

                if (callback != null)
                {
                    callback(user);
                }
            }, false);
        }
Beispiel #2
0
		public static void Get(int[] ids, Action<Objects.User[]> callback)
		{
			var parameters = new Dictionary<string, string>();
			parameters.Add(Constants.API_USERS_FETCH, string.Join(",", ids.Select(id => id.ToString()).ToArray()));

			Core.Request.Get("users/", parameters, (Core.Response response) => {
				Objects.User[] users;
				if(response.success)
				{
					int count = response.json["users"].AsArray.Count;
					users = new Objects.User[count];

					for (int i = 0; i < count; ++i)
					{
						users[i] = new Objects.User(response.json["users"][i].AsObject);
					}
				}
				else
				{
					users = null;
				}
				
				if (callback != null)
				{
					callback(users);
				}
			}, false);
		}
Beispiel #3
0
        public static void Get(int[] ids, Action <Objects.User[]> callback)
        {
            var parameters = new Dictionary <string, string>();

            parameters.Add(Constants.API_USERS_FETCH, string.Join(",", ids.Select(id => id.ToString()).ToArray()));

            Core.Request.Get("users/", parameters, (Core.Response response) => {
                Objects.User[] users;
                if (response.success)
                {
                    int count = response.json["users"].AsArray.Count;
                    users     = new Objects.User[count];

                    for (int i = 0; i < count; ++i)
                    {
                        users[i] = new Objects.User(response.json["users"][i].AsObject);
                    }
                }
                else
                {
                    users = null;
                }

                if (callback != null)
                {
                    callback(users);
                }
            }, false);
        }
    private IEnumerator AnimateRank(Upload upload, int stepCount)
    {
        int          calculatedRank    = -1;
        Score        previousBestScore = null;
        int          previousBestRank  = -1;
        bool         isRankLoaded      = false;
        List <Score> leaderboard       = upload.Leaderboards;

        GameJolt.API.Objects.User currentUser = GameJolt.API.Manager.Instance.CurrentUser;

        bool isUserAuthor = (currentUser.ID == upload.AuthorID);

        GameJolt.API.Misc.GetTime(dateTime => {
            isRankLoaded = true;
            upload.AddToLeaderboard(currentUser, stepCount, dateTime, out calculatedRank, out previousBestScore, out previousBestRank, isSuccess => {
                isRankLoaded = true;
            });
        });
        yield return(new WaitUntil(() => isRankLoaded));

        yield return(Util.AnimateScore(rank, 0, calculatedRank, 0.35f, scoreSound));

        if (previousBestScore != null)
        {
            pastStepsLabel.gameObject.SetActive(true);
            pastStepsLabel.color = Color.yellow;
            pastStepsLabel.text  = string.Format("Old steps: {0}", previousBestScore.Steps);
            pastRankingLabel.gameObject.SetActive(true);
            pastRankingLabel.color = Color.yellow;
            pastRankingLabel.text  = string.Format("Old rank: {0}", previousBestRank);
        }
    }
Beispiel #5
0
	public void SignIn()
	{
		Debug.Log("Sign In. Click to see source.");

		var user = new GameJolt.API.Objects.User(userNameField.text, userTokenField.text);
		user.SignIn((bool success) => {
			AddConsoleLine(string.Format("Sign In {0}.", success ? "Succeesful" : "Failed"));
		});
	}
Beispiel #6
0
    public void SignIn()
    {
        Debug.Log("Sign In. Click to see source.");

        var user = new GameJolt.API.Objects.User(userNameField.text, userTokenField.text);

        user.SignIn((bool success) => {
            AddConsoleLine(string.Format("Sign In {0}.", success ? "Succeesful" : "Failed"));
        });
    }
Beispiel #7
0
        void AutoConnectWebPlayer()
        {
#if UNITY_WEBPLAYER || UNITY_WEBGL
        #if UNITY_EDITOR
            if (DebugAutoConnect)
            {
                if (DebugUser != string.Empty && DebugToken != string.Empty)
                {
                    var user = new Objects.User(DebugUser, DebugToken);
                    user.SignIn((bool success) => { Debug.Log(string.Format("AutoConnect: " + success)); });
                }
                else
                {
                    Debug.LogWarning("Cannot simulate WebPlayer AutoConnect. Missing user and/or token in debug settings.");
                }
            }
        #else
            var uri = new Uri(Application.absoluteURL);
            if (uri.Host.EndsWith("gamejolt.net") || uri.Host.EndsWith("gamejolt.com"))
            {
                                #if UNITY_WEBPLAYER
                Application.ExternalCall("GJAPI_AuthUser", this.gameObject.name, "OnAutoConnectWebPlayer");
                                #elif UNITY_WEBGL
                Application.ExternalEval(string.Format(@"
var qs = location.search;
var params = {{}};
var tokens;
var re = /[?&]?([^=]+)=([^&]*)/g;

while (tokens = re.exec(qs)) {{
	params[decodeURIComponent(tokens[1])] = decodeURIComponent(tokens[2]);
}}

var message;
if ('gjapi_username' in params && params.gjapi_username !== '' && 'gjapi_token' in params && params.gjapi_token !== '') {{
	message = params.gjapi_username + ':' + params.gjapi_token;	
}}
else {{
	message = '';
}}

SendMessage('{0}', 'OnAutoConnectWebPlayer', message);
		"        , this.gameObject.name));
                                #endif
            }
            else
            {
                Debug.Log("Cannot AutoConnect, the game is not hosted on GameJolt.");
            }
        #endif
#endif
        }
Beispiel #8
0
 public void SignIn(string username, string token, APILoginController loginMenu)
 {
     GameJolt.API.Objects.User user = new GameJolt.API.Objects.User(username, token);
     user.SignIn((bool success) => {
         if (success)
         {
             signedIn = true;
             loginMenu.ToggleLoginButton(true);
             loginMenu.CloseLoginMenu();
         }
         else
         {
             loginMenu.SetErrorText("api.txt.noconnection");
         }
     });
 }
    private IEnumerator AnimateRank(int stepCount)
    {
        int   calculatedRank    = -1;
        Score previousBestScore = null;
        int   previousBestRank  = -1;
        bool  isRankLoaded      = false;

        GameJolt.API.Misc.GetTime(dateTime => {
            if (scoreIDOverride == 0)
            {
                Upload upload            = LevelInfo.Instance.Upload;
                List <Score> leaderboard = upload.Leaderboards;
                GameJolt.API.Objects.User currentUser = GameJolt.API.Manager.Instance.CurrentUser;

                bool isUserAuthor = (currentUser.ID == upload.AuthorID);
                upload.AddToLeaderboard(currentUser, stepCount, dateTime, out calculatedRank, out previousBestScore, out previousBestRank, isSuccess => {
                    isRankLoaded = true;
                });
            }
            else
            {
                GameJolt.API.Scores.GetRank(stepCount, scoreIDOverride, rank => {
                    Debug.Log("Rank load successful: " + rank);
                    calculatedRank = rank - 1;
                    GameJolt.API.Scores.Add(stepCount, stepCount.ToString(), scoreIDOverride);
                    isRankLoaded = true;
                });
            }
        });
        yield return(new WaitUntil(() => isRankLoaded));

        yield return(Util.AnimateScore(rank, 0, calculatedRank, 0.35f, scoreSound));

        if (previousBestScore != null)
        {
            pastStepsLabel.gameObject.SetActive(true);
            pastStepsLabel.color = Color.yellow;
            pastStepsLabel.text  = string.Format("Old steps: {0}", previousBestScore.Steps);
            pastRankingLabel.gameObject.SetActive(true);
            pastRankingLabel.color = Color.yellow;
            pastRankingLabel.text  = string.Format("Old rank: {0}", previousBestRank);
        }
    }
 public void OnAutoConnectWebPlayer(string response)
 {
     if (response != string.Empty)
     {
         var credentials = response.Split(new[] { ':' }, 2);
         if (credentials.Length == 2)
         {
             var user = new Objects.User(credentials[0], credentials[1]);
             user.SignIn();
             // TODO: Prompt "Welcome Back <username>!"
         }
         else
         {
             LogHelper.Info("Cannot AutoConnect.");
         }
     }
     else
     {
         // This is a Guest.
         // TODO: Prompt "Hello Guest!" and encourage to signup/signin?
     }
 }
 public void OnAutoConnectWebPlayer(string response)
 {
     if (response != string.Empty)
     {
         var credentials = response.Split(new[] { ':' }, 2);
         if (credentials.Length == 2)
         {
             var user = new Objects.User(credentials[0], credentials[1]);
             user.SignIn(success => AutoLoginEvent.Invoke(success ? AutoLoginResult.Success : AutoLoginResult.Failed));
             // TODO: Prompt "Welcome Back <username>!"
         }
         else
         {
             LogHelper.Info("Cannot AutoConnect.");
             AutoLoginEvent.Invoke(AutoLoginResult.MissingCredentials);
         }
     }
     else
     {
         // This is a Guest.
         // TODO: Prompt "Hello Guest!" and encourage to signup/signin?
         AutoLoginEvent.Invoke(AutoLoginResult.MissingCredentials);
     }
 }
Beispiel #12
0
		public static void Get(string name, Action<Objects.User> callback)
		{
			var user = new Objects.User(name, string.Empty);
			Get(user, callback);
		}
Beispiel #13
0
		public static void Get(int id, Action<Objects.User> callback)
		{
			var user = new Objects.User(id);
			Get(user, callback);
		}
Beispiel #14
0
        public static void Get(string name, Action <Objects.User> callback)
        {
            var user = new Objects.User(name, string.Empty);

            Get(user, callback);
        }
Beispiel #15
0
        public static void Get(int id, Action <Objects.User> callback)
        {
            var user = new Objects.User(id);

            Get(user, callback);
        }