Skip to content

Commit 473f9f9

Browse files
author
Conti
committed
bugfixes, preparation for music fest
1 parent 864adc1 commit 473f9f9

8 files changed

Lines changed: 122 additions & 42 deletions

File tree

ApiController.cs

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@ public static class ApiController
1616
{
1717
private static float brightness = RenderSettings.skybox.GetFloat("_Exposure") * 255f;
1818
private static float red, green, blue = 255f;
19+
private static string eventName = "";
1920
public static bool isRunning = false;
20-
public static async void PostAsync(float _red, float _green, float _blue, float _brightness)
21+
private static object token = null;
22+
public static async void PostAsync(float _red, float _green, float _blue, float _brightness, string _eventName)
2123
{
22-
string json = $"{{\"red\": {_red}, \"green\": {_green}, \"blue\": {_blue}, \"bright\": {_brightness}}}";
24+
string json = $"{{\"red\": {_red}, \"green\": {_green}, \"blue\": {_blue}, \"bright\": {_brightness}, \"event\": \"{_eventName}\"}}";
2325
try
2426
{
2527
HttpClient client = new HttpClient();
@@ -31,14 +33,16 @@ await client.PostAsync(
3133
{
3234
MelonLogger.Msg(ex.InnerException.Message);
3335
}
34-
3536
}
3637

3738
public static IEnumerator StartPost()
3839
{
3940
while (isRunning)
4041
{
41-
PostAsync(red, green, blue, brightness);
42+
if(InGameUI.I.mState != InGameUI.State.PausePage)
43+
{
44+
PostAsync(red, green, blue, brightness, eventName);
45+
}
4246
yield return new WaitForSecondsRealtime(.04f);
4347
}
4448
}
@@ -47,7 +51,8 @@ private static void Start()
4751
{
4852
isRunning = true;
4953
brightness = RenderSettings.skybox.GetFloat("_Exposure") * 255f;
50-
MelonCoroutines.Start(StartPost());
54+
eventName = "";
55+
token = MelonCoroutines.Start(StartPost());
5156
}
5257

5358
public static void SetBrightness(float _brightness)
@@ -72,13 +77,28 @@ public static void SetColor(Color color)
7277
}
7378
}
7479

80+
public static void SetEvent(string _event)
81+
{
82+
if (!Config.postToApi) return;
83+
eventName = _event;
84+
if (!isRunning)
85+
{
86+
Start();
87+
}
88+
}
89+
7590
public static void TurnOff()
7691
{
7792
if (!Config.postToApi) return;
7893
brightness = 0f;
94+
red = 255f;
95+
green = 255f;
96+
blue = 255;
7997
red = green = blue = 255f;
98+
eventName = "";
8099
isRunning = false;
81-
PostAsync(red, green, blue, brightness);
100+
MelonCoroutines.Stop(token);
101+
PostAsync(red, green, blue, brightness, eventName);
82102
}
83103
}
84104
}

src/AuthorableModifiers.cs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public class AuthorableModifiersMod : MelonMod
2121
public static List<Modifier> singleUseModifiers = new List<Modifier>();
2222
public static Dictionary<int, float> oldOffsetDict = new Dictionary<int, float>();
2323
public static string audicaFilePath = "";
24-
public static bool modifiersFound = false;
24+
public static bool modifiersFound { get; set; } = false;
2525

2626
public static Vector3 debugTextPosition = new Vector3(0f, 8f, 8f);
2727

@@ -43,12 +43,13 @@ public class AuthorableModifiersMod : MelonMod
4343

4444
public static Dictionary<float, DebugTextPopup> popupTextDictionary = new Dictionary<float, DebugTextPopup>();
4545
public static bool lightshowWasEnabled = false;
46+
public static Vector3 lastRotationEndValue = Vector3.zero;
4647
public static class BuildInfo
4748
{
4849
public const string Name = "AuthorableModifiers"; // Name of the Mod. (MUST BE SET)
4950
public const string Author = "Continuum"; // Author of the Mod. (Set as null if none)
5051
public const string Company = null; // Company that made the Mod. (Set as null if none)
51-
public const string Version = "1.2.6"; // Version of the Mod. (MUST BE SET)
52+
public const string Version = "1.2.7"; // Version of the Mod. (MUST BE SET)
5253
public const string DownloadLink = null; // Download Link for the Mod. (Set as null if none)
5354
}
5455

