Skip to content

Commit 762f24c

Browse files
author
Conti
committed
added ApiController for LED syncing, added skybox color
1 parent 6b330ac commit 762f24c

6 files changed

Lines changed: 117 additions & 41 deletions

File tree

ApiController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public static async void PostAsync(float _red, float _green, float _blue, float
2424
{
2525
HttpClient client = new HttpClient();
2626
await client.PostAsync(
27-
"http://192.168.1.76/led",
27+
Config.apiUrl,
2828
new StringContent(json, Encoding.UTF8, "application/json"));
2929
}
3030
catch(HttpRequestException ex)

src/AuthorableModifiers.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,10 @@ public class AuthorableModifiersMod : MelonMod
3737
public static float userArenaBrightness = .5f;
3838
public static float userArenaReflection = 1f;
3939
public static float userArenaRotation = 0f;
40-
4140
public static bool endless = false;
4241

42+
public static Color defaultSkyboxColor = new Color();
43+
4344
public static Dictionary<float, DebugTextPopup> popupTextDictionary = new Dictionary<float, DebugTextPopup>();
4445
public static bool lightshowWasEnabled = false;
4546
public static class BuildInfo
@@ -167,6 +168,7 @@ private static IEnumerator WaitForArenaSwitch()
167168
yield return new WaitForSecondsRealtime(.2f);
168169
}
169170
modifiersLoaded = true;
171+
defaultSkyboxColor = RenderSettings.skybox.GetColor("_Tint");
170172
}
171173

172174
private static void EnableAutoLightshow(bool enable)
@@ -351,7 +353,7 @@ private static void ResetValues(bool fromBack = false)
351353

