public void SwitchRankedMode()
 {
     if (isLoggingIn)
     {
         Popup.Make(this, "Now signing in, please wait...");
         return;
     }
     if (LocalProfile.Exists())
     {
         var ranked = PlayerPrefsExt.GetBool(PreferenceKeys.RankedMode(), false);
         ranked = !ranked;
         PlayerPrefsExt.SetBool(PreferenceKeys.RankedMode(), ranked);
         rankStatusText.text = ranked ? "On" : "Off";
         UpdateBestText();
         if (ranked && !PlayerPrefsExt.GetBool("dont_show_what_is_ranked_mode_again", false))
         {
             UIManager.ShowUiElement("WhatIsRankedModeBackground", "MusicSelection");
             UIManager.ShowUiElement("WhatIsRankedModeRoot", "MusicSelection");
         }
     }
     else
     {
         UIManager.ShowUiElement("LoginRoot", "MusicSelection");
         UIManager.ShowUiElement("LoginBackground", "MusicSelection");
     }
 }
Ejemplo n.º 2
0
 public void PostRankingData()
 {
     if (!CytoidApplication.LastPlayResult.Ranked || !LocalProfile.Exists())
     {
         Popup.Make(this, "ERROR: You haven't signed in.");
         return;
     }
     uploadButton.interactable = false;
     StartCoroutine(PostRankingDataCoroutine());
 }
Ejemplo n.º 3
0
    public LocalProcessor(LocalSystem system, GameObject instance) : base(system, instance)
    {
        this.profile              = new LocalProfile(GameObject);
        this.parentSystem         = (WorldSystem)System.Parent;
        this.shooter              = this.parentSystem.ShooterSystem.DeployInstance();
        this.shooter.Profile.IsAI = false;
        this.shooter.Profile.Rigidbody.position = new Vector3(50f, 0.5f, 50f);

        SubProcessors.Add(new LocalCameraProcessor(this.profile.CameraProfile, this.shooter));

        this.shooter.Dead += OnShooterDead;
    }
    public void Logout()
    {
        CancelLogin();
        PlayerPrefs.DeleteKey(PreferenceKeys.LastUsername());
        PlayerPrefs.DeleteKey(PreferenceKeys.LastPassword());
        CloseProfileWindows();
        avatarImage.overrideSprite = null;
        LocalProfile.reset();
        Popup.Make(this, "Signed out.");

        PlayerPrefsExt.SetBool(PreferenceKeys.RankedMode(), false);
        rankStatusText.text = "Off";
    }
