Example #1
0
    public IEnumerator LoadMap()
    {
        if (BeatSaberSongContainer.Instance == null)
        {
            yield break;
        }
        PersistentUI.Instance.LevelLoadSlider.gameObject.SetActive(true);
        PersistentUI.Instance.LevelLoadSliderLabel.text = "";
        yield return(new WaitUntil(() => atsc.gridStartPosition != -1)); //I need a way to find out when Start has been called.

        song = BeatSaberSongContainer.Instance.song;                     //Grab songe data
        diff = BeatSaberSongContainer.Instance.difficultyData;

        //Set up some local variables
        int  environmentID = 0;
        int  batchSize     = Settings.Instance.InitialLoadBatchSize;
        bool customPlat    = false;

        environmentID = SongInfoEditUI.GetEnvironmentIDFromString(song.environmentName); //Grab platform by name (Official or Custom)
        if (song.customData != null && song.customData["_customEnvironment"] != null && song.customData["_customEnvironment"].Value != "")
        {
            if (SongInfoEditUI.GetCustomPlatformsIndexFromString(song.customData["_customEnvironment"]) >= 0)
            {
                environmentID = SongInfoEditUI.GetCustomPlatformsIndexFromString(song.customData["_customEnvironment"]);
                customPlat    = true;
            }
        }

        //Instantiate platform, grab descriptor
        GameObject         platform    = (customPlat ? CustomPlatformPrefabs[environmentID] : PlatformPrefabs[environmentID]) ?? PlatformPrefabs[0];
        GameObject         instantiate = Instantiate(platform, new Vector3(0, -0.5f, -1.5f), Quaternion.identity);
        PlatformDescriptor descriptor  = instantiate.GetComponent <PlatformDescriptor>();

        BeatmapEventContainer.ModifyTypeMode = descriptor.SortMode; //Change sort mode

        //Update Colors
        Color leftNote = BeatSaberSong.DEFAULT_LEFTNOTE; //Have default note as base

        if (descriptor.RedColor != BeatSaberSong.DEFAULT_LEFTCOLOR)
        {
            leftNote = descriptor.RedColor;                                                         //Prioritize platforms
        }
        if (diff.colorLeft != BeatSaberSong.DEFAULT_LEFTNOTE)
        {
            leftNote = diff.colorLeft;                                                   //Then prioritize custom colors
        }
        Color rightNote = BeatSaberSong.DEFAULT_RIGHTNOTE;

        if (descriptor.BlueColor != BeatSaberSong.DEFAULT_RIGHTCOLOR)
        {
            rightNote = descriptor.BlueColor;
        }
        if (diff.colorRight != BeatSaberSong.DEFAULT_RIGHTNOTE)
        {
            rightNote = diff.colorRight;
        }

        notesContainer.UpdateColor(leftNote, rightNote);
        obstaclesContainer.UpdateColor(diff.obstacleColor);
        if (diff.colorLeft != BeatSaberSong.DEFAULT_LEFTNOTE)
        {
            descriptor.RedColor = diff.colorLeft;
        }
        if (diff.colorRight != BeatSaberSong.DEFAULT_RIGHTNOTE)
        {
            descriptor.BlueColor = diff.colorRight;
        }
        if (diff.envColorLeft != BeatSaberSong.DEFAULT_LEFTCOLOR)
        {
            descriptor.RedColor = diff.envColorLeft;
        }
        if (diff.envColorRight != BeatSaberSong.DEFAULT_RIGHTCOLOR)
        {
            descriptor.BlueColor = diff.envColorRight;
        }

        PlatformLoadedEvent.Invoke(descriptor);    //Trigger event for classes that use the platform

        map = BeatSaberSongContainer.Instance.map; //Grab map info, do some stuff
        int noteLaneSize  = 2;                     //Half of it, anyways
        int noteLayerSize = 3;

        Queue <BeatmapObject> queuedData = new Queue <BeatmapObject>( //Take all of our object data and combine them for batch loading.
            map._notes.Concat <BeatmapObject>(map._obstacles).Concat(map._events).Concat(map._BPMChanges).Concat(map._customEvents));

        totalObjectsToLoad = queuedData.Count;
        if (map != null)
        {
            while (queuedData.Count > 0)
            { //Batch loading is loading a certain amount of objects (Batch Size) every frame, so at least ChroMapper remains active.
                for (int i = 0; i < batchSize; i++)
                {
                    if (queuedData.Count == 0)
                    {
                        break;
                    }
                    BeatmapObject data = queuedData.Dequeue(); //Dequeue and load them into ChroMapper.
                    if (data is BeatmapNote noteData)
                    {
                        BeatmapNoteContainer beatmapNote = notesContainer.SpawnObject(noteData, out _) as BeatmapNoteContainer;
                        if (noteData._lineIndex >= 1000 || noteData._lineIndex <= -1000 || noteData._lineLayer >= 1000 || noteData._lineLayer <= -1000)
                        {
                            continue;
                        }
                        if (2 - noteData._lineIndex > noteLaneSize)
                        {
                            noteLaneSize = 2 - noteData._lineIndex;
                        }
                        if (noteData._lineIndex - 1 > noteLaneSize)
                        {
                            noteLaneSize = noteData._lineIndex - 1;
                        }
                        if (noteData._lineLayer + 1 > noteLayerSize)
                        {
                            noteLayerSize = noteData._lineLayer + 1;
                        }
                    }
                    else if (data is BeatmapObstacle obstacleData)
                    {
                        BeatmapObstacleContainer beatmapObstacle = obstaclesContainer.SpawnObject(obstacleData, out _) as BeatmapObstacleContainer;
                        if (obstacleData._lineIndex >= 1000 || obstacleData._lineIndex <= -1000)
                        {
                            continue;
                        }
                        if (2 - obstacleData._lineIndex > noteLaneSize)
                        {
                            noteLaneSize = 2 - obstacleData._lineIndex;
                        }
                        if (obstacleData._lineIndex - 1 > noteLaneSize)
                        {
                            noteLaneSize = obstacleData._lineIndex - 1;
                        }
                    }
                    else if (data is MapEvent eventData)
                    {
                        eventsContainer.SpawnObject(eventData, out _);
                    }
                    else if (data is BeatmapBPMChange bpmData)
                    {
                        bpmContainer.SpawnObject(bpmData, out _);
                    }
                    else if (data is BeatmapCustomEvent customData)
                    {
                        customEventsContainer.SpawnObject(customData, out _);
                    }
                }
                UpdateSlider(batchSize);
                yield return(new WaitForEndOfFrame());
            }
            notesContainer.SortObjects(); //Sort these boyes.
            obstaclesContainer.SortObjects();
            eventsContainer.SortObjects();
            bpmContainer.SortObjects();
            customEventsContainer.SortObjects();
            noteGrid.localScale = new Vector3((float)(noteLaneSize * 2) / 10 + 0.01f, 1, 1); //Set note lanes appropriately
        }
        PersistentUI.Instance.LevelLoadSlider.gameObject.SetActive(false);                   //Disable progress bar
        LevelLoadedEvent?.Invoke();
    }
