Skip to content

Commit

Permalink
Fix environment-specific screen placements not applying after a hot r…
Browse files Browse the repository at this point in the history
…eload. Closes #44
  • Loading branch information
Kevga committed Mar 13, 2022
1 parent 0966dc0 commit 8eacce8
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 68 deletions.
56 changes: 2 additions & 54 deletions BeatSaberCinema/Environment/EnvironmentController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -563,15 +563,6 @@ private static void DefaultSceneModifications(VideoConfig? videoConfig)
{
hud.transform.localScale = invertedScale;
}

//Use different defaults for this environment
var placement = new Placement(videoConfig, PlaybackController.Scene.SoloGameplay, PlaybackController.Instance.VideoPlayer.GetVideoAspectRatio())
{
Position = videoConfig?.screenPosition ?? new Vector3(0f, 6.2f, 52.7f), Rotation = videoConfig?.screenRotation ?? Vector3.zero,
Height = videoConfig?.screenHeight ?? 16f,
Curvature = videoConfig?.screenCurvature ?? 0f
};
PlaybackController.Instance.VideoPlayer.SetPlacement(placement);
break;
}
case "KaleidoscopeEnvironment":
Expand All @@ -593,14 +584,6 @@ private static void DefaultSceneModifications(VideoConfig? videoConfig)
var localPos = glowLine.transform.localPosition;
glowLine.transform.localPosition = new Vector3(localPos.x, localPos.y - coneOffset, localPos.z);
}

var placement = new Placement(videoConfig, PlaybackController.Scene.SoloGameplay, PlaybackController.Instance.VideoPlayer.GetVideoAspectRatio())
{
Position = videoConfig?.screenPosition ?? new Vector3(0f, 1f, 35f), Rotation = videoConfig?.screenRotation ?? Vector3.zero,
Height = videoConfig?.screenHeight ?? 12f,
Curvature = videoConfig?.screenCurvature
};
PlaybackController.Instance.VideoPlayer.SetPlacement(placement);
break;
}
case "GlassDesertEnvironment":
Expand Down Expand Up @@ -629,14 +612,6 @@ private static void DefaultSceneModifications(VideoConfig? videoConfig)
{
light.SetActive(false);
}

var placement = new Placement(videoConfig, PlaybackController.Scene.SoloGameplay, PlaybackController.Instance.VideoPlayer.GetVideoAspectRatio())
{
Position = videoConfig?.screenPosition ?? new Vector3(0f, 6.3f, 37f), Rotation = videoConfig?.screenRotation ?? Vector3.zero,
Height = videoConfig?.screenHeight ?? 12.5f,
Curvature = videoConfig?.screenCurvature
};
PlaybackController.Instance.VideoPlayer.SetPlacement(placement);
break;
}
case "CrabRaveEnvironment":
Expand Down Expand Up @@ -819,15 +794,6 @@ private static void DefaultSceneModifications(VideoConfig? videoConfig)
laser11.transform.position = new Vector3(-12.4f, 10f, 9.3f);
laser11.transform.eulerAngles = new Vector3(0f, 0, 30);
}

var placement = new Placement(videoConfig, PlaybackController.Scene.SoloGameplay, PlaybackController.Instance.VideoPlayer.GetVideoAspectRatio())
{
Position = videoConfig?.screenPosition ?? new Vector3(0f, 5.46f, 40f), Rotation = videoConfig?.screenRotation ?? new Vector3(-5f, 0f, 0f),
Height = videoConfig?.screenHeight ?? 13f,
Curvature = videoConfig?.screenCurvature
};
PlaybackController.Instance.VideoPlayer.SetPlacement(placement);

break;
}
case "SkrillexEnvironment":
Expand All @@ -843,25 +809,6 @@ private static void DefaultSceneModifications(VideoConfig? videoConfig)
{
skrillexLogoBottom.transform.position = new Vector3(-0.23f, -15.5f, 60f);
}

var placement = new Placement(videoConfig, PlaybackController.Scene.SoloGameplay, PlaybackController.Instance.VideoPlayer.GetVideoAspectRatio())
{
Position = videoConfig?.screenPosition ?? new Vector3(0f, 1.5f, 30f), Rotation = videoConfig?.screenRotation ?? new Vector3(0f, 0f, 0f),
Height = videoConfig?.screenHeight ?? 12f,
Curvature = videoConfig?.screenCurvature
};
PlaybackController.Instance.VideoPlayer.SetPlacement(placement);
break;
}
case "WeaveEnvironment":
{
var placement = new Placement(videoConfig, PlaybackController.Scene.SoloGameplay, PlaybackController.Instance.VideoPlayer.GetVideoAspectRatio())
{
Position = videoConfig?.screenPosition ?? new Vector3(0f, 1.5f, 21f), Rotation = videoConfig?.screenRotation ?? new Vector3(0f, 0f, 0f),
Height = videoConfig?.screenHeight ?? 4.3f,
Curvature = videoConfig?.screenCurvature
};
PlaybackController.Instance.VideoPlayer.SetPlacement(placement);
break;
}
}
Expand Down Expand Up @@ -1014,7 +961,8 @@ private static void PrepareClonedScreens(VideoConfig videoConfig)
}

PlaybackController.Instance.VideoPlayer.SetPlacement(
new Placement(videoConfig, PlaybackController.Scene.SoloGameplay, PlaybackController.Instance.VideoPlayer.GetVideoAspectRatio()));
Placement.CreatePlacementForConfig(videoConfig, PlaybackController.Scene.SoloGameplay, PlaybackController.Instance.VideoPlayer.GetVideoAspectRatio())
);
PlaybackController.Instance.VideoPlayer.screenController.SetShaderParameters(videoConfig);
}