@@ -113,6 +114,7 @@ public static void LoadModifierCues(bool fromRestart = false)
113114
modifiersLoaded = true;
114115
return;
115116
}
117+
if(fromRestart) AudioDriver.I.Pause();
116118
awaitEnableModifiers = Decoder.GetModifierCues(audicaFilePath);
117119

118120
if (awaitEnableModifiers is null || (awaitEnableModifiers.Count == 0 && preloadModifiers.Count == 0 && zOffsetList.Count == 0))
@@ -124,6 +126,7 @@ public static void LoadModifierCues(bool fromRestart = false)
124126
{
125127
ResetArena(true);
126128
}
129+
if (fromRestart) AudioDriver.I.Resume();
127130
return;
128131
}
129132
SetOldColors(KataConfig.I.leftHandColor, KataConfig.I.rightHandColor);
@@ -157,18 +160,20 @@ public static void LoadModifierCues(bool fromRestart = false)
157160
MelonCoroutines.Start(IWaitForArenaLoad("<color=\"red\">WARNING</color>\nMay contain flashing lights and rotating arenas. \nThis can be disabled in Mod Settings.", .001f));
158161
//if (endless) MelonCoroutines.Start(StartTimer());
159162
//else modifiersLoaded = true;
160-
MelonCoroutines.Start(WaitForArenaSwitch());
163+
MelonCoroutines.Start(WaitForArenaSwitch(fromRestart));
161164
//modifiersLoaded = true;
162165
}
163166

164-
private static IEnumerator WaitForArenaSwitch()
167+
168+
private static IEnumerator WaitForArenaSwitch(bool fromRestart)
165169
{
166170
while (EnvironmentLoader.I.IsSwitching())
167171
{
168172
yield return new WaitForSecondsRealtime(.2f);
169173
}
170174
modifiersLoaded = true;
171175
defaultSkyboxColor = RenderSettings.skybox.GetColor("_Tint");
176+
if (fromRestart) AudioDriver.I.Resume();
172177
}
173178

174179
private static void EnableAutoLightshow(bool enable)
@@ -390,10 +395,21 @@ private static IEnumerator IResetArenaValues(bool resetToUserValues)
390395
RenderSettings.skybox.SetFloat("_Rotation", rotation);
391396
ArenaLoaderMod.CurrentSkyboxReflection = 0f;
392397
ArenaLoaderMod.ChangeReflectionStrength(reflection);
398+
RenderSettings.skybox.SetColor("_Tint", defaultSkyboxColor);
393399
}
394400

