Skip to content

Commit

Permalink
Merge pull request #4001 from QiuFeng54321/editor-plugin-bookmark
Browse files Browse the repository at this point in the history
Update bookmark support to plugins
  • Loading branch information
AiAe committed Apr 10, 2024
2 parents d346ad8 + 82737c3 commit d28bb24
Show file tree
Hide file tree
Showing 15 changed files with 250 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using MoonSharp.Interpreter;
using MoonSharp.Interpreter.Interop;
using Quaver.API.Maps;
using Quaver.API.Maps.Structures;
using Quaver.Shared.Screens.Edit.Actions.Bookmarks.Remove;

namespace Quaver.Shared.Screens.Edit.Actions.Bookmarks.Add
{
[MoonSharpUserData]
public class EditorActionAddBookmark : IEditorAction
{
public EditorActionType Type { get; } = EditorActionType.AddBookmark;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System.Collections.Generic;
using Quaver.API.Maps;
using Quaver.API.Maps.Structures;
using MoonSharp.Interpreter;
using MoonSharp.Interpreter.Interop;
using Quaver.Shared.Screens.Edit.Actions.Bookmarks.RemoveBatch;

namespace Quaver.Shared.Screens.Edit.Actions.Bookmarks.AddBatch
{
[MoonSharpUserData]
public class EditorActionAddBookmarkBatch : IEditorAction
{
public EditorActionType Type { get; } = EditorActionType.AddBookmarkBatch;

private EditorActionManager ActionManager { get; }

private Qua WorkingMap { get; }

private List<BookmarkInfo> Bookmarks { get; }

[MoonSharpVisible(false)]
public EditorActionAddBookmarkBatch(EditorActionManager manager, Qua workingMap, List<BookmarkInfo> bookmarks)
{
ActionManager = manager;
WorkingMap = workingMap;
Bookmarks = bookmarks;
}

[MoonSharpVisible(false)]
public void Perform()
{
Bookmarks.ForEach(x => WorkingMap.Bookmarks.Add(x));
WorkingMap.Sort();

ActionManager.TriggerEvent(Type, new EditorActionBookmarkBatchAddedEventArgs(Bookmarks));
}

[MoonSharpVisible(false)]
public void Undo() => new EditorActionRemoveBookmarkBatch(ActionManager, WorkingMap, Bookmarks).Perform();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using Quaver.API.Maps.Structures;

namespace Quaver.Shared.Screens.Edit.Actions.Bookmarks.AddBatch
{
public class EditorActionBookmarkBatchAddedEventArgs : EventArgs
{
public List<BookmarkInfo> Bookmarks { get; }

public EditorActionBookmarkBatchAddedEventArgs(List<BookmarkInfo> bookmarks) => Bookmarks = bookmarks;
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
using MoonSharp.Interpreter;
using MoonSharp.Interpreter.Interop;
using Quaver.API.Maps;
using Quaver.API.Maps.Structures;

namespace Quaver.Shared.Screens.Edit.Actions.Bookmarks.Edit
{
[MoonSharpUserData]
public class EditorActionEditBookmark : IEditorAction
{
public EditorActionType Type { get; } = EditorActionType.EditBookmark;
Expand All @@ -17,6 +20,7 @@ public class EditorActionEditBookmark : IEditorAction

private string OldNote { get; }

[MoonSharpVisible(false)]
public EditorActionEditBookmark(EditorActionManager manager, Qua workingMap, BookmarkInfo bookmark, string newNote)
{
ActionManager = manager;
Expand All @@ -26,12 +30,14 @@ public EditorActionEditBookmark(EditorActionManager manager, Qua workingMap, Boo
OldNote = Bookmark.Note;
}

[MoonSharpVisible(false)]
public void Perform()
{
Bookmark.Note = NewNote;
ActionManager.TriggerEvent(Type, new EditorActionBookmarkEditedEventArgs(Bookmark));
}

[MoonSharpVisible(false)]
public void Undo() => new EditorActionEditBookmark(ActionManager, WorkingMap, Bookmark, OldNote).Perform();
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
using System.Collections.Generic;
using MoonSharp.Interpreter;
using MoonSharp.Interpreter.Interop;
using Quaver.API.Maps;
using Quaver.API.Maps.Structures;

namespace Quaver.Shared.Screens.Edit.Actions.Bookmarks.Offset
{
[MoonSharpUserData]
public class EditorActionChangeBookmarkOffsetBatch : IEditorAction
{
public EditorActionType Type { get; } = EditorActionType.ChangeBookmarkOffsetBatch;
Expand All @@ -16,6 +19,7 @@ public class EditorActionChangeBookmarkOffsetBatch : IEditorAction

private int Offset { get; }

[MoonSharpVisible(false)]
public EditorActionChangeBookmarkOffsetBatch(EditorActionManager manager, Qua map, List<BookmarkInfo> bookmarks, int offset)
{
ActionManager = manager;
Expand All @@ -24,6 +28,7 @@ public EditorActionChangeBookmarkOffsetBatch(EditorActionManager manager, Qua ma
Offset = offset;
}

[MoonSharpVisible(false)]
public void Perform()
{
foreach (var bookmark in Bookmarks)
Expand All @@ -33,6 +38,7 @@ public void Perform()
ActionManager.TriggerEvent(Type, new EditorActionChangeBookmarkOffsetBatchEventArgs(Bookmarks, Offset));
}

[MoonSharpVisible(false)]
public void Undo() => new EditorActionChangeBookmarkOffsetBatch(ActionManager, WorkingMap, Bookmarks, -Offset).Perform();
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using MoonSharp.Interpreter.Interop;
using Quaver.API.Maps;
using Quaver.API.Maps.Structures;
using Quaver.Shared.Screens.Edit.Actions.Bookmarks.Add;
Expand All @@ -14,13 +15,15 @@ public class EditorActionRemoveBookmark : IEditorAction

private BookmarkInfo Bookmark { get; }

[MoonSharpVisible(false)]
public EditorActionRemoveBookmark(EditorActionManager manager, Qua map, BookmarkInfo bookmark)
{
ActionManager = manager;
WorkingMap = map;
Bookmark = bookmark;
}

[MoonSharpVisible(false)]
public void Perform()
{
WorkingMap.Bookmarks.Remove(Bookmark);
Expand All @@ -29,6 +32,7 @@ public void Perform()
ActionManager.TriggerEvent(Type, new EditorActionBookmarkRemovedEventArgs(Bookmark));
}

[MoonSharpVisible(false)]
public void Undo() => new EditorActionAddBookmark(ActionManager, WorkingMap, Bookmark).Perform();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System.Collections.Generic;
using Quaver.API.Maps.Structures;
using Quaver.Shared.Screens.Edit.Actions.Bookmarks.AddBatch;

namespace Quaver.Shared.Screens.Edit.Actions.Bookmarks.RemoveBatch
{
public class EditorActionBookmarkBatchRemovedEventArgs : EditorActionBookmarkBatchAddedEventArgs
{
public EditorActionBookmarkBatchRemovedEventArgs(List<BookmarkInfo> bookmarks) : base(bookmarks)
{
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System.Collections.Generic;
using Quaver.API.Maps;
using Quaver.API.Maps.Structures;
using MoonSharp.Interpreter;
using MoonSharp.Interpreter.Interop;
using Quaver.Shared.Screens.Edit.Actions.Bookmarks.AddBatch;

namespace Quaver.Shared.Screens.Edit.Actions.Bookmarks.RemoveBatch
{
[MoonSharpUserData]
public class EditorActionRemoveBookmarkBatch : IEditorAction
{
public EditorActionType Type { get; } = EditorActionType.RemoveBookmarkBatch;

private EditorActionManager ActionManager { get; }

private Qua WorkingMap { get; }

private List<BookmarkInfo> Bookmarks { get; }

[MoonSharpVisible(false)]
public EditorActionRemoveBookmarkBatch(EditorActionManager manager, Qua workingMap, List<BookmarkInfo> bookmarks)
{
ActionManager = manager;
WorkingMap = workingMap;
Bookmarks = bookmarks;
}

[MoonSharpVisible(false)]
public void Perform()
{
foreach (var sv in Bookmarks)
WorkingMap.Bookmarks.Remove(sv);

ActionManager.TriggerEvent(Type, new EditorActionBookmarkBatchRemovedEventArgs(Bookmarks));
}

[MoonSharpVisible(false)]
public void Undo() => new EditorActionAddBookmarkBatch(ActionManager, WorkingMap, Bookmarks).Perform();
}
}
31 changes: 31 additions & 0 deletions Quaver.Shared/Screens/Edit/Actions/EditorActionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
using Quaver.Shared.Screens.Edit.Actions.Batch;
using Quaver.Shared.Screens.Edit.Actions.Bookmarks;
using Quaver.Shared.Screens.Edit.Actions.Bookmarks.Add;
using Quaver.Shared.Screens.Edit.Actions.Bookmarks.AddBatch;
using Quaver.Shared.Screens.Edit.Actions.Bookmarks.Edit;
using Quaver.Shared.Screens.Edit.Actions.Bookmarks.Offset;
using Quaver.Shared.Screens.Edit.Actions.Bookmarks.Remove;
using Quaver.Shared.Screens.Edit.Actions.Bookmarks.RemoveBatch;
using Quaver.Shared.Screens.Edit.Actions.HitObjects.Flip;
using Quaver.Shared.Screens.Edit.Actions.HitObjects.Move;
using Quaver.Shared.Screens.Edit.Actions.HitObjects.Place;
Expand Down Expand Up @@ -267,6 +269,16 @@ public class EditorActionManager : IDisposable
/// Event invoked when a bookmark has been removed.
/// </summary>
public event EventHandler<EditorActionBookmarkRemovedEventArgs> BookmarkRemoved;

/// <summary>
/// Event invoked when a bookmark has been added.
/// </summary>
public event EventHandler<EditorActionBookmarkBatchAddedEventArgs> BookmarkBatchAdded;

/// <summary>
/// Event invoked when a bookmark has been removed.
/// </summary>
public event EventHandler<EditorActionBookmarkBatchRemovedEventArgs> BookmarkBatchRemoved;

/// <summary>
/// Event invoked whe na bookmark has been edited.
Expand Down Expand Up @@ -607,12 +619,23 @@ public void SetHitObjectSelection(List<HitObjectInfo> hitObjects)
/// <param name="note"></param>
public void AddBookmark(int time, string note) => Perform(new EditorActionAddBookmark(this, WorkingMap, new BookmarkInfo { StartTime = time, Note = note }));

/// <summary>
/// Adds a batch of bookmarks to the map
/// </summary>
/// <param name="bookmarks"></param>
public void AddBookmarkBatch(List<BookmarkInfo> bookmarks) => Perform(new EditorActionAddBookmarkBatch(this, WorkingMap, bookmarks));
/// <summary>
/// Removes a bookmark from the map.
/// </summary>
/// <param name="bookmark"></param>
public void RemoveBookmark(BookmarkInfo bookmark) => Perform(new EditorActionRemoveBookmark(this, WorkingMap, bookmark));

/// <summary>
/// Removes a batch of bookmarks from the map.
/// </summary>
/// <param name="bookmark"></param>
public void RemoveBookmarkBatch(List<BookmarkInfo> bookmark) => Perform(new EditorActionRemoveBookmarkBatch(this, WorkingMap, bookmark));

/// <summary>
/// Edits the note of an existing bookmark
/// </summary>
Expand Down Expand Up @@ -744,6 +767,12 @@ public void TriggerEvent(EditorActionType type, EventArgs args)
case EditorActionType.RemoveBookmark:
BookmarkRemoved?.Invoke(this, (EditorActionBookmarkRemovedEventArgs) args);
break;
case EditorActionType.AddBookmarkBatch:
BookmarkBatchAdded?.Invoke(this, (EditorActionBookmarkBatchAddedEventArgs) args);
break;
case EditorActionType.RemoveBookmarkBatch:
BookmarkBatchRemoved?.Invoke(this, (EditorActionBookmarkBatchRemovedEventArgs) args);
break;
case EditorActionType.EditBookmark:
BookmarkEdited?.Invoke(this, (EditorActionBookmarkEditedEventArgs) args);
break;
Expand Down Expand Up @@ -797,6 +826,8 @@ public void Dispose()
BookmarkAdded = null;
BookmarkRemoved = null;
BookmarkEdited = null;
BookmarkBatchAdded = null;
BookmarkBatchRemoved = null;
BookmarkBatchOffsetChanged = null;
}
}
Expand Down
2 changes: 2 additions & 0 deletions Quaver.Shared/Screens/Edit/Actions/EditorActionType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ public enum EditorActionType
Batch,
ReverseHitObjects,
AddBookmark,
AddBookmarkBatch,
EditBookmark,
RemoveBookmark,
RemoveBookmarkBatch,
ChangeBookmarkOffsetBatch
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,10 @@ public HitObjectInfo PlaceHitObject(int lane, int startTime, int endTime = 0, in
ActionManager.ResnapNotes(snaps, hitObjectsToResnap);

public void AddBookmark(int time, string note) => ActionManager.AddBookmark(time, note);
public void AddBookmarkBatch(List<BookmarkInfo> bookmarks) => ActionManager.AddBookmarkBatch(bookmarks);

public void RemoveBookmark(BookmarkInfo bookmark) => ActionManager.RemoveBookmark(bookmark);
public void RemoveBookmarkBatch(List<BookmarkInfo> bookmarks) => ActionManager.RemoveBookmarkBatch(bookmarks);

public void EditBookmark(BookmarkInfo bookmark, string note) => ActionManager.EditBookmark(bookmark, note);

Expand Down
6 changes: 6 additions & 0 deletions Quaver.Shared/Screens/Edit/Plugins/EditorPluginMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ public class EditorPluginMap
/// The non-default editor layers that are currently in the map
/// </summary>
public List<EditorLayerInfo> EditorLayers { get; [MoonSharpVisible(false)] set; }

/// <summary>
/// The bookmarks that are currently in the map
/// </summary>
public List<BookmarkInfo> Bookmarks { get; [MoonSharpVisible(false)] set; }

/// <summary>
/// The default editor layer
Expand All @@ -69,6 +74,7 @@ public void SetFrameState()
ScrollVelocities = Map.SliderVelocities; // Original name was SliderVelocities but that name doesn't really make sense
HitObjects = Map.HitObjects;
EditorLayers = Map.EditorLayers;
Bookmarks = Map.Bookmarks;
TrackLength = Track.Length;
Normalized = Map.BPMDoesNotAffectScrollVelocity;
}
Expand Down
Loading

0 comments on commit d28bb24

Please sign in to comment.