Transposer/TransposerGame.cs
namespace Sandbox.Transposer;

/// <summary>
/// s&box Component entry point for the Transposer game.
///
/// Attach this to a GameObject alongside a <see cref="PixelScreen"/> component
/// (configured to 192×128 resolution). This component initialises the sprite
/// data, creates the scene manager, and drives the game loop each frame.
/// </summary>
[Title( "Transposer Game" )]
[Category( "Games" )]
[Icon( "sports_esports" )]
public sealed class TransposerGame : Component
{
	/// <summary>
	/// Reference to the PixelScreen component. Set via the editor inspector.
	/// Should be configured to 192×128 for the original Transposer resolution.
	/// </summary>
	[Property]
	public PixelScreen PixelScreen { get; set; }

	private TransposerSceneManager _sceneManager;

	protected override void OnStart()
	{
		// Force the correct Transposer resolution (original game was 192×128).
		// Must call ResizeBuffer() to reallocate the pixel array and GPU texture
		// since PixelScreen.OnEnabled already ran with the default size.
		if ( PixelScreen is not null )
		{
			PixelScreen.PixelWidth = 192;
			PixelScreen.PixelHeight = 128;
			PixelScreen.ResizeBuffer();
		}

		// Load persisted high score from disk.
		Globals.LoadFromDisk();

		// Ensure sprite data is loaded (including the transposer/ sprites).
		SpriteManager.Reload();

		_sceneManager = new TransposerSceneManager();
		_sceneManager.Begin();
	}

	protected override void OnUpdate()
	{
		// Poll input before any game logic.
		InputManager.Update();

		// Drive music fades and pitch updates.
		AudioManager.Tick( Time.Delta );

		// Tick the active scene.
		_sceneManager?.Update( Time.Delta );
	}
}