Пример #1
0
    static void GenerateSongIni(string path, Song song, float songLengthSeconds, bool isChPackage = false)
    {
        Metadata  metaData = song.metaData;
        INIParser parser   = new INIParser();

        try
        {
            parser.Open(Path.Combine(path, "song.ini"));

            // Clone explicit properties
            parser.WriteValue(song.iniProperties);

            SongIniFunctions.AddDefaultIniTags(song, parser, songLengthSeconds);

            if (isChPackage)
            {
                // Write defaults for any missing CH tags
                SongIniFunctions.AddCloneHeroIniTags(song, parser, songLengthSeconds);
            }
        }
        catch (System.Exception e)
        {
            Debug.LogError("Error encountered when trying to generate song.ini. " + e.Message);
        }
        finally
        {
            parser.Close();
        }
    }
 public void PopulateIniFromGeneralSettings()
 {
     RefreshIniDisplay();
     SongIniFunctions.PopulateIniWithSongMetadata(editor.currentSong, editor.currentSong.iniProperties, editor.currentSongLength);
     UpdateIniTextFromSongProperties();
     ChartEditor.isDirty = true;
 }
    public void AddCloneHeroIniTags()
    {
        RefreshIniDisplay();

        var song      = editor.currentSong;
        var iniParser = song.iniProperties;

        SongIniFunctions.AddCloneHeroIniTags(song, iniParser, editor.currentSongLength);
        UpdateIniTextFromSongProperties();
        ChartEditor.isDirty = true;
    }
Пример #4
0
    public IEnumerator _Load(string currentFileName, bool recordLastLoaded = true)
    {
        LoadingTasksManager tasksManager = services.loadingTasksManager;

        bool error  = false;
        Song backup = currentSong;

#if TIMING_DEBUG
        float totalLoadTime = Time.realtimeSinceStartup;
#endif
        bool mid = false;

        Song newSong = null;
        MidReader.CallbackState midiCallbackState = MidReader.CallbackState.None;

        List <LoadingTask> tasks = new List <LoadingTask>()
        {
            new LoadingTask("Loading file", () =>
            {
                // Wait for saving to complete just in case
                while (isSaving)
                {
                }

                if (errorManager.HasErrorToDisplay())
                {
                    error = true;
                    return;
                }

                mid = System.IO.Path.GetExtension(currentFileName) == ".mid";

                try
                {
                    if (mid)
                    {
                        newSong = MidReader.ReadMidi(currentFileName, ref midiCallbackState);
                    }
                    else
                    {
                        newSong = ChartReader.ReadChart(currentFileName);
                    }
                }
                catch (Exception e)
                {
                    currentSong = backup;

                    if (mid)
                    {
                        errorManager.QueueErrorMessage(Logger.LogException(e, "Failed to open mid file"));
                    }
                    else
                    {
                        errorManager.QueueErrorMessage(Logger.LogException(e, "Failed to open chart file"));
                    }

                    error = true;
                }

                try
                {
                    string directory = System.IO.Path.GetDirectoryName(currentFileName);
                    string iniPath   = System.IO.Path.Combine(directory, "song.ini");
                    if (System.IO.File.Exists(iniPath))
                    {
                        try
                        {
                            newSong.iniProperties.Open(iniPath);
                            newSong.iniProperties = SongIniFunctions.FixupSongIniWhitespace(newSong.iniProperties);
                        }
                        catch (Exception e)
                        {
                            errorManager.QueueErrorMessage(Logger.LogException(e, "Failed to parse song.ini"));
                        }
                        finally
                        {
                            newSong.iniProperties.Close();
                        }
                    }
                }
                catch (Exception e)
                {
                    // TODO
                }
            }),

            new LoadingTask("Loading audio", () =>
            {
                if (error)
                {
                    return;
                }

                // Free the previous audio clips
                currentSongAudio.FreeAudioStreams();
                currentSongAudio.LoadAllAudioClips(newSong);
            }),
        };

        tasksManager.KickTasks(tasks);

        while (tasksManager.isRunningTask)
        {
            while (midiCallbackState == MidReader.CallbackState.WaitingForExternalInformation)
            {
                // Halt main thread until message box is complete
            }
            yield return(null);
        }

        // Tasks have finished
        if (error)
        {
            yield break;    // Immediate exit
        }
        isDirty = false;

        if (mid)
        {
            currentFileName = string.Empty;
            isDirty         = true;
            Debug.Log("Loaded mid file");
        }

        if (recordLastLoaded && currentFileName != string.Empty && !mid)
        {
            lastLoadedFile = System.IO.Path.GetFullPath(currentFileName);
        }
        else
        {
            lastLoadedFile = string.Empty;
        }
        currentSong = newSong;

        LoadSong(currentSong);

#if TIMING_DEBUG
        Debug.Log("Total load time: " + (Time.realtimeSinceStartup - totalLoadTime));
#endif
    }
 void UpdateIniTextFromSongProperties()
 {
     customIniSettings.text = SongIniFunctions.IniTextFromSongProperties(editor.currentSong.iniProperties);
 }
    public void UpdateIni()
    {
        Song song = editor.currentSong;

        song.iniProperties = SongIniFunctions.SongIniFromString(customIniSettings.text);
    }