395401
public override void OnUpdate()
396402
{
403+
/*if (Input.GetKeyDown(KeyCode.L))
404+
{
405+
AutoPlayer.EnableAutoplayer(!AutoPlayer.I.IsAutoPlayerEnabled);
406+
MelonLogger.Msg("Auto player is " + (AutoPlayer.I.IsAutoPlayerEnabled ? "enabled" : "disabled"));
407+
408+
}
409+
if (Input.GetKeyDown(KeyCode.P) && MenuState.sState == MenuState.State.Launched)
410+
{
411+
InGameUI.I.GoToPausePage(true);
412+
}*/
397413
/*if (Input.GetKeyDown(KeyCode.L))
398414
{
399415
ApiController.isRunning = true;

src/Config.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,6 @@ public static void OnPreferencesSaved()
5353
else if (fieldInfo.FieldType == typeof(float)) fieldInfo.SetValue(null, MelonPreferences.GetEntryValue<float>(Category, fieldInfo.Name));
5454
else if (fieldInfo.FieldType == typeof(string)) fieldInfo.SetValue(null, MelonPreferences.GetEntryValue<string>(Category, fieldInfo.Name));
5555
}
56-
57-
AuthorableModifiersMod.modifiersFound = false;
5856
}
5957
}
6058
}

src/Decoder.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -418,8 +418,8 @@ public static List<Modifier> GetModifierCues(string audicaFilePath)
418418
AmountY = yOffset,
419419
AmountZ = zOffset,
420420
Reset = option1,
421-
Preload = option2
422-
421+
Preload = option2,
422+
ShortestRoute = independantBool
423423
};
424424
/*modifierCue = new ArenaScale(type,
425425
modifiersJSON["modifiers"][i]["startTick"],
@@ -433,8 +433,9 @@ public static List<Modifier> GetModifierCues(string audicaFilePath)
433433
preload = option2;
434434
break;
435435
case ModifierType.SkyboxColor:
436-
if (!Config.enableSkyboxColorChange) continue;
436+
if (!Config.enableSkyboxColorChange || !Integrations.arenaLoaderFound) continue;
437437
modifierCue = new SkyboxColor(type,
438+
amount,
438439
startTick,
439440
endTick,
440441
leftHandColor.r,

src/Hooks.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ private static class PatchShowPage
6767
{
6868
private static void Postfix(OptionsMenu __instance, OptionsMenu.Page page)
6969
{
70-
if (page == OptionsMenu.Page.Main)
70+
if (page == OptionsMenu.Page.Main && !AuthorableModifiersMod.modifiersFound)
7171
AuthorableModifiersMod.SetUserBrightness(RenderSettings.skybox.GetFloat("_Exposure"), RenderSettings.skybox.GetFloat("_Rotation"), RenderSettings.reflectionIntensity);
7272
}
7373
}
@@ -79,6 +79,7 @@ private static void Postfix(MenuState __instance, MenuState.State state)
7979
{
8080
if(state == MenuState.State.SongPage)
8181
{
82+
8283
AuthorableModifiersMod.SetEndlessActive(false);
8384
}
8485
}

src/Modifiers/ArenaManipulation.cs

Lines changed: 47 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public class ArenaManipulation : Modifier
2323
//private Quaternion currentRotation;
2424
public bool Preload { get; set; }
2525
public bool Reset { get; set; }
26+
public bool ShortestRoute { get; set; }
2627
/*protected ArenaManipulation(ModifierType _type, float _startTick, float _endTick, string _amountX, string _amountY, string _amountZ, bool _reset, bool _preload)
2728
{
2829
Type = _type;
@@ -48,14 +49,14 @@ public override void Activate()
4849
//MelonLogger.Msg("Target " + Type.ToString() + ": " + targetAmount.x + "/" + targetAmount.y + "/" + targetAmount.z);
4950
if (Preload)
5051
{
51-
SetAmount(targetAmount);
52+
SetAmount(targetAmount, true);
5253
}
5354
else
5455
{
5556
base.Activate();
5657
if (EndTick == StartTick || EndTick == 0)
5758
{
58-
SetAmount(targetAmount);
59+
SetAmount(targetAmount, true);
5960
}
6061
else
6162
{
@@ -140,16 +141,18 @@ private void GetTargetAmount()
140141
targetAmount.z = currentAmount.z;
141142
}
142143

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-
}
144+
145+
//if (Type != ModifierType.ArenaScale) targetAmount += currentAmount;
146+
}
147+
if (Type == ModifierType.ArenaSpin)
148+
{
149+
float tickSpan = EndTick - StartTick;
150+
if (Reset || EndTick == 0 || StartTick == EndTick) tickSpan = 1;
151+
//amountPerTick = new Vector3(Mathf.DeltaAngle(currentAmount.x, targetAmount.x), Mathf.DeltaAngle(currentAmount.y, targetAmount.y), Mathf.DeltaAngle(currentAmount.z, targetAmount.z));
152+
//amountPerTick /= tickSpan;
153+
amountPerTick = (targetAmount - currentAmount) / tickSpan;
154+
//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})");
155+
lastTick = StartTick;
153156
}
154157
}
155158
private Vector3 amountPerTick = new Vector3();
@@ -168,6 +171,7 @@ protected Vector3 GetAmount(float percentage)
168171
amnt.y = CalculateAmount(currentAmount.y, targetAmount.y, percentage);
169172
amnt.z = CalculateAmount(currentAmount.z, targetAmount.z, percentage);
170173
}*/
174+
171175
amnt.x = CalculateAmount(currentAmount.x, targetAmount.x, percentage);
172176
amnt.y = CalculateAmount(currentAmount.y, targetAmount.y, percentage);
173177
amnt.z = CalculateAmount(currentAmount.z, targetAmount.z, percentage);
@@ -194,16 +198,18 @@ private IEnumerator DoManipulation()
194198
{
195199
float percentage = ((AudioDriver.I.mCachedTick - StartTick) * 100f) / (EndTick - StartTick);
196200
percentage /= 100f;
197-
SetAmount(GetAmount(percentage));
201+
SetAmount(GetAmount(percentage), false, percentage);
202+
if(Type == ModifierType.ArenaSpin)
203+
{
204+
//world.rotation = Quaternion.Lerp(Quaternion.Euler(currentAmount), Quaternion.Euler(targetAmount), percentage);
205+
206+
}
198207
yield return new WaitForSecondsRealtime(Time.unscaledDeltaTime);
199208
}
200209
//if (Type == ModifierType.ArenaSpin) SetAmount(targetRotation);
201-
SetAmount(targetAmount);
210+
SetAmount(targetAmount, true);
202211
}
203212

