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());
    }
Beispiel #2
0
    public void SetNoteType(Note.NoteType type)
    {
        List <ActionHistory.Action> actions = new List <ActionHistory.Action>();

        foreach (ChartObject chartObject in editor.currentSelectedObjects)
        {
            if (chartObject.classID == (int)SongObject.ID.Note)
            {
                Note note = chartObject as Note;

                // Need to record the whole chord
                Note   unmodified = (Note)note.Clone();
                Note[] chord      = note.GetChord();

                ActionHistory.Action[] deleteRecord = new ActionHistory.Action[chord.Length];
                for (int i = 0; i < deleteRecord.Length; ++i)
                {
                    deleteRecord[i] = new ActionHistory.Delete(chord[i]);
                }

                note.SetType(type);
                //SetNoteType(note as Note, type);

                chord = note.GetChord();

                ActionHistory.Action[] addRecord = new ActionHistory.Action[chord.Length];
                for (int i = 0; i < addRecord.Length; ++i)
                {
                    addRecord[i] = new ActionHistory.Add(chord[i]);
                }

                if (note.flags != unmodified.flags)
                {
                    actions.AddRange(deleteRecord);
                    actions.AddRange(addRecord);
                }

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

            if (chartObject.controller)
            {
                chartObject.controller.SetDirty();
            }
        }

        if (actions.Count > 0)
        {
            editor.actionHistory.Insert(actions.ToArray());
        }

        ChartEditor.isDirty = true;
    }
 protected void RecordAddActionHistory <T>(T overwriteCheck, IList <T> overWriteSearch) where T : SongObject
 {
     ActionHistory.Action record = OverwriteActionHistory(overwriteCheck, overWriteSearch);
     if (record != null)
     {
         editor.actionHistory.Insert(record);
     }
 }
    protected static ActionHistory.Action[] ForwardCap(Note note)
    {
        List <ActionHistory.Action> actionRecord = new List <ActionHistory.Action>();
        Note next;

        next = note.nextSeperateNote;

        if (!GameSettings.extendedSustainsEnabled)
        {
            // Get chord
            next = note.nextSeperateNote;

            if (next != null)
            {
                foreach (Note noteToCap in note.chord)
                {
                    ActionHistory.Action action = noteToCap.CapSustain(next);
                    if (action != null)
                    {
                        actionRecord.Add(action);
                    }
                }
            }
        }
        else
        {
            // Find the next note of the same fret type or open
            next = note.next;
            while (next != null && next.guitarFret != note.guitarFret && !next.IsOpenNote())
            {
                next = next.next;
            }

            // If it's an open note it won't be capped

            if (next != null)
            {
                ActionHistory.Action action = note.CapSustain(next);
                if (action != null)
                {
                    actionRecord.Add(action);
                }
            }
        }


        return(actionRecord.ToArray());
    }
    protected static ActionHistory.Action[] CapNoteCheck(Note noteToAdd)
    {
        List <ActionHistory.Action> actionRecord = new List <ActionHistory.Action>();

        Note[] previousNotes = NoteFunctions.GetPreviousOfSustains(noteToAdd);
        if (!GameSettings.extendedSustainsEnabled)
        {
            // Cap all the notes
            foreach (Note prevNote in previousNotes)
            {
                if (prevNote.controller != null)
                {
                    ActionHistory.Action action = prevNote.CapSustain(noteToAdd);
                    if (action != null)
                    {
                        actionRecord.Add(action);
                    }
                }
            }

            foreach (Note chordNote in noteToAdd.chord)
            {
                if (chordNote.controller != null)
                {
                    chordNote.controller.note.length = noteToAdd.length;
                }
            }
        }
        else
        {
            // Cap only the sustain of the same fret type and open notes
            foreach (Note prevNote in previousNotes)
            {
                if (prevNote.controller != null && (noteToAdd.IsOpenNote() || prevNote.guitarFret == noteToAdd.guitarFret))
                {
                    ActionHistory.Action action = prevNote.CapSustain(noteToAdd);
                    if (action != null)
                    {
                        actionRecord.Add(action);
                    }
                }
            }
        }

        return(actionRecord.ToArray());
    }
Beispiel #6
0
    public void Move(Vector3 dest)
    {
        ActionHistory.Action moveAction = null;
        moveAction = delegate(GameObject self) {
            Movement movement = self.GetComponent <Movement>();

            if (!movement.CanMove(dest))
            {
                return(false);
            }

            movement.projectedLocation = dest;
            movement.SmoothMovement(dest);
            movement.actionHistory.Add(moveAction);

            return(true);
        };
        moveAction(gameObject);
    }
Beispiel #7
0
    protected virtual void Drop()
    {
        if (acting) //avoid infinite recursion
        {
            return;
        }

        acting = true;

        ActionHistory.Action dropAction = delegate(GameObject actor)
        {
            CarriedItem  slot = actor.GetComponent <CarriedItem>();
            PickableItem item = slot.carriedItem;

            item.RestoreTransform(new Vector3(0, 0, 0));
            item.slotTaken = null;
            item.pickedUp  = false;

            //Free the slot next turn so that the item is not picked up immediately
            new WaitNextTurn().Then(() => slot.Free()).Start(this);

            /* Put on top for one turn
             * SpriteRenderer renderer = item.GetComponent<SpriteRenderer>();
             * renderer.sortingLayerName = "Actor";
             * renderer.sortingOrder = 2;
             *
             * new WaitNextTurn().Then(() => {
             *  if (renderer.sortingOrder == 2) { //CAS
             *      renderer.sortingLayerName = "Item";
             *      renderer.sortingOrder = 0;
             *  }
             * }).Start(this);
             * //*/

            return(false);
        };

        slotTaken.gameObject.GetComponent <Movement>().actionHistory.Add(dropAction);
        dropAction(slotTaken.gameObject);

        acting = false;
    }
    protected override void AddObject()
    {
        System.Collections.Generic.List <ActionHistory.Action> noteRecord = new System.Collections.Generic.List <ActionHistory.Action>();
        noteRecord.Add(new ActionHistory.Delete(initObject));
        int arrayPos = SongObjectHelper.FindObjectPosition(note, editor.currentChart.notes);

        if (arrayPos != SongObjectHelper.NOTFOUND)       // Found an object that matches
        {
            if (!note.AllValuesCompare(editor.currentChart.notes[arrayPos]))
            {
                // Object will changed, therefore record
                noteRecord.Add(new ActionHistory.Modify(editor.currentChart.notes[arrayPos], note));
            }
        }
        else
        {
            noteRecord.Add(new ActionHistory.Add(note));
        }

        Note noteToAdd = new Note(note);

        editor.currentChart.Add(noteToAdd);
        //NoteController nCon = editor.CreateNoteObject(noteToAdd);
        standardOverwriteOpen(noteToAdd);

        noteRecord.AddRange(CapNoteCheck(noteToAdd));
        noteRecord.AddRange(ForwardCap(noteToAdd));     // Do this due to pasting from the clipboard

        // Check if the automatic un-force will kick in
        ActionHistory.Action forceCheck = AutoForcedCheck(noteToAdd);
        if (forceCheck != null)
        {
            noteRecord.Insert(0, forceCheck);           // Insert at the start so that the modification happens at the end of the undo function, otherwise the natural force check prevents it from being forced
        }
        editor.currentSelectedObject = noteToAdd;
        if (noteRecord.Count > 0 && !initObject.AllValuesCompare(noteToAdd))
        {
            editor.actionHistory.Insert(noteRecord.ToArray());
        }
    }
Beispiel #9
0
    protected virtual void Activate()
    {
        if (acting) //avoid infinite recursion
        {
            return;
        }

        acting = true;

        ActionHistory.Action activation = null;
        activation = delegate(GameObject actor)
        {
            CarriedItem  slot = actor.GetComponent <CarriedItem>();
            PickableItem item = slot.carriedItem;

            item.Activate();
            return(false);
        };

        activation(slotTaken.gameObject);
        slotTaken.gameObject.GetComponent <Movement>().actionHistory.Add(activation);

        acting = false;
    }
    public static ActionHistory.Action[] AddObjectToCurrentChart(Note note, ChartEditor editor, out Note addedNote, bool update = true, bool copy = true)
    {
        List <ActionHistory.Action> noteRecord = new List <ActionHistory.Action>();

        int index, length;

        SongObjectHelper.GetRange(editor.currentChart.notes, note.tick, note.tick, out index, out length);

        // Account for when adding an exact note as what's already in
        if (length > 0)
        {
            bool cancelAdd = false;
            for (int i = index; i < index + length; ++i)
            {
                Note overwriteNote = editor.currentChart.notes[i];

                if (note.AllValuesCompare(overwriteNote))
                {
                    cancelAdd = true;
                    break;
                }
                if ((((note.IsOpenNote() || overwriteNote.IsOpenNote()) && !Globals.drumMode) || note.guitarFret == overwriteNote.guitarFret) && !note.AllValuesCompare(overwriteNote))
                {
                    noteRecord.Add(new ActionHistory.Delete(overwriteNote));
                }
            }
            if (!cancelAdd)
            {
                noteRecord.Add(new ActionHistory.Add(note));
            }
        }
        else
        {
            noteRecord.Add(new ActionHistory.Add(note));
        }

        Note noteToAdd;

        if (copy)
        {
            noteToAdd = new Note(note);
        }
        else
        {
            noteToAdd = note;
        }

        if (noteToAdd.IsOpenNote())
        {
            noteToAdd.flags &= ~Note.Flags.Tap;
        }

        editor.currentChart.Add(noteToAdd, update);
        if (noteToAdd.cannotBeForced)
        {
            noteToAdd.flags &= ~Note.Flags.Forced;
        }

        noteToAdd.ApplyFlagsToChord();

        //NoteController nCon = editor.CreateNoteObject(noteToAdd);
        standardOverwriteOpen(noteToAdd);

        noteRecord.InsertRange(0, CapNoteCheck(noteToAdd));
        noteRecord.InsertRange(0, ForwardCap(noteToAdd));     // Do this due to pasting from the clipboard

        // Check if the automatic un-force will kick in
        ActionHistory.Action forceCheck = AutoForcedCheck(noteToAdd);

        addedNote = noteToAdd;

        if (forceCheck != null)
        {
            noteRecord.Insert(0, forceCheck);           // Insert at the start so that the modification happens at the end of the undo function, otherwise the natural force check prevents it from being forced
        }
        foreach (Note chordNote in addedNote.chord)
        {
            if (chordNote.controller)
            {
                chordNote.controller.SetDirty();
            }
        }

        Note next = addedNote.nextSeperateNote;

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

        return(noteRecord.ToArray());
    }