/*
	This script file is part of the Sonic 3 A.I.R. script software distribution.
	Copyright (C) 2017-2024 by Eukaryot

	Published under the GNU GPLv3 open source software license, see license.txt
	or https://www.gnu.org/licenses/gpl-3.0.en.html
*/



//# address-hook(0x003af0) end(0x003b12)
function void Menu.FadeInAfterInit()
{
	u8 lastGameMode = global.game_mode

	SetPaletteFadedOut(0x003f)
	D4.u16 = 0x15
	while (D4.s16 >= 0)
	{
		global.frame_state = 0x12
		waitForNextFrame()

		FadeInPalette()
		LoadRequiredSpritePatterns()
		--D4.s16

	#if STANDALONE
		// SEGA logo
		if (global.game_mode == 0x04)
		{
			Renderer.resetSprites()
			Renderer.drawCustomSprite("original_game_by", getScreenWidth() / 2 - 85, 60, 0x00, 0, 0x2000, 0, u16(u8[0xfffffc01] & 0x0e) * 96 / 0x0e)
		}

		// Data Select
		if (global.game_mode == 0x4c || lastGameMode == 0x4c)
		{
			// Draw our own widescreen version of the background
			//  -> For this to work, we need to update the sprites as well
			u16 backupD4 = D4.u16
			UpdateGameObjects()
			RenderSprites()

			// Update scroll offset (if the player scrolls during fade-in already)
			u16[0xffffe002] = -camera.foreground.x.u16

			DataSelect.drawCustomPlanes()
			D4.u16 = backupD4
		}
	#endif
	}
}


#if STANDALONE
function void Menu.fadeInImmediatelyAfterInit()
{
	SetPaletteFadedOut(0x003f)
	D4.u16 = 0x15
	while (D4.s16 >= 0)
	{
		FadeInPalette()
		LoadRequiredSpritePatterns()
		--D4.s16
	}
}
#endif
