Example #1
0
    public static void ApplyAction(SongObject songObject)
    {
        ChartEditor editor = ChartEditor.Instance;
        Song        song   = editor.currentSong;
        Chart       chart  = editor.currentChart;

        songObject = songObject.Clone();    // Add a new version of the object

        switch (songObject.classID)
        {
        case (int)SongObject.ID.Note:
            Note note = songObject as Note;
            chart.Add(note);

            foreach (Note chordNote in note.chord)
            {
                if (chordNote.controller)
                {
                    chordNote.controller.SetDirty();
                }
            }

            Note next = note.nextSeperateNote;
            if (next != null)
            {
                foreach (Note chordNote in next.chord)
                {
                    if (chordNote.controller)
                    {
                        chordNote.controller.SetDirty();
                    }
                }
            }
            break;

        case (int)SongObject.ID.Starpower:
            Starpower sp = songObject as Starpower;
            chart.Add(sp, false);
            SongEditAdd.SetNotesDirty(sp, editor.currentChart.chartObjects);
            break;

        case (int)SongObject.ID.ChartEvent:
            chart.Add(songObject as ChartObject, false);
            break;

        case (int)SongObject.ID.Section:
        case (int)SongObject.ID.Event:
            song.Add(songObject as Event, false);
            break;

        case (int)SongObject.ID.BPM:
            song.Add(songObject as SyncTrack, false);
            ChartEditor.Instance.songObjectPoolManager.SetAllPoolsDirty();
            break;

        case (int)SongObject.ID.TimeSignature:
            song.Add(songObject as SyncTrack, false);
            break;
        }
    }
    public static ActionHistory.Action[] AddObjectToCurrentChart(Starpower starpower, ChartEditor editor, bool update = true, bool copy = true)
    {
        List <ActionHistory.Action> record = new List <ActionHistory.Action>();

        Starpower starpowerToAdd;

        if (copy)
        {
            starpowerToAdd = new Starpower(starpower);
        }
        else
        {
            starpowerToAdd = starpower;
        }

        record.AddRange(CapPrevAndNextPreInsert(starpowerToAdd, editor.currentChart));
        ActionHistory.Action overwriteRecord = OverwriteActionHistory(starpowerToAdd, editor.currentChart.starPower);
        if (overwriteRecord != null)
        {
            record.Add(overwriteRecord);
        }

        editor.currentChart.Add(starpowerToAdd, update);
        //editor.CreateStarpowerObject(starpowerToAdd);
        editor.currentSelectedObject = starpowerToAdd;

        SetNotesDirty(starpowerToAdd);

        return(record.ToArray());
    }
    protected override void SetSongObjectAndController()
    {
        starpower = new Starpower(0, 0);

        controller           = GetComponent <StarpowerController>();
        controller.starpower = starpower;
        spRen = GetComponent <Renderer>();
    }
    public override void OnSelectableMouseUp()
    {
        if (unmodifiedSP != null && unmodifiedSP.length != starpower.length)
        {
            editor.actionHistory.Insert(new ActionHistory.Modify(unmodifiedSP, starpower));
        }

        unmodifiedSP = null;
    }
    protected override void AddObject()
    {
        editor.commandStack.Push(new SongEditAdd(new Starpower(starpower)));

        int insertionIndex = SongObjectHelper.FindObjectPosition(starpower, editor.currentChart.starPower);

        Debug.Assert(insertionIndex != SongObjectHelper.NOTFOUND, "Song event failed to be inserted?");
        lastPlacedSP = editor.currentChart.starPower[insertionIndex];
    }
    protected override void SetSongObjectAndController()
    {
        starpower = new Starpower(0, 0);

        controller           = GetComponent <StarpowerController>();
        controller.starpower = starpower;
        spRen  = GetComponent <Renderer>();
        record = new List <ActionHistory.Action>();
    }