Ejemplo n.º 5
0
    public static LocalProfile Init(string username, string password, string avatarUrl)
    {
        var profile = new LocalProfile
        {
            username  = username,
            password  = password,
            avatarUrl = avatarUrl
        };

        profile.Save();
        Instance = profile;
        return(profile);
    }
 public void OnProfilePressed()
 {
     if (isLoggingIn)
     {
         Popup.Make(this, "Now signing in, please wait...");
         return;
     }
     if (LocalProfile.Exists())
     {
         UIManager.ShowUiElement("ProfileRoot", "MusicSelection");
         UIManager.ShowUiElement("ProfileBackground", "MusicSelection");
     }
     else
     {
         UIManager.ShowUiElement("LoginRoot", "MusicSelection");
         UIManager.ShowUiElement("LoginBackground", "MusicSelection");
     }
 }
    public IEnumerator LoadAvatarCoroutine()
    {
        if (LocalProfile.Exists() && LocalProfile.Instance.avatarTexture != null)
        {
            // Update avatar from memory
            var texture = LocalProfile.Instance.avatarTexture;

            var rect   = new Rect(0, 0, texture.width, texture.height);
            var sprite = Sprite.Create(texture, rect, new Vector2(0.5f, 0.5f), 100);

            avatarImage.overrideSprite = sprite;

            yield return(null);
        }
        using (var www = new WWW(LocalProfile.Instance.avatarUrl))
        {
            yield return(www);

            if (!string.IsNullOrEmpty(www.error))
            {
                Log.e(www.error);
                Popup.Make(this, "Could not load avatar.");
            }
            Debug.Log("Downloaded avatar");

            var texture = www.texture;

            LocalProfile.Instance.avatarTexture = texture;

            var rect   = new Rect(0, 0, texture.width, texture.height);
            var sprite = Sprite.Create(texture, rect, new Vector2(0.5f, 0.5f), 100);

            avatarImage.overrideSprite = sprite;
        }

        /*if (!string.IsNullOrEmpty(www.error))
         * {
         *  Log.e(www.error);
         *  Popup.Make(this, "Could not load avatar.");
         *  yield return null;
         * }*/
    }
    public IEnumerator LoginCoroutine()
    {
        if (!PlayerPrefs.HasKey(PreferenceKeys.LastUsername()) || !PlayerPrefs.HasKey(PreferenceKeys.LastPassword()))
        {
            isLoggingIn = false;
            yield break;
        }

        // If logged in previously
        if (LocalProfile.Exists())
        {
            // Do nothing
        }
        else
        {
            Debug.Log("Logging in");
            var username = PlayerPrefs.GetString(PreferenceKeys.LastUsername());
            var password = PlayerPrefs.GetString(PreferenceKeys.LastPassword());

            var request = new UnityWebRequest(CytoidApplication.host + "/auth", "POST")
            {
                timeout = 10
            };
            var bodyRaw =
                Encoding.UTF8.GetBytes("{\"user\": \"" + username + "\", \"password\": \"" + password + "\"}");
            request.uploadHandler   = new UploadHandlerRaw(bodyRaw);
            request.downloadHandler = new DownloadHandlerBuffer();
            request.SetRequestHeader("Content-Type", "application/json");

            yield return(request.Send());

            if (request.isNetworkError || request.isHttpError)
            {
                Log.e(request.responseCode.ToString());
                Log.e(request.error);
                Popup.Make(this, "Could not sign in.");
                CloseLoginWindows();
                isLoggingIn = false;
                yield break;
            }

            var body = request.downloadHandler.text;

            AuthenticationResult authenticationResult;
            try
            {
                authenticationResult = JsonConvert.DeserializeObject <AuthenticationResult>(body);
            }
            catch (Exception e)
            {
                Log.e(e.Message);
                Popup.Make(this, "Could not sign in.");
                CloseLoginWindows();
                isLoggingIn = false;
                yield break;
            }

            request.Dispose();

            if (authenticationResult.status != 0)
            {
                Popup.Make(this, authenticationResult.message);

                if (authenticationResult.status == 1)
                {
                    PlayerPrefs.DeleteKey(PreferenceKeys.LastUsername());
                    PlayerPrefs.DeleteKey(PreferenceKeys.LastPassword());
                    usernameInput.text = "";
                    passwordInput.text = "";
                }
                else if (authenticationResult.status == 2)
                {
                    PlayerPrefs.DeleteKey(PreferenceKeys.LastPassword());
                    passwordInput.text = "";
                }

                CloseLoginWindows();
                isLoggingIn = false;
                yield break;
            }

            Popup.Make(this, "Signed in.");

            var profile = LocalProfile.Init(username, password, authenticationResult.avatarUrl);
            profile.localVersion++;
            profile.Save();
        }

        CloseLoginWindows();
        isLoggingIn = false;

        rankStatusText.text = PlayerPrefsExt.GetBool(PreferenceKeys.RankedMode()) ? "On" : "Off";

        UpdateProfileUi();
    }
