protected override void LoadPayload(ScreenLoadPromise promise)
    {
        coverImage.color = Color.black;

        if (IntentPayload.Collection != null)
        {
            promise.Resolve(IntentPayload);
            return;
        }

        SpinnerOverlay.Show();
        RestClient.Get <CollectionMeta>(new RequestHelper
        {
            Uri         = $"{Context.ApiUrl}/collections/{IntentPayload.CollectionId}",
            Headers     = Context.OnlinePlayer.GetRequestHeaders(),
            EnableDebug = true
        })
        .Then(meta =>
        {
            IntentPayload.Collection = meta;

            promise.Resolve(IntentPayload);
        })
        .CatchRequestError(error =>
        {
            Debug.LogError(error);
            Dialog.PromptGoBack("DIALOG_COULD_NOT_CONNECT_TO_SERVER".Get());

            promise.Reject();
        })
        .Finally(() => SpinnerOverlay.Hide());
    }
Example #2
0
    protected override async void LoadPayload(ScreenLoadPromise promise)
    {
        SpinnerOverlay.Show();
        await Context.LevelManager.LoadLevelsOfType(LevelType.User);

        RestClient.GetArray <EventMeta>(new RequestHelper
        {
            Uri         = $"{Context.ApiUrl}/events",
            Headers     = Context.OnlinePlayer.GetRequestHeaders(),
            EnableDebug = true
        }).Then(data =>
        {
            if (data.Length == 0)
            {
                Dialog.PromptGoBack("DIALOG_EVENTS_NOT_AVAILABLE".Get());
                promise.Reject();
                return;
            }
            IntentPayload.Events = data.ToList();
            promise.Resolve(IntentPayload);
        })
        .CatchRequestError(error =>
        {
            Debug.LogError(error);
            Dialog.PromptGoBack("DIALOG_COULD_NOT_CONNECT_TO_SERVER".Get());

            promise.Reject();
        })
        .Finally(() => SpinnerOverlay.Hide());
    }
Example #3
0
    protected override void LoadPayload(ScreenLoadPromise promise)
    {
        IntentPayload.IsPlayer = IntentPayload.Id == Context.OnlinePlayer.LastProfile?.User.Id;
        if (IntentPayload.Profile != null)
        {
            promise.Resolve(IntentPayload);
            return;
        }
        if (IntentPayload.IsPlayer)
        {
            if (Context.OnlinePlayer.LastFullProfile != null)
            {
                IntentPayload.Profile = Context.OnlinePlayer.LastFullProfile;
                promise.Resolve(IntentPayload);
                return;
            }

            if (Context.IsOffline())
            {
                // Fetch offline profile and cast it as full profile
                Context.OnlinePlayer.FetchProfile()
                .Then(profile =>
                {
                    var fullProfile =
                        JsonConvert.DeserializeObject <FullProfile>(JsonConvert.SerializeObject(profile));
                    IntentPayload.Profile = fullProfile;
                    promise.Resolve(IntentPayload);
                })
                .CatchRequestError(error =>
                {
                    Debug.LogError(error);
                    Dialog.PromptGoBack("DIALOG_OFFLINE_FEATURE_NOT_AVAILABLE".Get());
                });
                return;
            }
        }

        SpinnerOverlay.Show();
        RestClient.Get <FullProfile>(new RequestHelper
        {
            Uri         = $"{Context.ApiUrl}/profile/{IntentPayload.Id}/details",
            Headers     = Context.OnlinePlayer.GetRequestHeaders(),
            EnableDebug = true
        }).Then(data =>
        {
            if (IntentPayload.IsPlayer)
            {
                Context.OnlinePlayer.LastFullProfile = data;
            }
            IntentPayload.Profile = data;
            promise.Resolve(IntentPayload);
        }).CatchRequestError(error =>
        {
            Debug.LogError(error);
            Dialog.PromptGoBack("DIALOG_COULD_NOT_CONNECT_TO_SERVER".Get());
        }).Finally(() => SpinnerOverlay.Hide());
    }
