Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Selecting all the notes in a bookmark/timing change #59

Merged
merged 6 commits into from
Jul 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 0 additions & 17 deletions Classes/Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -306,23 +306,6 @@ public static Window GetFirstWindow<T>() where T : Window {
}
return null;
}
public static bool InsertSortedUnique(List<Note> notes, Note note) {
// check which index to insert the new note at (keep everything in sorted order)
var i = 0;
foreach (var thisNote in notes) {
int comp = thisNote.CompareTo(note);
if (comp == 0) {
return false;
}
if (comp > 0) {
notes.Insert(i, note);
return true;
}
i++;
}
notes.Add(note);
return true;
}
// TODO figure out a better way than this
public static string UidGenerator(Note n) {
return $"Note({Math.Round(n.beat, 4)},{n.col})";
Expand Down
99 changes: 58 additions & 41 deletions Classes/Integrations/DiscordClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,51 +4,68 @@

public class DiscordClient {
DiscordRpcClient client;
DateTime startTime;
bool enabled = false;
public DiscordClient() {
UpdateStartTime();
InitClient();
}
DateTime startTime;
bool enabled = false;
public DiscordClient() {
UpdateStartTime();
}

public void UpdateStartTime() {
startTime = DateTime.UtcNow;
}
public void UpdateStartTime() {
startTime = DateTime.UtcNow;
}
public void SetPresence() {
SetPresence(null, 0);
SetPresence(null, 0);
}
public void SetPresence(string songName, int numNotes) {
if (!enabled) {
return;
if (!enabled) {
return;
}
var rp = new RichPresence() {
Details = songName == null ? "No song open" : $"Mapping: {songName}",
State = songName == null ? "" : $"{numNotes} notes placed",
Assets = new Assets() {
LargeImageKey = Edda.Const.DiscordRPC.IconKey
}
}.WithTimestamps(new Timestamps(startTime));
var rp = new RichPresence() {
Details = GetPresenceDetails(songName),
State = songName == null ? "" : $"{numNotes} notes placed",
Assets = new Assets() {
LargeImageKey = Edda.Const.DiscordRPC.IconKey
}
}.WithTimestamps(new Timestamps(startTime));

client.SetPresence(rp);
}

client.SetPresence(rp);
}
public void Enable() {
enabled = true;
InitClient();
}
public void Disable() {
enabled = false;
//client.ClearPresence(); this causes a null-dereference crash in the library
DeinitClient();
}
private void InitClient() {
client = new DiscordRpcClient(Edda.Const.DiscordRPC.AppID);
client.Initialize();
SetPresence();
}
private void DeinitClient() {
if (client != null) {
client.Deinitialize();
client = null;
}
}
private string GetPresenceDetails(string songName)
{
return songName switch
{
null => "No song open",
"" => "Working on an untitled map",
_ => $"Mapping: {songName}",
};
}

public void Enable() {
var wasEnabled = enabled;
enabled = true;
if (!wasEnabled)
{
InitClient();
}
}
public void Disable() {
var wasEnabled = enabled;
enabled = false;
if (wasEnabled)
{
DeinitClient();
}
}
private void InitClient() {
client = new DiscordRpcClient(Edda.Const.DiscordRPC.AppID);
client.Initialize();
SetPresence();
}
private void DeinitClient() {
if (client != null) {
client.Deinitialize();
client = null;
}
}
}
3 changes: 1 addition & 2 deletions Classes/MapEditor/BPMChange.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ public int CompareTo(object obj) {
if (!(obj is BPMChange n)) {
throw new Exception();
}
BPMChange m = this;
return m.globalBeat.CompareTo(n.globalBeat);
return this.globalBeat.CompareTo(n.globalBeat);
}
}
29 changes: 24 additions & 5 deletions Classes/MapEditor/Bookmark.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,36 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Edda {
public class Bookmark {
public class Bookmark : IComparable, IEquatable<Bookmark>
{

public double beat { get; set; }
public string name { get; set; }
public Bookmark(double beat, string name) {
this.beat = beat;
this.name = name;
}

public int CompareTo(object obj)
{
if (!(obj is Bookmark b))
{
throw new Exception();
}
if (this.Equals(b))
{
return 0;
}
if (Helper.DoubleApproxGreater(this.beat, b.beat))
{
return 1;
}
return -1;
}

public bool Equals(Bookmark b)
{
return Helper.DoubleApproxEqual(b.beat, this.beat);
}
}
}
2 changes: 1 addition & 1 deletion Classes/MapEditor/EditManager/EditList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public EditList(List<Edit<T>> items) {
public EditList() {
this.items = new List<Edit<T>>();
}
public EditList(bool isAdding, List<T> items) {
public EditList(bool isAdding, IEnumerable<T> items) {
this.items = new List<Edit<T>>();
foreach (T item in items) {
this.items.Add(new Edit<T>(isAdding, item));
Expand Down
Loading