Ejemplo n.º 9
0
    public IEnumerator PostRankingDataCoroutine()
    {
        if (IsUploading)
        {
            Popup.Make(this, "Already uploading.");
        }
        IsUploading = true;

        Debug.Log("Posting ranking data");

        Popup.Make(this, "Uploading play data...");

        yield return(new WaitForSeconds(1));

        var request = new UnityWebRequest(CytoidApplication.host + "/rank/post", "POST")
        {
            timeout = 10
        };

        var bodyRaw = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(CytoidApplication.CurrentRankedPlayData));

        print("Body: " + JsonConvert.SerializeObject(CytoidApplication.CurrentRankedPlayData));
        request.uploadHandler   = new UploadHandlerRaw(bodyRaw);
        request.downloadHandler = new DownloadHandlerBuffer();
        request.SetRequestHeader("Content-Type", "application/json");

        yield return(request.Send());

        var response = request.responseCode;

        if (response != 200 || request.isNetworkError || request.isHttpError)
        {
            switch (response)
            {
            case 400:
                Popup.Make(this, "ERROR: " + "Invalid play data.");
                break;

            case 401:
                Popup.Make(this, "ERROR: " + "You haven't signed in.");
                LocalProfile.reset();
                break;

            case 403:
                Popup.Make(this, "ERROR: " + request.downloadHandler.text);
                break;

            default:
                Popup.Make(this, "ERROR: " + request.error + ".");
                break;
            }

            CloseUploadWindow();
            IsUploading = false;
            request.Dispose();
            uploadButton.interactable = true;
            yield break;
        }

        Popup.Make(this, "Uploaded play data.");

        CloseUploadWindow();
        IsUploading = false;
        request.Dispose();
    }