Example #4
0
    protected override void LoadPayload(ScreenLoadPromise promise)
    {
        SpinnerOverlay.Show();
        Context.CharacterManager.GetAvailableCharactersMeta()
        .Then(async characters =>
        {
            try
            {
                if (Application.isEditor)
                {
                    Debug.Log("Available characters:");
                    characters.PrintJson();
                }

                if (characters.Count == 0)
                {
                    // TODO: This should not happen! We have Sayaka
                    SpinnerOverlay.Hide();
                    Dialog.PromptGoBack("DIALOG_OFFLINE_FEATURE_NOT_AVAILABLE".Get());
                    promise.Reject();
                    return;
                }

                if (!await Context.BundleManager.DownloadAndSaveCatalog())
                {
                    SpinnerOverlay.Hide();
                    Dialog.PromptGoBack("DIALOG_COULD_NOT_CONNECT_TO_SERVER".Get());
                    promise.Reject();
                    return;
                }

                SpinnerOverlay.Hide();

                var downloadsRequired = 0;
                foreach (var meta in characters)
                {
                    if (!Context.BundleManager.IsUpToDate(CharacterAsset.GetMainBundleId(meta.AssetId)))
                    {
                        downloadsRequired++;
                    }
                }

                print($"Number of downloads required: {downloadsRequired}");

                var downloaded = 0;
                foreach (var meta in characters)
                {
                    var(success, locallyResolved) =
                        await Context.CharacterManager.DownloadCharacterAssetDialog(
                            CharacterAsset.GetMainBundleId(meta.AssetId));
                    if (success && !locallyResolved)
                    {
                        downloaded++;
                        print("Downloaded " + meta.AssetId);
                    }

                    if (!success)
                    {
                        Toast.Next(Toast.Status.Failure, "CHARACTER_FAILED_TO_DOWNLOAD".Get());
                    }
                    else
                    {
                        IntentPayload.OwnedCharacters.Add(meta);
                    }
                }

                print($"Number of downloads: {downloaded}");

                if (downloaded > downloadsRequired)
                {
                    // Update was performed, which requires player to restart the game
                    // Why? Too lazy to figure out dynamic reloads...
                    Dialog.PromptUnclosable("DIALOG_RESTART_REQUIRED".Get());
                    promise.Reject();
                    return;
                }

                if (IntentPayload.OwnedCharacters.Count == 0)
                {
                    Dialog.PromptGoBack("DIALOG_OFFLINE_FEATURE_NOT_AVAILABLE".Get());
                    promise.Reject();
                    return;
                }

                promise.Resolve(IntentPayload);
            }
            catch (Exception e)
            {
                Debug.LogError(e);
                SpinnerOverlay.Hide();
                Dialog.PromptGoBack("DIALOG_COULD_NOT_CONNECT_TO_SERVER".Get());
                promise.Reject();
            }
        })
        .CatchRequestError(error =>
        {
            SpinnerOverlay.Hide();
            promise.Reject();
            if (!error.IsNetworkError)
            {
                throw error;
            }

            Dialog.PromptGoBack("DIALOG_COULD_NOT_CONNECT_TO_SERVER".Get());
        });
    }
Example #5
0
    protected override async void LoadPayload(ScreenLoadPromise promise)
    {
        if (Context.Player.ShouldOneShot("Agree Copyright Policy"))
        {
            Context.Player.ClearOneShot("Agree Copyright Policy");
            if (!await TermsOverlay.Show("COPYRIGHT_POLICY".Get()))
            {
                promise.Reject();
                Context.ScreenManager.ChangeScreen(Context.ScreenManager.PopAndPeekHistory(), ScreenTransition.Out,
                                                   addTargetScreenToHistory: false);
                return;
            }
            Context.Player.ShouldOneShot("Agree Copyright Policy");
        }

        SpinnerOverlay.Show();

        var promises = new List <IPromise>();

        foreach (var section in IntentPayload.Layout.Sections)
        {
            switch (section)
            {
            case Layout.LevelSection levelSection:
                promises.Add(RestClient.GetArray <OnlineLevel>(new RequestHelper
                {
                    Uri         = levelSection.Query.BuildUri(levelSection.PreviewSize),
                    Headers     = Context.OnlinePlayer.GetRequestHeaders(),
                    EnableDebug = true
                }).Then(data =>
                {
                    levelSection.Levels = data.ToList();
                }));
                break;

            case Layout.CollectionSection collectionSection:
            {
                var collectionPromises = new List <RSG.IPromise <CollectionMeta> >();
                foreach (var collectionId in collectionSection.CollectionIds)
                {
                    collectionPromises.Add(RestClient.Get <CollectionMeta>(new RequestHelper {
                            Uri         = $"{Context.ApiUrl}/collections/{collectionId}",
                            Headers     = Context.OnlinePlayer.GetRequestHeaders(),
                            EnableDebug = true
                        }));
                }
                promises.Add(Promise <CollectionMeta> .All(collectionPromises).Then(data =>
                    {
                        collectionSection.Collections = data.ToList()
                                                        .Zip(collectionSection.CollectionIds, (meta, id) => meta.Also(it => it.id                = id))
                                                        .Zip(collectionSection.CollectionTitleKeys, (meta, title) => meta.Also(it => it.title    = title.Get()))
                                                        .Zip(collectionSection.CollectionSloganKeys, (meta, slogan) => meta.Also(it => it.slogan = slogan.Get()))
                                                        .ToList();
                    }));
                break;
            }
            }
        }

        Promise.All(promises)
        .Then(() =>
        {
            promise.Resolve(IntentPayload);
        })
        .Catch(error =>
        {
            Dialog.PromptGoBack("DIALOG_COULD_NOT_CONNECT_TO_SERVER".Get());
            Debug.LogError(error);
            promise.Reject();
        })
        .Finally(() => SpinnerOverlay.Hide());
    }