Skip to content

Commit

Permalink
Add beatmap.color
Browse files Browse the repository at this point in the history
  • Loading branch information
opl- committed Sep 24, 2021
1 parent dccac51 commit f093556
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 0 deletions.
4 changes: 4 additions & 0 deletions BeatSaberHTTPStatus/BeatSaberHTTPStatusPlugin.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@
<HintPath>$(GameDirPath)\Beat Saber_Data\Managed\BGNet.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Colors">
<HintPath>$(GameDirPath)\Beat Saber_Data\Managed\Colors.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Data" />
Expand Down
15 changes: 15 additions & 0 deletions BeatSaberHTTPStatus/GameStatus.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using UnityEngine;

namespace BeatSaberHTTPStatus {
[Serializable]
Expand Down Expand Up @@ -32,6 +33,13 @@ public class GameStatus {
public int maxScore = 0;
public string maxRank = "E";
public string environmentName = null;
public Color? colorSaberA = null;
public Color? colorSaberB = null;
public Color? colorEnvironment0 = null;
public Color? colorEnvironment1 = null;
public Color? colorEnvironmentBoost0 = null;
public Color? colorEnvironmentBoost1 = null;
public Color? colorObstacle = null;

// Performance
public int rawScore = 0;
Expand Down Expand Up @@ -140,6 +148,13 @@ public void ResetMapInfo() {
this.maxScore = 0;
this.maxRank = "E";
this.environmentName = null;
this.colorSaberA = null;
this.colorSaberB = null;
this.colorEnvironment0 = null;
this.colorEnvironment1 = null;
this.colorEnvironmentBoost0 = null;
this.colorEnvironmentBoost1 = null;
this.colorObstacle = null;
}

public void ResetPerformance() {
Expand Down
11 changes: 11 additions & 0 deletions BeatSaberHTTPStatus/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,17 @@ public async void HandleSongStart() {
gameStatus.obstaclesCount = diff.beatmapData.obstaclesCount;
gameStatus.environmentName = level.environmentInfo.sceneInfo.sceneName;

ColorScheme colorScheme = gameplayCoreSceneSetupData.colorScheme ?? new ColorScheme(gameplayCoreSceneSetupData.environmentInfo.colorScheme);
gameStatus.colorSaberA = colorScheme.saberAColor;
gameStatus.colorSaberB = colorScheme.saberBColor;
gameStatus.colorEnvironment0 = colorScheme.environmentColor0;
gameStatus.colorEnvironment1 = colorScheme.environmentColor1;
if (colorScheme.supportsEnvironmentColorBoost) {
gameStatus.colorEnvironmentBoost0 = colorScheme.environmentColor0Boost;
gameStatus.colorEnvironmentBoost1 = colorScheme.environmentColor1Boost;
}
gameStatus.colorObstacle = colorScheme.obstaclesColor;

try {
// From https://support.unity3d.com/hc/en-us/articles/206486626-How-can-I-get-pixels-from-unreadable-textures-
var texture = (await level.GetCoverImageAsync(CancellationToken.None)).texture;
Expand Down
26 changes: 26 additions & 0 deletions BeatSaberHTTPStatus/StatusManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,32 @@ private void UpdateBeatmapJSON() {
beatmapJSON["maxScore"] = gameStatus.maxScore;
beatmapJSON["maxRank"] = gameStatus.maxRank;
beatmapJSON["environmentName"] = gameStatus.environmentName;

if (beatmapJSON["color"] == null) beatmapJSON["color"] = new JSONObject();
JSONObject colorJSON = (JSONObject) beatmapJSON["color"];

UpdateColor(gameStatus.colorSaberA, colorJSON, "saberA");
UpdateColor(gameStatus.colorSaberB, colorJSON, "saberB");
UpdateColor(gameStatus.colorEnvironment0, colorJSON, "environment0");
UpdateColor(gameStatus.colorEnvironment1, colorJSON, "environment1");
UpdateColor(gameStatus.colorEnvironmentBoost0, colorJSON, "environment0Boost");
UpdateColor(gameStatus.colorEnvironmentBoost1, colorJSON, "environment1Boost");
UpdateColor(gameStatus.colorObstacle, colorJSON, "obstacle");
}

private void UpdateColor(Color? color, JSONObject parent, String key) {
if (color == null) {
parent[key] = JSONNull.CreateOrGet();
return;
}

var arr = parent[key] as JSONArray ?? new JSONArray();

arr[0] = Mathf.RoundToInt(((Color) color).r * 255);
arr[1] = Mathf.RoundToInt(((Color) color).g * 255);
arr[2] = Mathf.RoundToInt(((Color) color).b * 255);

parent[key] = arr;
}

private void UpdatePerformanceJSON() {
Expand Down
9 changes: 9 additions & 0 deletions protocol.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,15 @@ StatusObject = {
"maxScore": Integer, // Max score obtainable on the map with modifier multiplier
"maxRank": "SSS" | "SS" | "S" | "A" | "B" | "C" | "D" | "E", // Max rank obtainable using current modifiers
"environmentName": String, // Name of the environment this beatmap requested // TODO: list available names
"color": { // Contains colors used by this environment. If overrides were set by the player, they replace the values provided by the environment. SongCore may override the colors based on beatmap settings, including player overrides. Each color is stored as an array of three integers in the range [0..255] representing the red, green, and blue values in order.
"saberA": [Integer, Integer, Integer], // Color of the left saber and its notes
"saberB": [Integer, Integer, Integer], // Color of the right saber and its notes
"environment0": [Integer, Integer, Integer], // First environment color
"environment1": [Integer, Integer, Integer], // Second environment color
"environment0Boost": null | [Integer, Integer, Integer], // First environment boost color. If a boost color isn't set, this property will be `null`, and the value of `environment0` should be used instead.
"environment1Boost": null | [Integer, Integer, Integer], // Second environment boost color. If a boost color isn't set, this property will be `null`, and the value of `environment1` should be used instead.
"obstacle": [Integer, Integer, Integer], // Color of obstacles
},
},
"performance": null | {
"rawScore": Integer, // Current score without the modifier multiplier
Expand Down

0 comments on commit f093556

Please sign in to comment.