Example #7
0
    static void AddStarpower(Starpower sp, IList <BaseAction> subActions)
    {
        ChartEditor editor = ChartEditor.Instance;

        TryRecordOverwrite(sp, editor.currentChart.chartObjects, subActions);

        CapPrevAndNextPreInsert(sp, editor.currentChart, subActions);

        AddAndInvokeSubAction(new AddAction(sp), subActions);
    }
Example #8
0
    protected override void Update()
    {
        UpdateTogglesInteractable();
        UpdateTogglesDisplay();

        UpdateStringsInfo();
        Controls();

        prevSp = currentSp;
    }
    static byte[] GetUnrecognisedChartBytes(Chart chart, ExportOptions exportOptions)
    {
        List <SortableBytes> eventList = new List <SortableBytes>();
        del InsertionSort = (sortableByte) =>
        {
            int index = eventList.Count - 1;

            while (index >= 0 && sortableByte.tick < eventList[index].tick)
            {
                --index;
            }

            eventList.Insert(index + 1, sortableByte);
        };

        foreach (ChartObject chartObject in chart.chartObjects)
        {
            SortableBytes onEvent  = null;
            SortableBytes offEvent = null;

            Note note = chartObject as Note;
            if (note != null)
            {
                GetUnrecognisedChartNoteBytes(note, out onEvent, out offEvent);
            }

            Starpower sp = chartObject as Starpower;
            if (sp != null)     // Starpower cannot be split up between charts in a midi file
            {
                GetStarpowerBytes(sp, out onEvent, out offEvent);
            }

            ChartEvent chartEvent = chartObject as ChartEvent;
            if (chartEvent != null)     // Text events cannot be split up in the file
            {
                SortableBytes bytes = GetChartEventBytes(chartEvent);
                InsertionSort(bytes);
            }

            if (onEvent != null && offEvent != null)
            {
                InsertionSort(onEvent);

                if (offEvent.tick == onEvent.tick)
                {
                    ++offEvent.tick;
                }

                InsertionSort(offEvent);
            }
        }

        return(SortableBytesToTimedEventBytes(eventList.ToArray(), chart.song, exportOptions));
    }
    protected override void AddObject()
    {
        Starpower starpowerToAdd = new Starpower(starpower);

        record.AddRange(CapPrevAndNextPreInsert(starpowerToAdd, editor.currentChart));
        editor.currentChart.Add(starpowerToAdd);
        //editor.CreateStarpowerObject(starpowerToAdd);
        editor.currentSelectedObject = starpowerToAdd;

        lastPlacedSP = starpowerToAdd;

        SetNotesDirty(starpowerToAdd);
    }
Example #11
0
    public uint GetCappedLengthForPos(uint pos)
    {
        uint newLength = length;

        if (pos > tick)
        {
            newLength = pos - tick;
        }
        else
        {
            newLength = 0;
        }

        Starpower nextSp = null;

        if (song != null && chart != null)
        {
            int arrayPos = SongObjectHelper.FindClosestPosition(this, chart.starPower);
            if (arrayPos == SongObjectHelper.NOTFOUND)
            {
                return(newLength);
            }

            while (arrayPos < chart.starPower.Count - 1 && chart.starPower[arrayPos].tick <= tick)
            {
                ++arrayPos;
            }

            if (chart.starPower[arrayPos].tick > tick)
            {
                nextSp = chart.starPower[arrayPos];
            }

            if (nextSp != null)
            {
                // Cap sustain length
                if (nextSp.tick < tick)
                {
                    newLength = 0;
                }
                else if (pos > nextSp.tick)
                {
                    // Cap sustain
                    newLength = nextSp.tick - tick;
                }
            }
            // else it's the only starpower or it's the last starpower
        }

        return(newLength);
    }