Example #2
0
    public IEnumerator LoadMap()
    {
        if (BeatSaberSongContainer.Instance == null)
        {
            yield break;
        }
        PersistentUI.Instance.LevelLoadSlider.gameObject.SetActive(true);
        yield return(new WaitUntil(() => atsc.gridStartPosition != -1)); //I need a way to find out when Start has been called.

        song = BeatSaberSongContainer.Instance.song;
        float offset        = 0;
        int   environmentID = 0;
        int   batchSize     = Settings.Instance.InitialLoadBatchSize;
        bool  customPlat    = false;

        environmentID = SongInfoEditUI.GetEnvironmentIDFromString(song.environmentName);
        if (song.customData != null && song.customData["_customEnvironment"] != null && song.customData["_customEnvironment"].Value != "")
        {
            environmentID = SongInfoEditUI.GetCustomPlatformsIndexFromString(song.customData["_customEnvironment"]);
            customPlat    = true;
        }
        GameObject         platform    = (customPlat ? CustomPlatformPrefabs[environmentID] : PlatformPrefabs[environmentID]) ?? PlatformPrefabs[0];
        GameObject         instantiate = Instantiate(platform, new Vector3(0, -0.5f, -1.5f), Quaternion.identity);
        PlatformDescriptor descriptor  = instantiate.GetComponent <PlatformDescriptor>();

        BeatmapEventContainer.ModifyTypeMode = descriptor.SortMode;
        PlatformLoadedEvent.Invoke(descriptor);
        descriptor.RedColor  = BeatSaberSongContainer.Instance.difficultyData.colorLeft;
        descriptor.BlueColor = BeatSaberSongContainer.Instance.difficultyData.colorRight;
        map    = BeatSaberSongContainer.Instance.map;
        offset = (song.beatsPerMinute / 60) * (BeatSaberSongContainer.Instance.song.songTimeOffset / 1000);
        int noteLaneSize  = 2;                                        //Half of it, anyways
        int noteLayerSize = 3;
        Queue <BeatmapObject> queuedData = new Queue <BeatmapObject>( //Take all of our object data and combine them for batch loading.
            map._notes.Concat <BeatmapObject>(map._obstacles).Concat(map._events).Concat(map._BPMChanges));

        totalObjectsToLoad = queuedData.Count;
        if (map != null)
        {
            while (queuedData.Count > 0)
            {
                for (int i = 0; i < batchSize; i++)
                {
                    if (queuedData.Count == 0)
                    {
                        break;
                    }
                    BeatmapObject data = queuedData.Dequeue();
                    if (data is BeatmapNote noteData)
                    {
                        BeatmapNoteContainer beatmapNote = notesContainer.SpawnObject(noteData) as BeatmapNoteContainer;
                        if (noteData._lineIndex >= 1000 || noteData._lineIndex <= -1000 || noteData._lineLayer >= 1000 || noteData._lineLayer <= -1000)
                        {
                            continue;
                        }
                        if (2 - noteData._lineIndex > noteLaneSize)
                        {
                            noteLaneSize = 2 - noteData._lineIndex;
                        }
                        if (noteData._lineIndex - 1 > noteLaneSize)
                        {
                            noteLaneSize = noteData._lineIndex - 1;
                        }
                        if (noteData._lineLayer + 1 > noteLayerSize)
                        {
                            noteLayerSize = noteData._lineLayer + 1;
                        }
                    }
                    else if (data is BeatmapObstacle obstacleData)
                    {
                        BeatmapObstacleContainer beatmapObstacle = obstaclesContainer.SpawnObject(obstacleData) as BeatmapObstacleContainer;
                        if (obstacleData._lineIndex >= 1000 || obstacleData._lineIndex <= -1000)
                        {
                            continue;
                        }
                        if (2 - obstacleData._lineIndex > noteLaneSize)
                        {
                            noteLaneSize = 2 - obstacleData._lineIndex;
                        }
                        if (obstacleData._lineIndex - 1 > noteLaneSize)
                        {
                            noteLaneSize = obstacleData._lineIndex - 1;
                        }
                    }
                    else if (data is MapEvent eventData)
                    {
                        eventsContainer.SpawnObject(eventData);
                    }
                    else if (data is BeatmapBPMChange bpmData)
                    {
                        bpmContainer.SpawnObject(bpmData);
                    }
                }
                UpdateSlider(batchSize);
                yield return(new WaitForEndOfFrame());
            }
            notesContainer.SortObjects();
            obstaclesContainer.SortObjects();
            eventsContainer.SortObjects();
            bpmContainer.SortObjects();
            noteGrid.localScale = new Vector3((float)(noteLaneSize * 2) / 10 + 0.01f, 1, 1);
        }
        PersistentUI.Instance.LevelLoadSlider.gameObject.SetActive(false);
    }
