Esempio n. 1
0
    public void UpdateEventName(string name)
    {
        // Make sure the user isn't editing to create 2 of the same events
        if (currentEvent != null)
        {
            var charsToRemove = new string[] { "\"" };
            foreach (var c in charsToRemove)
            {
                name = name.Replace(c, string.Empty);
            }

            string prevName = currentEvent.title;
            if (SongObjectHelper.FindObjectPosition(new MoonscraperChartEditor.Song.Event(name, currentEvent.tick), editor.currentSong.events) == SongObjectHelper.NOTFOUND)
            {
                bool tentativeRecord, lockedRecord;
                ShouldRecordInputField(name, currentEvent.title, out tentativeRecord, out lockedRecord);

                if (!lockedRecord)
                {
                    editor.commandStack.Pop();
                }

                if (tentativeRecord || lockedRecord)
                {
                    MoonscraperChartEditor.Song.Event newEvent = new MoonscraperChartEditor.Song.Event(name, currentEvent.tick);
                    editor.commandStack.Push(new SongEditModify <MoonscraperChartEditor.Song.Event>(currentEvent, newEvent));
                    editor.selectedObjectsManager.SelectSongObject(newEvent, editor.currentSong.events);
                }
            }
        }
        else if (currentChartEvent != null)
        {
            string prevName = currentChartEvent.eventName;
            if (SongObjectHelper.FindObjectPosition(new ChartEvent(currentChartEvent.tick, name), editor.currentChart.events) == SongObjectHelper.NOTFOUND)
            {
                bool tentativeRecord, lockedRecord;
                ShouldRecordInputField(name, currentChartEvent.eventName, out tentativeRecord, out lockedRecord);

                if (!lockedRecord)
                {
                    editor.commandStack.Pop();
                }

                if (tentativeRecord || lockedRecord)
                {
                    ChartEvent newChartEvent = new ChartEvent(currentChartEvent.tick, name);
                    editor.commandStack.Push(new SongEditModify <ChartEvent>(currentChartEvent, newChartEvent));
                    editor.selectedObjectsManager.SelectSongObject(newChartEvent, editor.currentChart.events);
                }
            }
        }
    }
    static string CheckForErrorsMoonscraper(Song song, ValidationParameters validationParams, ref bool hasErrors)
    {
        bool          hasErrorsLocal = false;
        StringBuilder sb             = new StringBuilder();

        sb.AppendLine("Moonscraper validation report: ");

        // Check if any objects have exceeded the max length
        {
            uint tick = song.TimeToTick(validationParams.songLength, song.resolution);

            // Song objects
            {
                // Synctrack
                {
                    int index, length;
                    SongObjectHelper.GetRange(song.syncTrack, tick, uint.MaxValue, out index, out length);

                    for (int i = index; i < length; ++i)
                    {
                        hasErrorsLocal |= true;

                        SyncTrack st = song.syncTrack[i];

                        sb.AppendFormat("\tFound synctrack object beyond the length of the song-\n");
                        sb.AppendFormat("\t\tType = {0}, position = {1}\n", st.GetType(), st.tick);
                    }
                }

                // Events
                {
                    int index, length;
                    SongObjectHelper.GetRange(song.eventsAndSections, tick, uint.MaxValue, out index, out length);

                    for (int i = index; i < length; ++i)
                    {
                        hasErrorsLocal |= true;

                        MoonscraperChartEditor.Song.Event eventObject = song.eventsAndSections[i];

                        sb.AppendFormat("\tFound event object beyond the length of the song-\n");
                        sb.AppendFormat("\t\tType = {0}, position = {1}\n", eventObject.GetType(), eventObject.tick);
                    }
                }
            }

            // Chart objects
            foreach (Song.Instrument instrument in EnumX <Song.Instrument> .Values)
            {
                if (instrument == Song.Instrument.Unrecognised)
                {
                    continue;
                }

                foreach (Song.Difficulty difficulty in EnumX <Song.Difficulty> .Values)
                {
                    Chart chart = song.GetChart(instrument, difficulty);

                    int index, length;
                    SongObjectHelper.GetRange(chart.chartObjects, tick, uint.MaxValue, out index, out length);

                    for (int i = index; i < length; ++i)
                    {
                        hasErrorsLocal |= true;

                        ChartObject co = chart.chartObjects[i];

                        sb.AppendFormat("\tFound chart object beyond the length of the song-\n");
                        sb.AppendFormat("\t\tType = {0}, position = {1}\n", co.GetType(), co.tick);
                    }
                }
            }
        }

        if (!hasErrorsLocal)
        {
            sb.AppendLine("\tNo errors detected");
        }

        hasErrors |= hasErrorsLocal;

        return(sb.ToString());
    }