Ejemplo n.º 1
0
    internal IEnumerator SendRequest <T>(string section, string action, Action <Dictionary <string, T>, PResponse> callback) where T : GameVar, new()
    {
        var www = PRequest.Prepare(section, action, null);

        yield return(www);

        var response = PRequest.Process(www);

        var data = response.success ? response.json : null;

        Dictionary <string, T> gameVars = new Dictionary <string, T>();

        if (data != null)
        {
            if (data is IDictionary)
            {
                foreach (string key in data.Keys)
                {
                    if (data[key] is IDictionary)
                    {
                        gameVars.Add(key, (T)Activator.CreateInstance(typeof(T), new object[] { data[key] }));
                    }
                }
            }
        }

        callback(gameVars, response);
    }
Ejemplo n.º 2
0
    private IEnumerator SendListRequest <T>(Dictionary <string, object> postdata, Action <List <T>, int, PResponse> callback) where T : PlayerLevel, new()
    {
        var www = PRequest.Prepare(SECTION, LIST, postdata);

        yield return(www);

        var      response  = PRequest.Process(www);
        List <T> levels    = null;
        int      numlevels = 0;

        if (response.success)
        {
            var data = response.json;
            levels    = new List <T>();
            numlevels = (int)(double)data["numlevels"];

            var levelarr = (List <object>)data["levels"];

            for (var i = 0; i < levelarr.Count; i++)
            {
                levels.Add((T) new PlayerLevel((Dictionary <string, object>)levelarr[i]));
            }
        }

        callback(levels, numlevels, response);
    }
Ejemplo n.º 3
0
    internal IEnumerator SendRequest <T>(string name, string section, string action, Action <T, PResponse> callback, Dictionary <string, object> postdata = null) where T : GameVar, new()
    {
        var www = PRequest.Prepare(section, action, postdata);

        yield return(www);

        var response = PRequest.Process(www);

        var data = response.success ? response.json : null;

        T gameVar = new T();

        if (data != null)
        {
            if (data is IDictionary)
            {
                if (data.ContainsKey(name))
                {
                    gameVar = (T)Activator.CreateInstance(typeof(T), new object[] { data[name] });
                }
            }
        }

        callback(gameVar, response);
    }
Ejemplo n.º 4
0
    private IEnumerator SendListRequest <T>(string section, string action, Dictionary <string, object> postdata, Action <List <T>, int, PResponse> callback) where T : PlayerScore
    {
        WWW www = PRequest.Prepare(section, action, postdata);

        yield return(www);

        var response = PRequest.Process(www);
        var data     = response.json;

        List <T> scores = new List <T>();

        int numscores = 0;

        if (response.success)
        {
            if (data.ContainsKey("numscores"))
            {
                int.TryParse(data["numscores"].ToString(), out numscores);
            }

            if (data.ContainsKey("scores"))
            {
                if (data["scores"] is IList)
                {
                    foreach (IDictionary score in (IList)data["scores"])
                    {
                        scores.Add((T)Activator.CreateInstance(typeof(T), new object[] { score }));
                    }
                }
            }
        }

        callback(scores, numscores, response);
    }
Ejemplo n.º 5
0
    private IEnumerator SendRateRequest(Dictionary <string, object> postdata, Action <PResponse> callback)
    {
        var www = PRequest.Prepare(SECTION, RATE, postdata);

        yield return(www);

        var response = PRequest.Process(www);

        callback(response);
    }
Ejemplo n.º 6
0
    internal IEnumerator SendSaveRequest(string section, string action, Action <PResponse> callback, Dictionary <string, object> postdata = null)
    {
        var www = PRequest.Prepare(section, action, postdata);

        yield return(www);

        var response = PRequest.Process(www);

        callback(response);
    }
Ejemplo n.º 7
0
    private IEnumerator SendSaveRequest(string section, string action, Dictionary <string, object> postdata, Action <PResponse> callback)
    {
        WWW www = PRequest.Prepare(section, action, postdata);

        yield return(www);

        PResponse response = PRequest.Process(www);

        callback(response);
    }
Ejemplo n.º 8
0
    private IEnumerator SendRequest(string section, string action, Action <PResponse> callback, PNewsletterOptions options)
    {
        var www = PRequest.Prepare(section, action, options);

        yield return(www);

        var response = PRequest.Process(www);

        callback(response);
    }
Ejemplo n.º 9
0
    private IEnumerator SendRequest(string section, string action, Action <PlayerCountry, PResponse> callback)
    {
        var www = PRequest.Prepare(section, action);

        yield return(www);

        var response = PRequest.Process(www);
        var data     = response.success ? response.json : null;

        callback(new PlayerCountry(data), response);
    }
Ejemplo n.º 10
0
    private IEnumerator SendSaveLoadRequest <T>(string section, string action, Dictionary <string, object> postdata, Action <T, PResponse> callback) where T : PlayerLevel
    {
        var www = PRequest.Prepare(section, action, postdata);

        yield return(www);

        var response = PRequest.Process(www);
        T   level    = default(T);

        if (response.success)
        {
            level = (T) new PlayerLevel((Dictionary <string, object>)response.json["level"]);
        }

        callback(level, response);
    }
Ejemplo n.º 11
0
    private IEnumerator SendSaveLoadRequest(string section, string action, Dictionary <string, object> postdata, Action <PlayerLevel, PResponse> callback)
    {
        var www = PRequest.Prepare(section, action, postdata);

        yield return(www);

        var         response = PRequest.Process(www);
        PlayerLevel level    = null;

        if (response.success)
        {
            level = new PlayerLevel((Dictionary <string, object>)response.json["level"]);
        }

        callback(level, response);
    }
Ejemplo n.º 12
0
    internal IEnumerator SendListRequest <T>(string section, string action, Action <List <T>, PResponse> callback, Dictionary <string, object> postdata = null) where T : PlayerAchievement
    {
        var www = PRequest.Prepare(section, action, postdata);

        yield return(www);

        var response = PRequest.Process(www);
        var data     = response.success ? response.json : null;

        List <T> achievements = new List <T>();

        if (response.success)
        {
            foreach (IDictionary achievment in (IList)data["achievements"])
            {
                achievements.Add((T)Activator.CreateInstance(typeof(T), new object[] { achievment }));
            }
        }

        callback(achievements, response);
    }
Ejemplo n.º 13
0
    internal IEnumerator SendStreamRequest(string section, string action, Action <List <PlayerAward>, int, PResponse> callback, Dictionary <string, object> postdata = null)
    {
        var www = PRequest.Prepare(section, action, postdata);

        yield return(www);

        var response = PRequest.Process(www);
        var data     = response.success ? response.json : null;

        int numachievements = 0;

        int.TryParse(data["numachievements"].ToString(), out numachievements);

        var achievements = new List <PlayerAward>();

        if (response.success)
        {
            var acharray = (List <object>)data["achievements"];
            achievements.AddRange(from object t in acharray select new PlayerAward((Dictionary <string, object>)t));
        }

        callback(achievements, numachievements, response);
    }