Example #3
0
    public IEnumerator LoadMap()
    {
        if (BeatSaberSongContainer.Instance == null)
        {
            yield break;
        }
        PersistentUI.Instance.LevelLoadSliderLabel.text = "";
        yield return(new WaitUntil(() => atsc.gridStartPosition != -1)); //I need a way to find out when Start has been called.

        song = BeatSaberSongContainer.Instance.song;                     //Grab songe data
        diff = BeatSaberSongContainer.Instance.difficultyData;

        //Set up some local variables
        int  environmentID = 0;
        bool customPlat    = false;
        bool directional   = false;

        environmentID = SongInfoEditUI.GetEnvironmentIDFromString(song.environmentName); //Grab platform by name (Official or Custom)
        if (song.customData != null && ((song.customData["_customEnvironment"] != null && song.customData["_customEnvironment"].Value != "")))
        {
            if (CustomPlatformsLoader.Instance.GetAllEnvironmentIds().IndexOf(song.customData["_customEnvironment"] ?? "") >= 0)
            {
                customPlat = true;
            }
        }
        if (rotationController.IsActive && diff.parentBeatmapSet.beatmapCharacteristicName != "Lawless")
        {
            environmentID = SongInfoEditUI.GetDirectionalEnvironmentIDFromString(song.allDirectionsEnvironmentName);
            customPlat    = false;
            directional   = true;
        }

        //Instantiate platform, grab descriptor
        GameObject platform = (customPlat ? CustomPlatformsLoader.Instance.LoadPlatform(song.customData["_customEnvironment"], (PlatformPrefabs[environmentID]) ?? PlatformPrefabs[0], null) : PlatformPrefabs[environmentID]) ?? PlatformPrefabs[0];

        if (directional)
        {
            platform = DirectionalPlatformPrefabs[environmentID];
        }
        GameObject instantiate = null;

        if (customPlat)
        {
            instantiate = platform;
        }
        else
        {
            Debug.Log("Instanciate nonCustomPlat");
            instantiate = Instantiate(platform, PlatformOffset, Quaternion.identity) as GameObject;
        }
        PlatformDescriptor descriptor = instantiate.GetComponent <PlatformDescriptor>();

        BeatmapEventContainer.ModifyTypeMode = descriptor.SortMode; //Change sort mode

        //Update Colors
        Color leftNote = BeatSaberSong.DEFAULT_LEFTNOTE; //Have default note as base

        if (descriptor.RedColor != BeatSaberSong.DEFAULT_LEFTCOLOR)
        {
            leftNote = descriptor.RedColor;                                                         //Prioritize platforms
        }
        if (diff.colorLeft != BeatSaberSong.DEFAULT_LEFTNOTE)
        {
            leftNote = diff.colorLeft;                                                   //Then prioritize custom colors
        }
        Color rightNote = BeatSaberSong.DEFAULT_RIGHTNOTE;

        if (descriptor.BlueColor != BeatSaberSong.DEFAULT_RIGHTCOLOR)
        {
            rightNote = descriptor.BlueColor;
        }
        if (diff.colorRight != BeatSaberSong.DEFAULT_RIGHTNOTE)
        {
            rightNote = diff.colorRight;
        }

        notesContainer.UpdateColor(leftNote, rightNote);
        obstaclesContainer.UpdateColor(diff.obstacleColor);
        if (diff.colorLeft != BeatSaberSong.DEFAULT_LEFTNOTE)
        {
            descriptor.RedColor = diff.colorLeft;
        }
        if (diff.colorRight != BeatSaberSong.DEFAULT_RIGHTNOTE)
        {
            descriptor.BlueColor = diff.colorRight;
        }
        if (diff.envColorLeft != BeatSaberSong.DEFAULT_LEFTCOLOR)
        {
            descriptor.RedColor = diff.envColorLeft;
        }
        if (diff.envColorRight != BeatSaberSong.DEFAULT_RIGHTCOLOR)
        {
            descriptor.BlueColor = diff.envColorRight;
        }

        PlatformLoadedEvent.Invoke(descriptor); //Trigger event for classes that use the platform

        loader.UpdateMapData(BeatSaberSongContainer.Instance.map);
        yield return(StartCoroutine(loader.HardRefresh()));

        LevelLoadedEvent?.Invoke();
    }