Example #12
0
    public static void SetNotesDirty(Starpower sp, IList <ChartObject> notes)
    {
        int start, length;

        SongObjectHelper.GetRange(notes, sp.tick, sp.tick + sp.length, out start, out length);

        for (int i = start; i < start + length; ++i)
        {
            if (notes[i].classID == (int)SongObject.ID.Note && notes[i].controller)
            {
                notes[i].controller.SetDirty();
            }
        }
    }
Example #13
0
    public bool DragCheck()
    {
        if (editor.currentState == ChartEditor.State.Editor && Input.GetMouseButton(1))
        {
            if (unmodifiedSP == null)
            {
                unmodifiedSP = (Starpower)starpower.Clone();
            }

            TailDrag();
            return(true);
        }

        return(false);
    }
    static void SetNotesDirty(Starpower sp)
    {
        int start, length;
        var notes = sp.chart.notes;

        SongObjectHelper.GetRange(notes, sp.tick, sp.tick + sp.length, out start, out length);

        for (int i = start; i < start + length; ++i)
        {
            if (notes[i].controller)
            {
                notes[i].controller.SetDirty();
            }
        }
    }
    public bool dragCheck()
    {
        if (Globals.applicationMode == Globals.ApplicationMode.Editor && Input.GetMouseButton(1))
        {
            if (unmodifiedSP == null)
            {
                unmodifiedSP = (Starpower)starpower.Clone();
            }

            TailDrag();
            return(true);
        }

        return(false);
    }
Example #16
0
    static void TryRecordOverwrite(Starpower songObject, IList <ChartObject> searchObjects, IList <SongObject> overwrittenObjects)
    {
        if (overwrittenObjects == null)
        {
            return;
        }

        ChartEditor editor         = ChartEditor.Instance;
        int         overwriteIndex = SongObjectHelper.FindObjectPosition(songObject, searchObjects);

        if (overwriteIndex != SongObjectHelper.NOTFOUND)
        {
            overwrittenObjects.Add(searchObjects[overwriteIndex].Clone());
            SetNotesDirty(songObject, searchObjects);
        }
    }
    // Update is called once per frame
    protected override void Update()
    {
        starpower.chart = editor.currentChart;
        if (!GameSettings.keysModeEnabled)
        {
            spRen.enabled = lastPlacedSP == null;
        }

        base.Update();

        if ((Input.GetMouseButtonUp(0) && !GameSettings.keysModeEnabled) || (GameSettings.keysModeEnabled && Input.GetButtonUp("Add Object")))
        {
            // Reset
            lastPlacedSP = null;
        }
    }
Example #18
0
    static void TryRecordOverwrite(Starpower songObject, IList <ChartObject> searchObjects, IList <BaseAction> subActions)
    {
        if (subActions == null)
        {
            return;
        }

        ChartEditor editor         = ChartEditor.Instance;
        int         overwriteIndex = SongObjectHelper.FindObjectPosition(songObject, searchObjects);

        if (overwriteIndex != SongObjectHelper.NOTFOUND)
        {
            AddAndInvokeSubAction(new DeleteAction(searchObjects[overwriteIndex]), subActions);
            SetNotesDirty(songObject, searchObjects);
        }
    }
    protected override void Controls()
    {
        if (!GameSettings.keysModeEnabled)
        {
            if (Toolpane.currentTool == Toolpane.Tools.Starpower && Globals.applicationMode == Globals.ApplicationMode.Editor && Input.GetMouseButton(0))
            {
                if (lastPlacedSP == null)
                {
                    // Check if there's a starpower already in that position
                    int arrayPos = SongObjectHelper.FindObjectPosition(starpower, editor.currentChart.starPower);
                    if (arrayPos != SongObjectHelper.NOTFOUND)       // Found an object that matches
                    {
                        overwrittenSP = (Starpower)editor.currentChart.starPower[arrayPos].Clone();
                    }

                    AddObject();
                }
                else
                {
                    UpdateLastPlacedSp();
                }
            }
        }
        else if (ShortcutInput.GetInput(Shortcut.AddSongObject))
        {
            if (ShortcutInput.GetInputDown(Shortcut.AddSongObject))
            {
                var searchArray = editor.currentChart.starPower;
                int pos         = SongObjectHelper.FindObjectPosition(starpower, searchArray);
                if (pos == SongObjectHelper.NOTFOUND)
                {
                    editor.actionHistory.Insert(new ActionHistory.Add(starpower));
                    AddObject();
                }
                else
                {
                    editor.actionHistory.Insert(new ActionHistory.Delete(searchArray[pos]));
                    searchArray[pos].Delete();
                    editor.currentSelectedObject = null;
                }
            }
            else if (lastPlacedSP != null)
            {
                UpdateLastPlacedSp();
            }
        }
    }