204-
205-
206-
207213
private float CalculateAmount(float current, float target, float percentage)
208214
{
209215
//if(Type == ModifierType.ArenaSpin) target = target * target * (3f - 2f * target); //test this
@@ -216,7 +222,7 @@ private float CalculateAmount(float current, float target, float percentage)
216222
world.transform.rotation = rot;
217223
}*/
218224

219-
private void SetAmount(Vector3 _amount)
225+
private void SetAmount(Vector3 _amount, bool instant, float percentage = 100f)
220226
{
221227
switch (Type)
222228
{
@@ -227,9 +233,9 @@ private void SetAmount(Vector3 _amount)
227233
world.transform.localScale = _amount;
228234
break;
229235
case ModifierType.ArenaSpin:
230-
/*float currentTick = AudioDriver.I.mCachedTick;
236+
float currentTick = AudioDriver.I.mCachedTick;
231237
float numTicksPassed = currentTick - lastTick;
232-
lastTick = currentTick;*/
238+
lastTick = currentTick;
233239

234240
/*world.Rotate(Vector3.right, amountPerTick.x * numTicksPassed);
235241
world.Rotate(Vector3.up, amountPerTick.y * numTicksPassed);
@@ -239,14 +245,31 @@ private void SetAmount(Vector3 _amount)
239245
/*world.rotation *= Quaternion.AngleAxis(amountPerTick.x * numTicksPassed, Vector3.right);
240246
world.rotation *= Quaternion.AngleAxis(amountPerTick.y * numTicksPassed, Vector3.up);
241247
world.rotation *= Quaternion.AngleAxis(amountPerTick.z * numTicksPassed, Vector3.forward);*/
242-
/*
243-
world.transform.rotation *= Quaternion.AngleAxis(_amount.x, Vector3.right);
248+
249+
/*world.transform.rotation *= Quaternion.AngleAxis(_amount.x, Vector3.right);
244250
world.transform.rotation *= Quaternion.AngleAxis(_amount.y, Vector3.up);
245251
world.transform.rotation *= Quaternion.AngleAxis(_amount.z, Vector3.forward);
246252
*/
253+
/*if (instant) world.rotation = Quaternion.Euler(_amount);
254+
else
255+
{
256+
257+
}*/
258+
if (Reset && instant) world.rotation = Quaternion.identity;
259+
else
260+
{
261+
if(ShortestRoute) world.rotation = Quaternion.Lerp(Quaternion.Euler(currentAmount), Quaternion.Euler(targetAmount), percentage);
262+
else world.rotation = Quaternion.Euler(_amount);
263+
}
247264

248-
//world.eulerAngles = _amount;
249-
world.rotation = Quaternion.Euler(_amount);
265+
266+
/*world.rotation *= Quaternion.AngleAxis(amountPerTick.x * numTicksPassed, Vector3.right);
267+
world.rotation *= Quaternion.AngleAxis(amountPerTick.y * numTicksPassed, Vector3.up);
268+
world.rotation *= Quaternion.AngleAxis(amountPerTick.z * numTicksPassed, Vector3.forward);*/
269+
270+
271+
//world.rotation = Quaternion.Euler(_amount);
272+
//MelonLogger.Msg(world.rotation.x + " " + world.rotation.y + " " + world.rotation.z);
250273
//world.localRotation = Quaternion.Euler(_amount);
251274
break;
252275
default:

src/Modifiers/SkyboxColor.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,17 @@ public class SkyboxColor : Modifier
1818
private bool isDefaultEnvironment = false;
1919
private bool reset;
2020
private Color defaultColor;
21-
public SkyboxColor(ModifierType _type, float _startTick, float _endTick, float r, float g, float b, bool _reset)
21+
public SkyboxColor(ModifierType _type, float _amount, float _startTick, float _endTick, float r, float g, float b, bool _reset)
2222
{
23+
if (_amount == 0f) _amount = 1f;
24+
Amount = _amount;
2325
Type = _type;
2426
StartTick = _startTick;
2527
EndTick = _endTick;
2628
reset = _reset;
29+
r *= Amount;
30+
g *= Amount;
31+
b *= Amount;
2732
targetColor = new Color(r, g, b, defaultColor.a);
2833

2934
//if (!PlayerPreferences.I.Environment.Get().ToLower().Contains("environment")) targetColor *= .7f;

0 commit comments

Comments
 (0)