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

New beast saber #30

Merged
merged 2 commits into from
Mar 20, 2022
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
5 changes: 4 additions & 1 deletion SyncSaber/BeatSaberUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ public class BeatSaberUI : MonoBehaviour
/// <param name="text">The text to be displayed.</param>
/// <param name="anchoredPosition">The position the button should be anchored to.</param>
/// <returns>The newly created TextMeshProUGUI component.</returns>
public static TextMeshProUGUI CreateText(RectTransform parent, string text, Vector2 anchoredPosition) => CreateText(parent, text, anchoredPosition, new Vector2(60f, 10f));
public static TextMeshProUGUI CreateText(RectTransform parent, string text, Vector2 anchoredPosition)
{
return CreateText(parent, text, anchoredPosition, new Vector2(60f, 10f));
}

/// <summary>
/// Creates a TextMeshProUGUI component.
Expand Down
3 changes: 1 addition & 2 deletions SyncSaber/Installers/SyncSaberInstaller.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using SiraUtil;
using SyncSaber.Views;
using SyncSaber.Views;
using Zenject;

namespace SyncSaber.Installers
Expand Down
10 changes: 7 additions & 3 deletions SyncSaber/NetWorks/WebClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ internal static async Task<WebResponse> SendAsync(HttpMethod methodType, string
} while (resp?.StatusCode != HttpStatusCode.NotFound && resp?.IsSuccessStatusCode != true && retryCount <= RETRY_COUNT);


if (token.IsCancellationRequested) throw new TaskCanceledException();
if (token.IsCancellationRequested) {
throw new TaskCanceledException();
}

using (var memoryStream = new MemoryStream())
using (var stream = await resp.Content.ReadAsStreamAsync().ConfigureAwait(false)) {
Expand All @@ -111,10 +113,12 @@ internal static async Task<WebResponse> SendAsync(HttpMethod methodType, string
progress?.Report(0);

while ((bytesRead = await stream.ReadAsync(buffer, 0, buffer.Length).ConfigureAwait(false)) > 0) {
if (token.IsCancellationRequested) throw new TaskCanceledException();
if (token.IsCancellationRequested) {
throw new TaskCanceledException();
}

if (contentLength != null) {
progress?.Report((double)totalRead / (double)contentLength);
progress?.Report(totalRead / (double)contentLength);
}

await memoryStream.WriteAsync(buffer, 0, bytesRead).ConfigureAwait(false);
Expand Down
17 changes: 14 additions & 3 deletions SyncSaber/NetWorks/WebResponce.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,19 @@ internal WebResponse(HttpResponseMessage resp, byte[] body)
this._content = body;
}

public byte[] ContentToBytes() => this._content;
public string ContentToString() => Encoding.UTF8.GetString(this._content);
public JSONNode ConvertToJsonNode() => JSONNode.Parse(this.ContentToString());
public byte[] ContentToBytes()
{
return this._content;
}

public string ContentToString()
{
return Encoding.UTF8.GetString(this._content);
}

public JSONNode ConvertToJsonNode()
{
return JSONNode.Parse(this.ContentToString());
}
}
}
15 changes: 12 additions & 3 deletions SyncSaber/Playlist.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,10 @@ public static void WritePlaylist(Playlist playlist)

playlistNode.Add("fileLoc", new JSONString("1"));

if (!Directory.Exists("Playlists")) Directory.CreateDirectory("Playlists");
if (!Directory.Exists("Playlists")) {
Directory.CreateDirectory("Playlists");
}

File.WriteAllText($"Playlists\\{playlist.fileName}{(playlist.oldFormat ? ".json" : ".bplist")}", playlistNode.ToString());
}
}
Expand Down Expand Up @@ -103,9 +106,15 @@ public Playlist(string playlistFileName, string playlistTitle, string playlistAu
this.ReadPlaylist();
}

public void Add(string hash, string songName) => this.Songs.Add(new PlaylistSong(hash, songName));
public void Add(string hash, string songName)
{
this.Songs.Add(new PlaylistSong(hash, songName));
}

public void WritePlaylist() => PlaylistIO.WritePlaylist(this);
public void WritePlaylist()
{
PlaylistIO.WritePlaylist(this);
}

public bool ReadPlaylist()
{
Expand Down
5 changes: 4 additions & 1 deletion SyncSaber/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ public void OnApplicationQuit()
BSEvents.earlyMenuSceneLoadedFresh -= this.BSEvents_earlyMenuSceneLoadedFresh;
}

private void SceneManagerOnActiveSceneChanged(Scene arg0, Scene scene) => this.IsInGame = scene.name == "GameCore";
private void SceneManagerOnActiveSceneChanged(Scene arg0, Scene scene)
{
this.IsInGame = scene.name == "GameCore";
}
}
}
1 change: 0 additions & 1 deletion SyncSaber/ScoreSabers/ScoreSaberManager.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using SyncSaber.NetWorks;
using SyncSaber.SimpleJSON;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;

Expand Down
Loading