Example #20
0
    static Starpower AddStarpower(Starpower sp, IList <SongObject> overwrittenList, IList <SongObject> validatedList)
    {
        ChartEditor editor = ChartEditor.Instance;

        TryRecordOverwrite(sp, editor.currentChart.chartObjects, overwrittenList);

        CapPrevAndNextPreInsert(sp, editor.currentChart, overwrittenList, validatedList);

        Starpower spToAdd = new Starpower(sp);

        editor.currentChart.Add(spToAdd, false);
        Debug.Log("Added new starpower");

        SetNotesDirty(spToAdd, editor.currentChart.chartObjects);

        return(spToAdd);
    }
    public static Note.SpecialType IsStarpower(Note note)
    {
        Note.SpecialType specialType = Note.SpecialType.None;

        int index = SongObjectHelper.FindClosestPositionRoundedDown(note.tick, note.chart.starPower);

        if (index != SongObjectHelper.NOTFOUND)
        {
            Starpower sp = note.chart.starPower[index];
            if (sp.tick == note.tick || (sp.tick <= note.tick && sp.tick + sp.length > note.tick))
            {
                specialType = Note.SpecialType.StarPower;
            }
        }

        return(specialType);
    }
Example #22
0
        static byte[] GetUnrecognisedChartBytes(Chart chart, ExportOptions exportOptions, float resolutionScaleRatio)
        {
            List <SortableBytes> eventList = new List <SortableBytes>();

            foreach (ChartObject chartObject in chart.chartObjects)
            {
                SortableBytes onEvent  = null;
                SortableBytes offEvent = null;

                Note note = chartObject as Note;
                if (note != null)
                {
                    GetUnrecognisedChartNoteBytes(note, out onEvent, out offEvent);
                }

                Starpower sp = chartObject as Starpower;
                if (sp != null)     // Starpower cannot be split up between charts in a midi file
                {
                    GetStarpowerBytes(sp, out onEvent, out offEvent);
                }

                ChartEvent chartEvent = chartObject as ChartEvent;
                if (chartEvent != null)     // Text events cannot be split up in the file
                {
                    SortableBytes bytes = GetChartEventBytes(chartEvent);
                    InsertionSort(eventList, bytes);
                }

                if (onEvent != null && offEvent != null)
                {
                    InsertionSort(eventList, onEvent);

                    if (offEvent.tick == onEvent.tick)
                    {
                        ++offEvent.tick;
                    }

                    InsertionSort(eventList, offEvent);
                }
            }

            return(SortableBytesToTimedEventBytes(eventList.ToArray(), chart.song, exportOptions, resolutionScaleRatio));
        }