352354
private static void ResetArena(bool forceReset = false)
353355
{
354-
RenderSettings.skybox.SetColor("_Tint", new Color(1f, 1f, 1f, 1f));
356+
RenderSettings.skybox.SetColor("_Tint", defaultSkyboxColor);
355357
ApiController.TurnOff();
356358
SkyboxControl skyboxControl = GameObject.FindObjectOfType<SkyboxControl>();
357359
if (skyboxControl != null) skyboxControl.enabled = true;
@@ -397,8 +399,8 @@ public override void OnUpdate()
397399
ApiController.isRunning = true;
398400
MelonCoroutines.Start(ApiController.StartPost());
399401
//ApiController.PostAsync(255, 255, 255, 255);
400-
}*/
401-
/*if (Input.GetKeyDown(KeyCode.L))
402+
}
403+
if (Input.GetKeyDown(KeyCode.L))
402404
{
403405
AutoPlayer.EnableAutoplayer(!AutoPlayer.I.IsAutoPlayerEnabled);
404406
MelonLogger.Msg("Auto player is " + (AutoPlayer.I.IsAutoPlayerEnabled ? "enabled" : "disabled"));

src/Config.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ public static class Config
2020
public static string lightingTitle = "[Header]Lighting Options";
2121
public static float intensity;
2222

23-
public static string apiTitle = "[Header]Lights Api Options";
2423
public static bool postToApi;
2524
public static string apiUrl;
2625

@@ -36,10 +35,9 @@ public static void RegisterConfig()
3635
MelonPreferences.CreateEntry(Category, nameof(enableSkyboxColorChange), true, "Allows maps to use Skybox Color Changes.");
3736
MelonPreferences.CreateEntry(Category, nameof(hideWarning), false, "Hides the warning before starting a song.");
3837

39-
MelonPreferences.CreateEntry(Category, nameof(lightingTitle), "", lightingTitle);
38+
MelonPreferences.CreateEntry(Category, nameof(lightingTitle), "", "[Header]Lighting Options");
4039
MelonPreferences.CreateEntry(Category, nameof(intensity), 1f, "Controls how intense lighting modifiers are. [0.1, 1, 0.1, 1]{P}");
4140

42-
MelonPreferences.CreateEntry(Category, nameof(apiTitle), "", apiTitle);
4341
MelonPreferences.CreateEntry(Category, nameof(postToApi), false, "Posts Brightness and Color data to specified URL in apiUrl");
4442
MelonPreferences.CreateEntry(Category, nameof(apiUrl), "", apiUrl);
4543

src/Decoder.cs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -435,12 +435,16 @@ public static List<Modifier> GetModifierCues(string audicaFilePath)
435435
case ModifierType.SkyboxColor:
436436
if (!Config.enableSkyboxColorChange) continue;
437437
modifierCue = new SkyboxColor(type,
438-
modifiersJSON["modifiers"][i]["startTick"],
439-
modifiersJSON["modifiers"][i]["endTick"],
440-
modifiersJSON["modifiers"][i]["leftHandColor"][0],
441-
modifiersJSON["modifiers"][i]["leftHandColor"][1],
442-
modifiersJSON["modifiers"][i]["leftHandColor"][2],
443-
modifiersJSON["modifiers"][i]["option2"]);
438+
startTick,
439+
endTick,
440+
leftHandColor.r,
441+
leftHandColor.g,
442+
leftHandColor.b,
443+
option2);
444+
if(startTick == endTick || endTick == 0)
445+
{
446+
modifierCue.IsSingleUse = true;
447+
}
444448
break;
445449
default:
446450
break;

src/Modifiers/ArenaManipulation.cs

Lines changed: 82 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public override void Activate()
4545
if (world is null) return;
4646
GetCurrentAmount();
4747
GetTargetAmount();
48-
48+
//MelonLogger.Msg("Target " + Type.ToString() + ": " + targetAmount.x + "/" + targetAmount.y + "/" + targetAmount.z);
4949
if (Preload)
5050
{
5151
SetAmount(targetAmount);
@@ -77,6 +77,7 @@ private void GetCurrentAmount()
7777
currentAmount = world.position;
7878
break;
7979
case ModifierType.ArenaScale:
80+
//currentAmount = world.localScale;
8081
currentAmount = world.localScale;
8182
break;
8283
case ModifierType.ArenaSpin:
@@ -96,49 +97,88 @@ private void GetTargetAmount()
9697
}
9798
else
9899
{
99-
100-
if (float.TryParse(AmountX, out float _x))
100+
if(AmountX == "")
101+
{
102+
targetAmount.x = currentAmount.x;
103+
}
104+
else if (float.TryParse(AmountX, out float _x))
101105
{
102-
targetAmount.x = _x + currentAmount.x;
106+
//targetAmount.x = _x + (Type == ModifierType.ArenaScale ? 0f : currentAmount.x);
107+
targetAmount.x = _x;
103108
//parsedX = _x;
104109
}
105110
else
106111
{
107112
targetAmount.x = currentAmount.x;
108113
}
109-
if (float.TryParse(AmountY, out float _y))
114+
if (AmountY == "")
115+
{
116+
targetAmount.y = currentAmount.y;
117+
}
118+
else if (float.TryParse(AmountY, out float _y))
110119
{
111-
targetAmount.y = _y + currentAmount.y;
120+
//targetAmount.y = _y + (Type == ModifierType.ArenaScale ? 0f : currentAmount.y);
121+
targetAmount.y = _y;
112122
//parsedY = _y;
113123
}
114124
else
115125
{
116126
targetAmount.y = currentAmount.y;
117127
}
118-
if (float.TryParse(AmountZ, out float _z))
128+
if (AmountZ == "")
119129
{
120-
targetAmount.z = _z + currentAmount.z;
130+
targetAmount.z = currentAmount.z;
131+
}
132+
else if (float.TryParse(AmountZ, out float _z))
133+
{
134+
//targetAmount.z = _z + (Type == ModifierType.ArenaScale ? 0f : currentAmount.z);
135+
targetAmount.z = _z;
121136
//parsedZ = _z;
122137
}
123138
else
124139
{
125140
targetAmount.z = currentAmount.z;
126141
}
127142

128-
//if (type == ModifierType.ArenaSpin) targetRotation = Quaternion.Euler(targetAmount);
143+
if(Type == ModifierType.ArenaSpin)
144+
{
145+
float tickSpan = EndTick - StartTick;
146+
if (Reset) tickSpan = 1;
147+
amountPerTick = new Vector3(Mathf.DeltaAngle(currentAmount.x, targetAmount.x), Mathf.DeltaAngle(currentAmount.y, targetAmount.y), Mathf.DeltaAngle(currentAmount.z, targetAmount.z));
148+
amountPerTick /= tickSpan;
149+
//amountPerTick = (targetAmount - currentAmount) / tickSpan;
150+
//MelonLogger.Msg($"{amountPerTick.x}/{amountPerTick.y}/{amountPerTick.z} over {tickSpan} ticks (Target: {targetAmount.x}/{targetAmount.y}/{targetAmount.z} || Calculated: {amountPerTick.x * tickSpan}/{amountPerTick.y * tickSpan}/{amountPerTick.z * tickSpan})");
151+
lastTick = StartTick;
152+
}
129153
}
130154
}
131-
155+
private Vector3 amountPerTick = new Vector3();
156+
private float lastTick;
132157
protected Vector3 GetAmount(float percentage)
133158
{
134159

135160
Vector3 amnt;
161+
/*if(Type == ModifierType.ArenaSpin)
162+
{
163+
amnt = Quaternion.Euler(CalculateRotation(currentAmount, targetAmount, percentage)).eulerAngles;
164+
}
165+
else
166+
{
167+
amnt.x = CalculateAmount(currentAmount.x, targetAmount.x, percentage);
168+
amnt.y = CalculateAmount(currentAmount.y, targetAmount.y, percentage);
169+
amnt.z = CalculateAmount(currentAmount.z, targetAmount.z, percentage);
170+
}*/
136171
amnt.x = CalculateAmount(currentAmount.x, targetAmount.x, percentage);
137172
amnt.y = CalculateAmount(currentAmount.y, targetAmount.y, percentage);
138173
amnt.z = CalculateAmount(currentAmount.z, targetAmount.z, percentage);
139174
return amnt;
140175
}
141176

