Exemple #1
0
    public void onGotHeartBeat(APIEvent e)
    {
        Debug.Log (e.Response);

        CheckInResponse response = Parsing.json_decode<CheckInResponse>(e.Response);

        Globals.CurGameState = (Globals.GameState)response.CheckInResult.CurGameState;

        if(response.CheckInResult.TargetPlayerGuid == Globals.UserID)
        {
            // IM IT!
            Gui.ScoreLabel.text = "Score: " + response.CheckInResult.TargetScore.ToString();
            Gui.TimerLabel.text = "Timer: " + response.CheckInResult.StateTimeExpiration.ToString();
            Gui.CommonLabel.text = "RUN!!!";
        }
        else
        {
            Gui.ScoreLabel.text = "Score: " + response.CheckInResult.TargetScore.ToString();
            Gui.TimerLabel.text = "Timer: " + response.CheckInResult.StateTimeExpiration.ToString();
            foreach(PlayerLocation loc in response.CheckInResult.PlayerLocations)
            {
                if(loc.UserId == response.CheckInResult.TargetPlayerGuid)
                {
                    float dis = GetDistanceFromMeTo(loc);
                    Gui.CommonLabel.text = dis.ToString();
                }
            }
        }
    }
Exemple #2
0
    // TODO: Change to two callbacks: OnRegistered Callback & OnHeartbeat
    public void onRegisterCompleted(APIEvent e)
    {
        Debug.Log("Got callback");

        try {
            RegisterResponse response = Parsing.json_decode<RegisterResponse>(e.Response);

            Globals.UserID = response.RegisterResult.UserId;

            Application.LoadLevel("Game");
        } catch (System.Exception ex) {
            Gui.DebuggingLabel.text = ex.Message;
        }
    }
Exemple #3
0
    // TODO: Change to two callbacks: OnRegistered Callback & OnHeartbeat
    public void onCallCompleted(APIEvent e)
    {
        Debug.Log("Got callback");

        RegisterResponse response = Parsing.json_decode<RegisterResponse>(e.Response);

        Debug.Log ("UserId: " + response.RegisterResult.UserId);
        Debug.Log ("Latitude: " + response.RegisterResult.Latitude);
        Debug.Log ("Longitude: " + response.RegisterResult.Longitude);

        Globals.UserID = response.RegisterResult.UserId;

        Application.LoadLevel("GameScene");
    }
Exemple #4
0
    public void Update()
    {
        while (m_commands.Count > 0)
        {
            JSONCollection data        = m_commands.Dequeue();
            string         commandName = data.Find("command_id");
            string         contents    = data.JSONString();
            int            i           = 0;

            if (data.Find("error_msg") != "")
            {
                ErrorCodes errorCode = (ErrorCodes)data.FindInt("error_code");

                m_output  = "";
                m_output += ("Error Message: " + data.Find("error_msg")) + '\n';
                m_output += ("Error type: " + errorCode.ToString()) + '\n';
                m_output += ("JSON String: " + contents);
                Debug.LogError(m_output);
                return;
            }

            switch (commandName)
            {
            case "connectMovie":
                m_output  += "\nConnect to NG received data: " + data.JSONString() + '\n';
                m_gameName = data.Find("movie_name");

                APIEvent.Activate(APIEvent.EventNames.API_CONNECTED, m_medals);
                break;

            case "getMedals":
                m_medals = new Dictionary <string, Medal>();

                List <JSONCollection> medals = data.GetArray("medals");

                for (i = 0; i < medals.Count; i++)
                {
                    m_output += "Registered medal " + medals[i].Find("medal_name") + '\n';
                    m_medals[medals[i].Find("medal_name")] = new Medal(medals[i]);
                }

                APIEvent.Activate(APIEvent.EventNames.MEDALS_LOADED, m_medals);
                break;

            case "unlockMedal":
                Medal med = m_medals[data.Find("medal_name")];
                if (!med.m_unlocked)
                {
                    Debug.Log("Unlocked medal " + data.Find("medal_name"));
                }
                else
                {
                    Debug.Log("Unlocking medal " + data.Find("medal_name") + " again.");
                }
                med.Unlock();
                APIEvent.Activate(APIEvent.EventNames.MEDAL_UNLOCKED, med);
                break;

            case "preloadSettings":
                m_scoreboards = new Dictionary <string, Scoreboard>();
                List <JSONCollection> scores = data.GetArray("score_boards");

                for (i = 0; i < scores.Count; i++)
                {
                    m_scoreboards.Add(scores[i].Find("name"), new Scoreboard(scores[i]));
                }

                m_saveFiles = new Dictionary <string, SaveFile>();
                List <JSONCollection> saveFiles = data.GetArray("save_groups");

                for (i = 0; i < saveFiles.Count; i++)
                {
                    m_saveFiles[saveFiles[i].Find("group_name")] = new Newgrounds.SaveFile(saveFiles[i]);
                }
                APIEvent.Activate(APIEvent.EventNames.METADATA_LOADED, null);
                break;

            case "loadScores":
                JSONCollection        scoreHolder  = new JSONCollection(contents);
                List <JSONCollection> scoreHolders = scoreHolder.GetArray("scores");

                m_output += "High Scores:\n";
                for (i = 0; i < scoreHolders.Count; i++)
                {
                    m_output += "Name: " + scoreHolders[i].Find("username") + ", Score: " + scoreHolders[i].Find("value") + '\n';
                }

                APIEvent.Activate(APIEvent.EventNames.SCORES_LOADED, scoreHolder);
                break;

            case "saveFile":
                m_output += contents;
                break;

            case "postScore":
                m_output += m_ngUsername + " posted a score of " + data.FindInt("value").ToString() + "!\n";
                List <object> postScoreInfo = new List <object>();

                foreach (Scoreboard sb in m_scoreboards.Values)
                {
                    if (sb.m_id == data.FindInt("board"))
                    {
                        postScoreInfo.Add(sb);
                        break;
                    }
                }
                postScoreInfo.Add(m_userName);
                postScoreInfo.Add(data.FindInt("value"));
                APIEvent.Activate(APIEvent.EventNames.SCORE_POSTED, postScoreInfo);
                break;

            default:
                m_output += contents;
                break;
            }
        }
    }