Example #23
0
    void SetNewFlags(Starpower sp, Starpower.Flags newFlags)
    {
        if (sp.flags == newFlags)
        {
            return;
        }

        if (editor.toolManager.currentToolId == EditorObjectToolManager.ToolID.Cursor)
        {
            Starpower newSp = new Starpower(sp.tick, sp.length, newFlags);
            SongEditModify <Starpower> command = new SongEditModify <Starpower>(sp, newSp);
            editor.commandStack.Push(command);
        }
        else
        {
            // Updating sp tool parameters and visuals
            starpowerToolController.starpower.flags = newFlags;
            starpowerToolController.controller.SetDirty();
        }
    }
    static ActionHistory.Action[] CapPrevAndNextPreInsert(Starpower sp, Chart chart)
    {
        List <ActionHistory.Action> record = new List <ActionHistory.Action>();
        int arrayPos = SongObjectHelper.FindClosestPosition(sp, chart.starPower);

        if (arrayPos != SongObjectHelper.NOTFOUND)       // Found an object that matches
        {
            if (chart.starPower[arrayPos] < sp)
            {
                ++arrayPos;
            }

            if (arrayPos > 0 && chart.starPower[arrayPos - 1].tick < sp.tick)
            {
                Starpower prevSp = chart.starPower[arrayPos - 1];
                // Cap previous sp
                if (prevSp.tick + prevSp.length > sp.tick)
                {
                    Starpower originalPrev = (Starpower)prevSp.Clone();

                    prevSp.length = sp.tick - prevSp.tick;
                    record.Add(new ActionHistory.Modify(originalPrev, prevSp));
                }
            }

            if (arrayPos < chart.starPower.Count && chart.starPower[arrayPos].tick > sp.tick)
            {
                Starpower nextSp = chart.starPower[arrayPos];

                // Cap self
                if (sp.tick + sp.length > nextSp.tick)
                {
                    Starpower originalNext = (Starpower)nextSp.Clone();
                    sp.length = nextSp.tick - sp.tick;
                    record.Add(new ActionHistory.Modify(originalNext, nextSp));
                }
            }
        }

        return(record.ToArray());
    }
    // Update is called once per frame
    protected override void Update()
    {
        starpower.chart = editor.currentChart;
        if (lastPlacedSP != null)
        {
            spRen.enabled = false;
        }
        else
        {
            spRen.enabled = true;
        }
        base.Update();

        if ((Input.GetMouseButtonUp(0) && !GameSettings.keysModeEnabled) || (GameSettings.keysModeEnabled && Input.GetButtonUp("Add Object")))
        {
            if (lastPlacedSP != null)
            {
                // Make a record of the last SP
                if (overwrittenSP == null)
                {
                    record.Add(new ActionHistory.Add(lastPlacedSP));
                }
                else if (!overwrittenSP.AllValuesCompare(lastPlacedSP))
                {
                    record.Add(new ActionHistory.Modify(overwrittenSP, lastPlacedSP));
                }
            }

            if (record.Count > 0)
            {
                //Debug.Log(record.Count);
                editor.actionHistory.Insert(record.ToArray());
            }

            // Reset
            lastPlacedSP  = null;
            overwrittenSP = null;
            record.Clear();
        }
    }
    public void UpdateVisuals()
    {
        if (!spRenderer)
        {
            Awake();
        }

        Starpower sp = spCon.starpower;

        if (sp != null)
        {
            Starpower.Flags flags = sp.flags;
            if (flags.HasFlag(Starpower.Flags.ProDrums_Activation))
            {
                spRenderer.sharedMaterials = resourceSharedMatsSpDrumFill;
            }
            else
            {
                // Default visuals
                spRenderer.sharedMaterials = resourceSharedMatsSp;
            }
        }
    }
Example #27
0
 public void Reset()
 {
     unmodifiedSP = null;
     wantPop      = false;
 }