177+
protected Vector3 CalculateRotation(Vector3 current, Vector3 target, float percentage)
178+
{
179+
return Vector3.Lerp(current, target, percentage);
180+
}
181+
142182
/*protected Vector3 GetRotation(float percentage)
143183
{
144184
float seconds = AudioDriver.TickSpanToMs(SongDataHolder.I.songData, StartTick, EndTick);
@@ -154,17 +194,20 @@ private IEnumerator DoManipulation()
154194
{
155195
float percentage = ((AudioDriver.I.mCachedTick - StartTick) * 100f) / (EndTick - StartTick);
156196
percentage /= 100f;
157-
if (Type == ModifierType.ArenaSpin) SetAmount(GetAmount(percentage));
158-
else SetAmount(GetAmount(percentage));
159-
197+
SetAmount(GetAmount(percentage));
160198
yield return new WaitForSecondsRealtime(Time.unscaledDeltaTime);
161199
}
200+
//if (Type == ModifierType.ArenaSpin) SetAmount(targetRotation);
162201
SetAmount(targetAmount);
163202
}
164203

204+
205+
206+
165207
private float CalculateAmount(float current, float target, float percentage)
166208
{
167-
target = target * target * (3f - 2f * target); //test this
209+
//if(Type == ModifierType.ArenaSpin) target = target * target * (3f - 2f * target); //test this
210+
168211
return Mathf.Lerp(current, target, percentage);
169212
}
170213

@@ -184,16 +227,38 @@ private void SetAmount(Vector3 _amount)
184227
world.transform.localScale = _amount;
185228
break;
186229
case ModifierType.ArenaSpin:
187-
/*world.transform.rotation *= Quaternion.AngleAxis(_amount.x, Vector3.right);
230+
/*float currentTick = AudioDriver.I.mCachedTick;
231+
float numTicksPassed = currentTick - lastTick;
232+
lastTick = currentTick;*/
233+
234+
/*world.Rotate(Vector3.right, amountPerTick.x * numTicksPassed);
235+
world.Rotate(Vector3.up, amountPerTick.y * numTicksPassed);
236+
world.Rotate(Vector3.forward, amountPerTick.z * numTicksPassed);*/
237+
//world.Rotate(amountPerTick * numTicksPassed);
238+
239+
/*world.rotation *= Quaternion.AngleAxis(amountPerTick.x * numTicksPassed, Vector3.right);
240+
world.rotation *= Quaternion.AngleAxis(amountPerTick.y * numTicksPassed, Vector3.up);
241+
world.rotation *= Quaternion.AngleAxis(amountPerTick.z * numTicksPassed, Vector3.forward);*/
242+
/*
243+
world.transform.rotation *= Quaternion.AngleAxis(_amount.x, Vector3.right);
188244
world.transform.rotation *= Quaternion.AngleAxis(_amount.y, Vector3.up);
189-
world.transform.rotation *= Quaternion.AngleAxis(_amount.z, Vector3.forward);*/
190-
world.eulerAngles = _amount;
245+
world.transform.rotation *= Quaternion.AngleAxis(_amount.z, Vector3.forward);
246+
*/
247+
248+
//world.eulerAngles = _amount;
249+
world.rotation = Quaternion.Euler(_amount);
250+
//world.localRotation = Quaternion.Euler(_amount);
191251
break;
192252
default:
193253
break;
194254
}
195255
}
196256

