Beispiel #1
0
        private IEnumerator GetPersonalImprovementsImpl(
            Action <PersonalImprovementsData> onSuccess,
            Action <string> onError)
        {
            UnityWebRequest request = UnityWebRequest.Get(FullUrl(kPersonalImprovements));

            request.SetRequestHeader(authKey, AuthHeader);
            UnityWebRequestAsyncOperation operation = request.SendWebRequest();

            yield return(operation);

            if (operation.isDone)
            {
                if (!operation.webRequest.isHttpError)
                {
                    try {
                        string result = operation.webRequest.downloadHandler.text;
                        string json   = JsonWebToken.Decode(result, secretKey);
                        print(json);
                        JObject parent = JObject.Parse(json);
                        JToken  arr    = parent["response"]["data"];

                        PersonalConvertData    personalConvertData             = ParsePersonalConvertData(arr["c"]);
                        List <StatusPointData> statusPoints                    = ParseStatusPoints(arr["s"]);
                        Dictionary <ProductType, List <ProductData> > products = ParseProducts(arr["i"]);
                        onSuccess?.Invoke(new PersonalImprovementsData(personalConvertData, statusPoints));
                        UDebug.Log("success loading personal improvements");
                    } catch (Exception exception) {
                        UDebug.LogError(exception.Message.Bold());
                        UDebug.LogError(exception.StackTrace.Bold());
                        onError?.Invoke($"{exception.Message}{Environment.NewLine}{exception.StackTrace}");
                    }
                }
                else
                {
                    UDebug.LogError(operation.webRequest.error);
                    onError?.Invoke(operation.webRequest.error);
                }
            }
            else
            {
                UDebug.LogError($"operation {nameof(GetPersonalImprovementsImpl)} is not done".Bold());
                onError?.Invoke($"operation {nameof(GetPersonalImprovementsImpl)} is not done");
            }
        }
Beispiel #2
0
    private static void DownloadPersonalImprovements()
    {
        WebClient webClient = new WebClient();

        webClient.Headers.Add(HttpRequestHeader.Authorization, NetService.AuthHeader);
        string  downloadedString = webClient.DownloadString(NetService.FullUrl(NetService.kPersonalImprovements));
        string  json             = JsonWebToken.Decode(downloadedString, NetService.secretKey);
        JObject parent           = JObject.Parse(json);
        JToken  arr = parent["response"]["data"];

        PersonalConvertData    personalConvertData             = NetService.ParsePersonalConvertData(arr["c"]);
        List <StatusPointData> statusPoints                    = NetService.ParseStatusPoints(arr["s"]);
        Dictionary <ProductType, List <ProductData> > products = NetService.ParseProducts(arr["i"]);
        PersonalImprovementJsonData jsonData                   = new PersonalImprovementsData(personalConvertData, statusPoints).GetJsonData();

        string         serializePath = Path.Combine(Application.dataPath, "Resources/Data/personal_improvements.json");
        JsonSerializer serializer    = new JsonSerializer();

        serializer.Formatting = Formatting.Indented;
        Serialize(serializePath, jsonData);
        Debug.Log("personal improvements saved...".Colored(ConsoleTextColor.orange).BoldItalic());
        EditorUtility.DisplayDialog("Personal improvements loaded", $"data saved to {"Resources/Data/personal_improvements.json"}", "Ok");
    }
Beispiel #3
0
 public static double OfficialConvertCashValue(this PersonalConvertData convertData, double sourceCash)
 {
     return(convertData.OfficialConvertPercent * sourceCash);
 }