Expand Down
51 changes: 39 additions & 12 deletions BeatSaberCinema/Screen/Placement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ public class Placement
public bool? CurveYAxis;
public int? Subsurfaces;

public static Placement SoloGameplayPlacement => new Placement(
private static Placement SoloGameplayPlacement => new Placement(
new Vector3(0, 12.4f, 67.8f),
new Vector3(-8, 0, 0),
25f
);

public static Placement MultiplayerPlacement => new Placement(
private static Placement MultiplayerPlacement => new Placement(
new Vector3(0, 5f, 67f),
new Vector3(-5, 0, 0),
17f
Expand All @@ -36,35 +36,62 @@ public class Placement
12f
);

public Placement(Vector3 position, Vector3 rotation, float height, float? width = null)
private Placement(Vector3 position, Vector3 rotation, float height, float? width = null, float? curvature = null)
{
Position = position;
Rotation = rotation;
Height = height;
Width = width ?? (height * (16f / 9f));
Curvature = curvature;
}

public Placement(VideoConfig? config, PlaybackController.Scene scene, float aspectRatio)
public static Placement CreatePlacementForConfig(VideoConfig? config, PlaybackController.Scene scene, float aspectRatio)
{
var defaultPlacement = GetDefaultPlacementForScene(scene);
Position = config?.screenPosition ?? defaultPlacement.Position;
Rotation = config?.screenRotation ?? defaultPlacement.Rotation;
Height = config?.screenHeight ?? defaultPlacement.Height;
Width = Height * aspectRatio;
Curvature = config?.screenCurvature;
Subsurfaces = config?.screenSubsurfaces;
CurveYAxis = config?.curveYAxis;
if (scene == PlaybackController.Scene.MultiplayerGameplay || config == null)
{
return defaultPlacement;
}

var placement = new Placement(
config.screenPosition ?? defaultPlacement.Position,
config.screenRotation ?? defaultPlacement.Rotation,
config.screenHeight ?? defaultPlacement.Height
);

placement.Width = placement.Height * aspectRatio;
placement.Curvature = config?.screenCurvature;
placement.Subsurfaces = config?.screenSubsurfaces;
placement.CurveYAxis = config?.curveYAxis;

return placement;
}

public static Placement GetDefaultPlacementForScene(PlaybackController.Scene scene)
{
return scene switch
{
PlaybackController.Scene.SoloGameplay => SoloGameplayPlacement,
PlaybackController.Scene.SoloGameplay => (GetDefaultEnvironmentPlacement() ?? SoloGameplayPlacement),
PlaybackController.Scene.MultiplayerGameplay => MultiplayerPlacement,
PlaybackController.Scene.Menu => MenuPlacement,
_ => SoloGameplayPlacement
};
}

private static Placement? GetDefaultEnvironmentPlacement()
{
return Util.GetEnvironmentName() switch
{
"LinkinParkEnvironment" => new Placement(new Vector3(0f, 6.2f, 52.7f), Vector3.zero, 16f, null, 0f),
"BTSEnvironment" => new Placement(new Vector3(0, 12.4f, 80f), new Vector3(-8, 0, 0), 25f),
"KaleidoscopeEnvironment" => new Placement(new Vector3(0f, 1f, 35f), Vector3.zero, 12f),
"InterscopeEnvironment" => new Placement(new Vector3(0f, 6.3f, 37f), Vector3.zero, 12.5f),
"CrabRaveEnvironment" => new Placement(new Vector3(0f, 5.46f, 40f), new Vector3(-5f, 0f, 0f), 13f),
"MonstercatEnvironment" => new Placement(new Vector3(0f, 5.46f, 40f), new Vector3(-5f, 0f, 0f), 13f),
"SkrillexEnvironment" => new Placement(new Vector3(0f, 1.5f, 30f), Vector3.zero, 12f),
"WeaveEnvironment" => new Placement(new Vector3(0f, 1.5f, 21f), Vector3.zero, 4.3f, null, 0f),
_ => null
};
}
}
}
4 changes: 2 additions & 2 deletions BeatSaberCinema/Screen/PlaybackController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ private void OnConfigChanged(VideoConfig? config)
}
else
{
VideoPlayer.SetPlacement(new Placement(config, _activeScene, VideoPlayer.GetVideoAspectRatio()));
VideoPlayer.SetPlacement(Placement.CreatePlacementForConfig(config, _activeScene, VideoPlayer.GetVideoAspectRatio()));
}

if (previousVideoPath != config.VideoPath)
Expand Down Expand Up @@ -575,7 +575,7 @@ private void GameSceneLoaded()
VideoLoader.SaveVideoConfig(VideoConfig);
}

VideoPlayer.SetPlacement(Util.IsMultiplayer() ? Placement.MultiplayerPlacement : new Placement(VideoConfig, _activeScene, VideoPlayer.GetVideoAspectRatio()));
VideoPlayer.SetPlacement(Placement.CreatePlacementForConfig(VideoConfig, _activeScene, VideoPlayer.GetVideoAspectRatio()));

//Fixes rough pop-in at the start of the song when transparency is disabled
if (VideoConfig.TransparencyEnabled)
Expand Down

0 comments on commit 8eacce8

Please sign in to comment.