257+
private void SetAmount(Quaternion rotation)
258+
{
259+
world.rotation = rotation;
260+
}
261+
197262
private void ResetArena()
198263
{
199264
switch (Type)

src/Modifiers/SkyboxColor.cs

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,28 +15,31 @@ public class SkyboxColor : Modifier
1515
private Color targetColor;
1616
//private Color originalColor = new Color(0f, 0f, 0f);
1717
private Color oldColor;
18+
private bool isDefaultEnvironment = false;
19+
private bool reset;
20+
private Color defaultColor;
1821
public SkyboxColor(ModifierType _type, float _startTick, float _endTick, float r, float g, float b, bool _reset)
1922
{
2023
Type = _type;
2124
StartTick = _startTick;
2225
EndTick = _endTick;
23-
if (_reset)
24-
{
25-
targetColor = new Color(1f, 1f, 1f);
26-
}
27-
else
28-
{
29-
targetColor = new Color(r, g, b);
30-
}
26+
reset = _reset;
27+
targetColor = new Color(r, g, b, defaultColor.a);
28+
29+
//if (!PlayerPreferences.I.Environment.Get().ToLower().Contains("environment")) targetColor *= .7f;
30+
//if (!PlayerPreferences.I.Environment.Get().ToLower().Contains("environment")) isDefaultEnvironment = true;
3131
}
3232

3333
public override void Activate()
3434
{
35+
//if (reset && IsSingleUse && !isDefaultEnvironment) targetColor = new Color(0f, 0f, 0f, 0f);
36+
defaultColor = AuthorableModifiersMod.defaultSkyboxColor;
37+
if (reset) targetColor = defaultColor;
3538
SkyboxControl skyboxControl = GameObject.FindObjectOfType<SkyboxControl>();
3639
if(skyboxControl != null) skyboxControl.enabled = false;
3740
base.Activate();
3841
oldColor = RenderSettings.skybox.GetColor("_Tint");
39-
if(StartTick == 0 || StartTick == EndTick)
42+
if(IsSingleUse)
4043
{
4144
UpdateColor(targetColor);
4245
}
@@ -63,7 +66,7 @@ private IEnumerator SmoothColorChange()
6366
private void UpdateColor(Color col)
6467
{
6568
RenderSettings.skybox.SetColor("_Tint", col);
66-
//ApiController.SetColor(col);
69+
ApiController.SetColor(col);
6770
}
6871

6972
public override void Deactivate()
@@ -75,6 +78,10 @@ public override void Deactivate()
7578
base.Deactivate();
7679
}
7780

81+
private void ResetColor()
82+
{
83+
if(isDefaultEnvironment && reset) UpdateColor(new Color(0f, 0f, 0f, 0f));
84+
}
7885

7986
}
8087
}

0 commit comments

Comments
 (0)