Skip to content

Commit 8344fcf

Browse files
author
sepfy
committed
- Cleaned up BS variable to be less gross
- Created a MenuCamera setting that can be added to settings file for more control over placement - Default settings file now creates the MenuCamera as well - If no MenuCamera is found, will fall back to an internally generated one - Added MenuCamera to optional settings files - Fixed bug where first camera index gets skipped over in song-specific settings files (where the MenuCamera was before) - Added code to handle less than 3 Cameras in settings file, tested with 1 and 2 - Likely still broken if you only have 2 cameras and they're orbital
1 parent 440c54c commit 8344fcf

File tree

7 files changed

+114
-66
lines changed

7 files changed

+114
-66
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@
33
################################################################################
44

55
/bin
6+
/.vs/FriesBSCam/v16
7+
/obj/x64/Plugin

Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@
2525
// You can specify all the values or you can default the Build and Revision Numbers
2626
// by using the '*' as shown below:
2727
// [assembly: AssemblyVersion("1.0.*")]
28-
[assembly: AssemblyVersion("1.1.3.0")]
29-
[assembly: AssemblyFileVersion("1.1.3.0")]
28+
[assembly: AssemblyVersion("1.2.0.0")]
29+
[assembly: AssemblyFileVersion("1.2.0.0")]

Settings/settings.713E301FC4F774EDF4EA1001A19DD5BF7E3F4CE6.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
GlobalBias='0.0'
2-
Camera={
2+
MenuCamera={
33
Name='MenuCam'
44
Type='LookAt'
55
PositionBinding='playerWaist'
66
PositionOffset={x='2.0', y='1.0', z='-3.0'}
77
LookAt={x='-2.0', y='0.0', z='5.0'}
8-
ActualTime='3.0'
9-
TransitionTime='0.0'
108
}
119
Camera={
1210
Name='DiagonalFrontLeft'

Settings/settings.825DBD980EADCEABA54C8E9D8E68F93A1B4CB029.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
GlobalBias='0.0'
2-
Camera={
2+
MenuCamera={
33
Name='MenuCam'
44
Type='LookAt'
55
PositionBinding='playerWaist'
66
PositionOffset={x='2.0', y='1.0', z='-3.0'}
77
LookAt={x='-2.0', y='0.0', z='5.0'}
8-
ActualTime='3.0'
9-
TransitionTime='0.0'
108
}
119
Camera={
1210
Name='DiagonalFrontRight'

Settings/settings.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
GlobalBias='0.0'
2+
MenuCamera={
3+
Name='MenuCam'
4+
Type='LookAt'
5+
PositionBinding='playerWaist'
6+
PositionOffset={x='2.0', y='1.0', z='-3.0'}
7+
LookAt={x='-2.0', y='0.0', z='5.0'}
8+
}
29
Camera={
310
Name='TopDown'
411
Type='LookAt'

Src/CameraData.cs

Lines changed: 44 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ public static class CameraPluginSettings
6868
public static bool Debug = false;
6969
// public static float BlendSpeed;
7070
public static List<CameraData> CameraDataList;
71+
public static CameraData MenuCamera;
7172

7273
/// <summary>
7374
/// Loads Default Settings File
@@ -86,14 +87,12 @@ public static void LoadSettings()
8687
using (var ws = new StreamWriter(@settingLoc))
8788
{
8889
ws.WriteLine("GlobalBias='0.0'");
89-
ws.WriteLine("Camera={");
90+
ws.WriteLine("MenuCamera={");
9091
ws.WriteLine(" Name='MenuCamera'");
9192
ws.WriteLine(" Type='LookAt'");
9293
ws.WriteLine(" PositionBinding='playerWaist'");
9394
ws.WriteLine(" PositionOffset={x='2.0', y='1.0', z='-3.0'} ");
9495
ws.WriteLine(" LookAt={x='-2.0', y='0.0', z='5.0'} ");
95-
ws.WriteLine(" MinTime='4.0' ");
96-
ws.WriteLine(" MaxTime='8.0' ");
9796
ws.WriteLine("}");
9897
ws.WriteLine("Camera={");
9998
ws.WriteLine(" Name='TopRight'");
@@ -179,6 +178,7 @@ public static void LoadSettings()
179178
}
180179
}
181180

181+
MenuCamera = new CameraData();
182182
CameraDataList = new List<CameraData>();
183183
ParseSettingsFile(@settingLoc);
184184
SongSpecific = false;
@@ -198,6 +198,7 @@ public static void LoadSettings(string settingsFile)
198198
// Check to see if the file exists.
199199
if (File.Exists(@settingLoc))
200200
{
201+
MenuCamera = new CameraData();
201202
CameraDataList = new List<CameraData>();
202203
ParseSettingsFile(@settingLoc);
203204
SongSpecific = true;
@@ -220,31 +221,55 @@ public static void ParseSettingsFile(string fileName)
220221

221222
GlobalBias = ParseFloat(root.GetChildSafe("GlobalBias"));
222223
Debug = ParseBool(root.GetChildSafe("Debug"));
223-
// BlendSpeed = ParseFloat(root.GetChildSafe("BlendSpeed"));
224+
// BlendSpeed = ParseFloat(root.GetChildSafe("BlendSpeed"));
225+
226+
// Adding support for a custom MenuCamera if it exists
227+
var menuCamera = root.GetChild("MenuCamera");
228+
if (menuCamera != null)
229+
{
230+
MenuCamera = ParseCamera(menuCamera);
231+
}
232+
else
233+
{
234+
// Moving Menu Camera 'backup' over here during settings parse time
235+
MenuCamera = new CameraData();
236+
MenuCamera.Name = "MenuCamera";
237+
MenuCamera.Type = CameraType.LookAt;
238+
MenuCamera.PositionBinding = "playerWaist";
239+
MenuCamera.PositionOffset = new Vector3(2.0f, 1.0f, -3.0f);
240+
MenuCamera.LookAt = new Vector3(-2.0f, 0.0f, 5.0f);
241+
}
224242

225243
var camera = root.GetChild("Camera");
226244
while (camera != null)
227245
{
228-
var cameraData = new CameraData();
229-
cameraData.Name = camera.GetChildSafe("Name").mValue;
230-
cameraData.Type = GetCameraTypeFromToken(camera.GetChildSafe("Type"));
231-
cameraData.PositionOffset = GetVector3Token(camera.GetChildSafe("PositionOffset"));
232-
cameraData.LookAt = GetVector3Token(camera.GetChildSafe("LookAt"));
233-
cameraData.PositionBinding = camera.GetChildSafe("PositionBinding").mValue;
234-
cameraData.LookAtBinding = camera.GetChildSafe("LookAtBinding").mValue;
235-
cameraData.Distance = ParseFloat(camera.GetChildSafe("Distance"));
236-
cameraData.Speed = ParseFloat(camera.GetChildSafe("Speed"));
237-
cameraData.MinTime = ParseFloat(camera.GetChildSafe("MinTime"));
238-
cameraData.MaxTime = ParseFloat(camera.GetChildSafe("MaxTime"));
239-
cameraData.ActualTime = ParseFloat(camera.GetChildSafe("ActualTime"));
240-
cameraData.TransitionTime = ParseFloat(camera.GetChildSafe("TransitionTime"));
241-
242-
CameraDataList.Add(cameraData);
246+
CameraDataList.Add(ParseCamera(camera));
243247

244248
camera = root.GetNextChild(camera);
245249
}
246250
}
247251

252+
public static CameraData ParseCamera(ReflectionToken camera)
253+
{
254+
CameraData outCamera = new CameraData();
255+
256+
outCamera.Name = camera.GetChildSafe("Name").mValue;
257+
outCamera.Type = GetCameraTypeFromToken(camera.GetChildSafe("Type"));
258+
outCamera.PositionOffset = GetVector3Token(camera.GetChildSafe("PositionOffset"));
259+
outCamera.LookAt = GetVector3Token(camera.GetChildSafe("LookAt"));
260+
outCamera.PositionBinding = camera.GetChildSafe("PositionBinding").mValue;
261+
outCamera.LookAtBinding = camera.GetChildSafe("LookAtBinding").mValue;
262+
outCamera.Distance = ParseFloat(camera.GetChildSafe("Distance"));
263+
outCamera.Speed = ParseFloat(camera.GetChildSafe("Speed"));
264+
outCamera.MinTime = ParseFloat(camera.GetChildSafe("MinTime"));
265+
outCamera.MaxTime = ParseFloat(camera.GetChildSafe("MaxTime"));
266+
outCamera.ActualTime = ParseFloat(camera.GetChildSafe("ActualTime"));
267+
outCamera.TransitionTime = ParseFloat(camera.GetChildSafe("TransitionTime"));
268+
269+
return outCamera;
270+
}
271+
272+
248273
public static bool ParseBool(ReflectionToken token)
249274
{
250275
bool outBool = false;

Src/MyCameraPlugin.cs

Lines changed: 57 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public class MyCameraPlugin : IPluginCameraBehaviour
3434
// Invoke ApplySettings event when you need to save your settings.
3535
// Do not invoke event every frame if possible.
3636
public event EventHandler ApplySettings;
37-
private BeatSaberStatus BS;
37+
private BeatSaberStatus beatSaberStatus;
3838

3939
// ID is used for the camera behaviour identification when the behaviour is selected by the user.
4040
// It has to be unique so there are no plugin collisions.
@@ -44,7 +44,7 @@ public class MyCameraPlugin : IPluginCameraBehaviour
4444
// Author name.
4545
public string author => "fries";
4646
// Plugin version.
47-
public string version => "1.1.3";
47+
public string version => "1.2.0";
4848

4949
// Locally store the camera helper provided by LIV.
5050
PluginCameraHelper _helper;
@@ -105,7 +105,7 @@ public void OnActivate(PluginCameraHelper helper)
105105

106106
_helper = helper;
107107

108-
BS = new BeatSaberStatus();
108+
beatSaberStatus = new BeatSaberStatus();
109109

110110
_helper.UpdateFov(60.0f);
111111
UpdateCameraChange();
@@ -178,16 +178,16 @@ public void UpdateCameraChange()
178178
if (useHttpStatus)
179179
{
180180
// If HTTPStatus is available, see if we can extract some of the song details
181-
Log("Song Name: " + BS.songName);
182-
Log("Song SubName: " + BS.songSubName);
183-
Log("Song AuthorName: " + BS.songAuthorName);
184-
Log("Level Author: " + BS.levelAuthorName);
185-
Log("Song Hash: " + BS.songHash);
186-
Log("Level ID: " + BS.levelId);
181+
Log("Song Name: " + beatSaberStatus.songName);
182+
Log("Song SubName: " + beatSaberStatus.songSubName);
183+
Log("Song AuthorName: " + beatSaberStatus.songAuthorName);
184+
Log("Level Author: " + beatSaberStatus.levelAuthorName);
185+
Log("Song Hash: " + beatSaberStatus.songHash);
186+
Log("Level ID: " + beatSaberStatus.levelId);
187187

188188
// We need to check to see if there is a song-specific settings file, and if so, load that instead
189189
Log("Checking to see if there are song-specific Settings");
190-
CameraPluginSettings.LoadSettings("settings." + BS.songHash + ".txt");
190+
CameraPluginSettings.LoadSettings("settings." + beatSaberStatus.songHash + ".txt");
191191

192192
if (CameraPluginSettings.SongSpecific)
193193
{
@@ -200,7 +200,7 @@ public void UpdateCameraChange()
200200
}
201201
}
202202

203-
if (useHttpStatus && BS.paused)
203+
if (useHttpStatus && beatSaberStatus.paused)
204204
{
205205
//We're paused, don't do anything
206206
}
@@ -213,45 +213,63 @@ public void UpdateCameraChange()
213213

214214
if (transitionToMenu)
215215
{
216+
// Transition to the Menu Camera and mark that we've done so. Update currentCameraIndex to -1 so we don't skip over Index 0 when we move to another camera
217+
Log("Preparing to change to Menu Camera");
216218
transitionToMenu = false;
217-
currentCameraIndex = 0;
218-
219-
//currentCameraData = CameraPluginSettings.CameraDataList[currentCameraIndex];
220-
//currentCameraType = currentCameraData.Type;
221-
222-
// I hate that this is hardcoded but unless we add a specific 'menu' camera in the base settings file it'll have to do for now
223-
currentCameraData = new CameraData();
224-
currentCameraData.Name = "MenuCamera";
225-
currentCameraData.Type = CameraType.LookAt;
226-
currentCameraData.PositionBinding = "playerWaist";
227-
currentCameraData.PositionOffset = new Vector3(2.0f, 1.0f, -3.0f);
228-
currentCameraData.LookAt = new Vector3(-2.0f, 0.0f, 5.0f);
229-
currentCameraType = currentCameraData.Type;
230-
219+
currentCameraIndex = -1;
220+
currentCameraData = CameraPluginSettings.MenuCamera;
221+
currentCameraType = currentCameraData.Type;
231222
}
232223
else
233224
{
225+
Log("Preparing to change to new Game Camera, currentCameraIndex = " + currentCameraIndex.ToString());
234226
if (CameraPluginSettings.SongSpecific)
235227
{
236-
// Increment camera by 1
228+
Log("Song specific settings file active, increment to next camera");
229+
// Increment camera by 1 but make sure we don't skip over index 0 now
237230
if (newCameraIndex < CameraPluginSettings.CameraDataList.Count)
238231
newCameraIndex++;
239232
}
240233
else
241234
{
242-
// Don't pick the same camera again for a few times
243-
while (previousCameraIndices.Contains(newCameraIndex) || (currentCameraType == CameraType.Orbital && CameraPluginSettings.CameraDataList[newCameraIndex].Type == CameraType.Orbital))
235+
Log("Default settings file active, preparing to pick next camera");
236+
// If we don't have enough cameras to truly randomize...uh...I guess don't
237+
if (CameraPluginSettings.CameraDataList.Count > 2)
244238
{
245-
newCameraIndex = rand.Next() % CameraPluginSettings.CameraDataList.Count;
239+
// Don't pick the same camera again for a few times
240+
while (previousCameraIndices.Contains(newCameraIndex) || (currentCameraType == CameraType.Orbital && CameraPluginSettings.CameraDataList[newCameraIndex].Type == CameraType.Orbital))
241+
{
242+
newCameraIndex = rand.Next() % CameraPluginSettings.CameraDataList.Count;
243+
}
244+
}
245+
else if (CameraPluginSettings.CameraDataList.Count == 2)
246+
{
247+
Log("Only 2 cameras available, swapping between them");
248+
// If you've got two cameras switch between them, otherwise just stick with the current one
249+
switch (currentCameraIndex)
250+
{
251+
case 0:
252+
newCameraIndex = 1;
253+
break;
254+
case 1:
255+
newCameraIndex = 0;
256+
break;
257+
default:
258+
newCameraIndex = 0;
259+
break;
260+
}
261+
}
262+
else
263+
{
264+
newCameraIndex = 0;
246265
}
247266
}
248267

249268
if (previousCameraIndices.Count > 1)
250-
{
251269
previousCameraIndices.RemoveAt(0);
252-
}
253270

254271
previousCameraIndices.Add(newCameraIndex);
272+
255273
currentCameraIndex = newCameraIndex;
256274
currentCameraData = CameraPluginSettings.CameraDataList[currentCameraIndex];
257275
currentCameraType = currentCameraData.Type;
@@ -267,9 +285,9 @@ public void UpdateCameraChange()
267285
var maxTime = currentCameraData.MaxTime;
268286
nextChangeTimer = _elapsedTime + minTime + (float)(rand.NextDouble() * (maxTime - minTime));
269287
}
270-
}
271288

272-
Log("New Camera: " + newCameraIndex + ", " + currentCameraData.Name + ", " + currentCameraData.Type.ToString());
289+
Log("New Camera: " + newCameraIndex + ", " + currentCameraData.Name + ", " + currentCameraData.Type.ToString() + ", " + nextChangeTimer.ToString() + "s");
290+
}
273291

274292
switch (currentCameraType)
275293
{
@@ -324,7 +342,7 @@ public void UpdateCameraChange()
324342
public void OnUpdate()
325343
{
326344
// Allows us to track when HTTPStatus first makes a connecction
327-
if (!useHttpStatus && BS.connected)
345+
if (!useHttpStatus && beatSaberStatus.connected)
328346
{
329347
useHttpStatus = true;
330348
inMenu = true;
@@ -333,14 +351,14 @@ public void OnUpdate()
333351

334352
if (useHttpStatus)
335353
{
336-
if (CameraPluginSettings.Debug && BS.debug.Count > 0)
354+
if (CameraPluginSettings.Debug && beatSaberStatus.debug.Count > 0)
337355
{
338356
// Write debug messages from HTTPStatus
339-
Log(BS.debug[0]);
340-
BS.debug.RemoveAt(0);
357+
Log(beatSaberStatus.debug[0]);
358+
beatSaberStatus.debug.RemoveAt(0);
341359
}
342360

343-
if (BS.menu)
361+
if (beatSaberStatus.menu)
344362
{
345363
// This is a silly way to do this but it allows us to keep track of when we transition between menu and game mode
346364
// That still seems silly, but when juggling random songs, and song-specific camera update files it is helpful. Maybe.
@@ -353,7 +371,7 @@ public void OnUpdate()
353371
// Don't start the timer until we hit our first note, also check for pause
354372
// This allows us to have 'synced' song-specific camera files as different systems will load songs at different speeds
355373
// based on storage and cpu performance. Just...don't miss the first note I guess?
356-
if (BS.score > 0 && !BS.paused)
374+
if (beatSaberStatus.score > 0 && !beatSaberStatus.paused)
357375
_elapsedTime += Time.deltaTime;
358376
}
359377
}

0 commit comments

Comments
 (0)