Exemple #1
0
        public override SongObject Invoke(ChartEditor editor)
        {
            foreach (SongObject songObject in songObjects)
            {
                PlaceSongObject.AddObjectToCurrentEditor(songObject.Clone(), editor, false);
            }

            return(songObjects[0]);
        }
Exemple #2
0
    void ReadClipboardFromFile()
    {
        FileStream fs = null;

        clipboard = null;

        try
        {
            // Read clipboard data from a file instead of the actual clipboard because the actual clipboard doesn't work for whatever reason
            fs = new FileStream(ClipboardObjectController.CLIPBOARD_FILE_LOCATION, FileMode.Open);
            BinaryFormatter formatter = new BinaryFormatter();

            clipboard = (Clipboard)formatter.Deserialize(fs);
        }
        catch (System.Exception e)
        {
            Logger.LogException(e, "Failed to read from clipboard file");
            clipboard = null;
        }
        finally
        {
            if (fs != null)
            {
                fs.Close();
            }
            else
            {
                Debug.LogError("Filestream when reading clipboard data failed to initialise");
            }
        }

        if (clipboard != null)
        {
            foreach (SongObject clipboardSongObject in clipboard.data)
            {
                PlaceSongObject.AddObjectToCurrentEditor(clipboardSongObject.Clone(), editor, false);
            }
        }
    }