Ejemplo n.º 10
0
    private IEnumerator Start()
    {
        IsRanked = PlayerPrefsExt.GetBool(PreferenceKeys.RankedMode());
        if (!LocalProfile.Exists())
        {
            IsRanked = false;
        }

        if (!IsRanked)
        {
            levelInfoIndicator.transform.SetLocalX(rankedIndicator.transform.localPosition.x);
            rankedIndicator.SetActive(false);
        }

        if (PlayerPrefs.GetInt("autoplay") == 1 && !IsRanked)
        {
            autoPlay = true;
        }
        if (PlayerPrefsExt.GetBool("larger_hitboxes"))
        {
            hitboxMultiplier = 1.33f;
        }
        showEarlyLateIndicator = PlayerPrefsExt.GetBool("early_late_indicator");

        CytoidApplication.SetAutoRotation(false);

        SetAllowPause(false);

        OnScreenChainNotes          = new List <NoteView>();
        OnScreenHoldNotes           = new List <NoteView>();
        OnScreenRegularAndHoldNotes = new List <NoteView>();

#if UNITY_EDITOR
        autoPlay = true;
        if (!string.IsNullOrEmpty(editorLevelOverride))
        {
            CytoidApplication.CurrentLevel = CytoidApplication.Levels.Find(it =>
                                                                           string.Equals(it.title, editorLevelOverride, StringComparison.OrdinalIgnoreCase));
            CytoidApplication.CurrentChartType = editorChartTypeOverride;
        }
        // Still null? Fallback
        if (CytoidApplication.CurrentLevel == null)
        {
            CytoidApplication.CurrentLevel = CytoidApplication.Levels.Find(it =>
                                                                           string.Equals(it.title, editorLevelFallback, StringComparison.OrdinalIgnoreCase));
            CytoidApplication.CurrentChartType = editorChartTypeFallback;
        }
        if (Math.Abs(editorStartAtOverride - startAt) > 0.00001f)
        {
            startAt = editorStartAtOverride;
        }
#endif

        var level = CytoidApplication.CurrentLevel;

        if (!level.ChartsLoaded)
        {
            level.LoadCharts();
        }

        ThemeController.Instance.Init(level);
        DisplayDifficultyView.Instance.SetDifficulty(CytoidApplication.CurrentChartType,
                                                     level.GetDifficulty(CytoidApplication.CurrentChartType));
        titleText.text = level.title;

        isInversed = PlayerPrefsExt.GetBool("inverse");

        // Override options?
        if (ZPlayerPrefs.GetBool(PreferenceKeys.WillOverrideOptions(level)))
        {
            isInversed = ZPlayerPrefs.GetBool(PreferenceKeys.WillInverse(level));
        }

        // Chart and background are already loaded

        if (CytoidApplication.CurrentChartType == null)
        {
            CytoidApplication.CurrentChartType = level.charts[0].type;
        }
        Chart    = level.charts.Find(it => it.type == CytoidApplication.CurrentChartType).chart;
        PlayData = new PlayData(Chart, IsRanked);
        CytoidApplication.CurrentPlayData = PlayData;

        if (IsRanked)
        {
            CytoidApplication.CurrentRankedPlayData = RankedPlayData;
        }


        // Load audio clip
        if (level.is_internal || Application.platform != RuntimePlatform.Android)
        {
            var www = new WWW((level.is_internal && Application.platform == RuntimePlatform.Android ? "" : "file://") +
                              level.basePath + level.GetMusicPath(CytoidApplication.CurrentChartType));
            yield return(www);

            clip             = CytoidApplication.ReadAudioClipFromWWW(www);
            audioSource.clip = clip;
        }

        // Don't continue until faded in
        backgroundOverlayMask.willFadeIn = true;
        while (backgroundOverlayMask.IsFading)
        {
            yield return(null);
        }
        yield return(null);

        // Init notes
        NoteViews = new OrderedDictionary();
        foreach (var id in Chart.chronologicalIds)
        {
            var note = Chart.notes[id];
            // if (note.time <= startAt) continue;
            var prefab = singleNotePrefab;
            switch (note.type)
            {
            case NoteType.Hold:
                prefab = holdNotePrefab;
                break;

            case NoteType.Chain:
                prefab = chainNotePrefab;
                break;
            }
            var noteView = Instantiate(prefab, transform).GetComponent <NoteView>();
            noteView.Init(Chart, note);
            NoteViews.Add(id, noteView);
        }

        foreach (NoteView note in NoteViews.Values)
        {
            note.OnAllNotesInitialized();
        }

        // Register handlers
        LeanTouch.OnFingerDown += OnFingerDown;
        LeanTouch.OnFingerSet  += OnFingerSet;
        LeanTouch.OnFingerUp   += OnFingerUp;

        // Release unused assets
        Resources.UnloadUnusedAssets();

        // Init scanner
        Instantiate(scannerPrefab, transform);


        if (level.is_internal || Application.platform != RuntimePlatform.Android)
        {
            audioSource.time = startAt;
            var userOffset = PlayerPrefs.GetFloat("user_offset", 0.2f);

            // Override options?
            if (ZPlayerPrefs.GetBool(PreferenceKeys.WillOverrideOptions(level)))
            {
                userOffset = ZPlayerPrefs.GetFloat(PreferenceKeys.NoteDelay(level));
            }

            const float delay = 1f;
            audioSource.PlayDelayed(delay);

            StartTime = Time.time + Chart.offset + userOffset + delay;
        }
        else
        {
            anaId = ANAMusic.load(level.basePath + level.GetMusicPath(CytoidApplication.CurrentChartType), true, true,
                                  id =>
            {
                StartCoroutine(OnAndroidPlayerLoaded());
            });
        }

        // Ranked
        if (!LocalProfile.Exists())
        {
            RankedPlayData.user     = "******";
            RankedPlayData.password = "";
        }
        else
        {
            RankedPlayData.user     = LocalProfile.Instance.username;
            RankedPlayData.password = LocalProfile.Instance.password;
        }
        RankedPlayData.start          = TimeExt.Millis();
        RankedPlayData.id             = level.id;
        RankedPlayData.type           = CytoidApplication.CurrentChartType;
        RankedPlayData.mods           = "";
        RankedPlayData.version        = level.version;
        RankedPlayData.chart_checksum = Chart.checksum;
        RankedPlayData.device.width   = Screen.width;
        RankedPlayData.device.height  = Screen.height;
        RankedPlayData.device.dpi     = (int)Screen.dpi;
        RankedPlayData.device.model   = SystemInfo.deviceModel;
        // Ranked

/*#if UNITY_EDITOR
 *      StartCoroutine(EndGame());
 #endif*/
    }