Example #28
0
 public void CopyFrom(Starpower sp)
 {
     tick   = sp.tick;
     length = sp.length;
 }
    string GetSaveString <T>(Song song, IList <T> list, ExportOptions exportOptions, ref string out_errorList, Song.Instrument instrument = Song.Instrument.Guitar) where T : SongObject
    {
        System.Text.StringBuilder saveString = new System.Text.StringBuilder();

        float resolutionScaleRatio = song.ResolutionScaleRatio(exportOptions.targetResolution);

        for (int i = 0; i < list.Count; ++i)
        {
            SongObject songObject = list[i];
            try
            {
                uint tick = (uint)Mathf.Round(songObject.tick * resolutionScaleRatio) + exportOptions.tickOffset;
                saveString.Append(Globals.TABSPACE + tick);

                switch ((SongObject.ID)songObject.classID)
                {
                case (SongObject.ID.BPM):
                    BPM bpm = songObject as BPM;
                    if (bpm.anchor != null)
                    {
                        uint anchorValue = (uint)((double)bpm.anchor * 1000000);
                        saveString.AppendFormat(s_anchorFormat, anchorValue, tick);
                    }

                    saveString.AppendFormat(s_bpmFormat, bpm.value);
                    break;

                case (SongObject.ID.TimeSignature):
                    TimeSignature ts = songObject as TimeSignature;

                    if (ts.denominator == 4)
                    {
                        saveString.AppendFormat(s_tsFormat, ts.numerator);
                    }
                    else
                    {
                        uint denominatorSaveVal = (uint)Mathf.Log(ts.denominator, 2);
                        saveString.AppendFormat(s_tsDenomFormat, ts.numerator, denominatorSaveVal);
                    }
                    break;

                case (SongObject.ID.Section):
                    Section section = songObject as Section;
                    saveString.AppendFormat(s_sectionFormat, section.title);
                    break;

                case (SongObject.ID.Event):
                    Event songEvent = songObject as Event;
                    saveString.AppendFormat(s_eventFormat, songEvent.title);
                    break;

                case (SongObject.ID.ChartEvent):
                    ChartEvent chartEvent = songObject as ChartEvent;
                    saveString.AppendFormat(s_chartEventFormat, chartEvent.eventName);
                    break;

                case (SongObject.ID.Starpower):
                    Starpower sp = songObject as Starpower;
                    saveString.AppendFormat(s_starpowerFormat, (uint)Mathf.Round(sp.length * resolutionScaleRatio));
                    break;

                case (SongObject.ID.Note):
                    Note note = songObject as Note;
                    int  fretNumber;

                    if (instrument != Song.Instrument.Unrecognised)
                    {
                        if (instrument == Song.Instrument.Drums)
                        {
                            fretNumber = GetDrumsSaveNoteNumber(note);
                        }

                        else if (instrument == Song.Instrument.GHLiveGuitar || instrument == Song.Instrument.GHLiveBass)
                        {
                            fretNumber = GetGHLSaveNoteNumber(note);
                        }

                        else
                        {
                            fretNumber = GetStandardSaveNoteNumber(note);
                        }
                    }
                    else
                    {
                        fretNumber = note.rawNote;
                    }

                    saveString.AppendFormat(s_noteFormat, fretNumber, (uint)Mathf.Round(note.length * resolutionScaleRatio));

                    // Only need to get the flags of one note of a chord
                    if (exportOptions.forced && (note.next == null || (note.next != null && note.next.tick != note.tick)))
                    {
                        if ((note.flags & Note.Flags.Forced) == Note.Flags.Forced)
                        {
                            saveString.AppendFormat(s_forcedNoteFormat, tick);
                        }

                        // Save taps line if not an open note, as open note taps cause weird artifacts under sp
                        if (!note.IsOpenNote() && (note.flags & Note.Flags.Tap) == Note.Flags.Tap)
                        {
                            saveString.AppendFormat(s_tapNoteFormat, tick);
                        }
                    }
                    continue;

                default:
                    continue;
                }
                saveString.Append(Globals.LINE_ENDING);

                //throw new System.Exception("Test error count: " + i);
            }
            catch (System.Exception e)
            {
                string error = Logger.LogException(e, "Error with saving object #" + i + " as " + songObject);
                out_errorList += error + Globals.LINE_ENDING;
            }
        }

        return(saveString.ToString());
    }
Example #30
0
 public Starpower(Starpower _starpower) : base(_starpower.tick)
 {
     length = _starpower.length;
 }