Exemple #3
0
    public void AddSongObjects()
    {
        List <ActionHistory.Action> record       = new List <ActionHistory.Action>();
        List <ActionHistory.Action> deleteRecord = new List <ActionHistory.Action>();

        // Need to remember to undo/redo. This current will only work once object pools are implemented.
        // Check to see what the current offset is to decide how to record
        // Will also need to check for overwrites
        // All relative to the original notes

        bool moved = false;

        for (int i = 0; i < movingSongObjects.Count; ++i)
        {
            ActionHistory.Action overwriteRecord;

            if (movingSongObjects[i] != originalSongObjects[i])
            {
                moved = true;
                deleteRecord.Add(new ActionHistory.Delete(originalSongObjects[i]));
            }

            switch ((SongObject.ID)movingSongObjects[i].classID)
            {
            case (SongObject.ID.Note):
                record.AddRange(PlaceNote.AddObjectToCurrentChart((Note)movingSongObjects[i], editor, false, false));         // Capping
                break;

            case (SongObject.ID.Starpower):
                record.AddRange(PlaceStarpower.AddObjectToCurrentChart((Starpower)movingSongObjects[i], editor, false, false));           // Capping
                break;

            case (SongObject.ID.ChartEvent):
                overwriteRecord = PlaceSongObject.OverwriteActionHistory((ChartEvent)movingSongObjects[i], editor.currentChart.events);
                if (record != null)
                {
                    record.Add(overwriteRecord);
                }
                editor.currentChart.Add((ChartEvent)movingSongObjects[i], false);
                break;

            case (SongObject.ID.BPM):
                overwriteRecord = PlaceSongObject.OverwriteActionHistory((BPM)movingSongObjects[i], editor.currentSong.bpms);
                if (record != null)
                {
                    record.Add(overwriteRecord);
                }
                BPM bpm = (BPM)movingSongObjects[i];
                editor.currentSong.Add(bpm, false);
                if (bpm.anchor != null)
                {
                    bpm.anchor = bpm.song.LiveTickToTime(bpm.tick, bpm.song.resolution);
                }

                ChartEditor.GetInstance().songObjectPoolManager.SetAllPoolsDirty();
                break;

            case (SongObject.ID.TimeSignature):
                overwriteRecord = PlaceSongObject.OverwriteActionHistory((TimeSignature)movingSongObjects[i], editor.currentSong.timeSignatures);
                if (record != null)
                {
                    record.Add(overwriteRecord);
                }
                editor.currentSong.Add((TimeSignature)movingSongObjects[i], false);
                break;

            case (SongObject.ID.Section):
                overwriteRecord = PlaceSongObject.OverwriteActionHistory((Section)movingSongObjects[i], editor.currentSong.sections);
                if (record != null)
                {
                    record.Add(overwriteRecord);
                }
                editor.currentSong.Add((Section)movingSongObjects[i], false);
                break;

            case (SongObject.ID.Event):
                overwriteRecord = PlaceSongObject.OverwriteActionHistory((Event)movingSongObjects[i], editor.currentSong.events);
                if (record != null)
                {
                    record.Add(overwriteRecord);
                }
                editor.currentSong.Add((Event)movingSongObjects[i], false);
                break;

            default:
                break;
            }
        }

        editor.currentSelectedObjects = movingSongObjects.ToArray();

        if (moved)
        {
            editor.actionHistory.Insert(deleteRecord.ToArray());                // In case user removes a bpm from an anchor area
            editor.actionHistory.Insert(bpmAnchorRecord.ToArray());

            editor.currentSong.UpdateCache();
            editor.currentChart.UpdateCache();

            editor.actionHistory.Insert(record.ToArray());
            editor.actionHistory.Insert(editor.FixUpBPMAnchors().ToArray());    // In case user moves a bpm into an anchor area
        }

        editor.currentSong.UpdateCache();
        editor.currentChart.UpdateCache();

        Reset();
    }
    // Paste the clipboard data into the chart, overwriting anything else in the process
    public void Paste(uint chartLocationToPaste)
    {
        //if (System.Windows.Forms.Clipboard.GetDataObject().GetFormats().Length > 0 &&
        //    !(
        //        System.Windows.Forms.Clipboard.ContainsText(TextDataFormat.UnicodeText) &&
        //        System.Windows.Forms.Clipboard.ContainsText(TextDataFormat.Text) &&
        //        System.Windows.Forms.Clipboard.GetText() == "")
        //    )     // Something else is pasted on the clipboard instead of Moonscraper stuff.
        //    return;

        FileStream fs = null;

        clipboard = null;
        try
        {
            // Read clipboard data from a file instead of the actual clipboard because the actual clipboard doesn't work for whatever reason
            fs = new FileStream(CLIPBOARD_FILE_LOCATION, FileMode.Open);
            BinaryFormatter formatter = new BinaryFormatter();

            clipboard = (Clipboard)formatter.Deserialize(fs);
        }
        catch (System.Exception e)
        {
            Logger.LogException(e, "Failed to read from clipboard file");
            clipboard = null;
        }
        finally
        {
            if (fs != null)
            {
                fs.Close();
            }
            else
            {
                Debug.LogError("Filestream when reading clipboard data failed to initialise");
            }
        }

        if (Globals.applicationMode == Globals.ApplicationMode.Editor && clipboard != null && clipboard.data.Length > 0)
        {
            List <ActionHistory.Action> record = new List <ActionHistory.Action>();
            Rect collisionRect = clipboard.GetCollisionRect(chartLocationToPaste, editor.currentSong);
            if (clipboard.areaChartPosMin > clipboard.areaChartPosMax)
            {
                Debug.LogError("Clipboard minimum (" + clipboard.areaChartPosMin + ") is greater than clipboard the max (" + clipboard.areaChartPosMax + ")");
            }
            uint colliderChartDistance = TickFunctions.TickScaling(clipboard.areaChartPosMax - clipboard.areaChartPosMin, clipboard.resolution, editor.currentSong.resolution);

            viewModeController.ToggleSongViewMode(!clipboard.data[0].GetType().IsSubclassOf(typeof(ChartObject)));

            // Overwrite any objects in the clipboard space
            if (clipboard.data[0].GetType().IsSubclassOf(typeof(ChartObject)))
            {
                foreach (ChartObject chartObject in editor.currentChart.chartObjects)
                {
                    if (chartObject.tick >= chartLocationToPaste && chartObject.tick <= (chartLocationToPaste + colliderChartDistance) && PrefabGlobals.HorizontalCollisionCheck(PrefabGlobals.GetCollisionRect(chartObject), collisionRect))
                    {
                        chartObject.Delete(false);

                        record.Add(new ActionHistory.Delete(chartObject));
                    }
                }
            }
            else
            {
                // Overwrite synctrack, leave sections alone
                foreach (SyncTrack syncObject in editor.currentSong.syncTrack)
                {
                    if (syncObject.tick >= chartLocationToPaste && syncObject.tick <= (chartLocationToPaste + colliderChartDistance) && PrefabGlobals.HorizontalCollisionCheck(PrefabGlobals.GetCollisionRect(syncObject), collisionRect))
                    {
                        syncObject.Delete(false);

                        record.Add(new ActionHistory.Delete(syncObject));
                    }
                }
            }

            editor.currentChart.UpdateCache();
            editor.currentSong.UpdateCache();

            uint maxLength = editor.currentSong.TimeToTick(editor.currentSong.length, editor.currentSong.resolution);

            // Paste the new objects in
            foreach (SongObject clipboardSongObject in clipboard.data)
            {
                SongObject objectToAdd = clipboardSongObject.Clone();

                objectToAdd.tick = chartLocationToPaste +
                                   TickFunctions.TickScaling(clipboardSongObject.tick, clipboard.resolution, editor.currentSong.resolution) -
                                   TickFunctions.TickScaling(clipboard.areaChartPosMin, clipboard.resolution, editor.currentSong.resolution);

                if (objectToAdd.tick >= maxLength)
                {
                    break;
                }

                if (objectToAdd.GetType() == typeof(Note))
                {
                    Note note = (Note)objectToAdd;

                    if (clipboard.instrument == Song.Instrument.GHLiveGuitar || clipboard.instrument == Song.Instrument.GHLiveBass)
                    {
                        // Pasting from a ghl track
                        if (!Globals.ghLiveMode)
                        {
                            if (note.ghliveGuitarFret == Note.GHLiveGuitarFret.Open)
                            {
                                note.guitarFret = Note.GuitarFret.Open;
                            }
                            else if (note.ghliveGuitarFret == Note.GHLiveGuitarFret.White3)
                            {
                                continue;
                            }
                        }
                    }
                    else if (Globals.ghLiveMode)
                    {
                        // Pasting onto a ghl track
                        if (note.guitarFret == Note.GuitarFret.Open)
                        {
                            note.ghliveGuitarFret = Note.GHLiveGuitarFret.Open;
                        }
                    }

                    note.length = TickFunctions.TickScaling(note.length, clipboard.resolution, editor.currentSong.resolution);

                    record.AddRange(PlaceNote.AddObjectToCurrentChart(note, editor, false));
                }
                else if (objectToAdd.GetType() == typeof(Starpower))
                {
                    Starpower sp = (Starpower)objectToAdd;
                    sp.length = TickFunctions.TickScaling(sp.length, clipboard.resolution, editor.currentSong.resolution);

                    record.AddRange(PlaceStarpower.AddObjectToCurrentChart(sp, editor, false));
                }
                else
                {
                    PlaceSongObject.AddObjectToCurrentEditor(objectToAdd, editor, false);

                    record.Add(new ActionHistory.Add(objectToAdd));
                }
            }
            editor.currentChart.UpdateCache();
            editor.currentSong.UpdateCache();
            editor.actionHistory.Insert(record.ToArray());
            editor.actionHistory.Insert(editor.FixUpBPMAnchors().ToArray());
        }
        // 0 objects in clipboard, don't bother pasting
    }