// Custom Invincibility / Grow Jingle by Pontrol

// =======================
// COLAPAK THEME TABLE
// =======================
local characterThemes = {

	pastel = { inv = "tunes PASINV", grow = "tunes PASINV" },
	
}

// =======================
// GLOBAL SETTINGS
// =======================
local defaulttheme = "tunes -default"
local tuned = 0   -- 0 = default, 1 = inv, 2 = grow

// =======================
// MAIN LOGIC
// =======================
addHook("ThinkFrame", function()
	if not consoleplayer or not consoleplayer.mo then return end

	if consoleplayer.exiting then
		if tuned ~= 0 then
			COM_BufInsertText(consoleplayer, defaulttheme)
			tuned = 0
		end
		return
	end

	local skin = consoleplayer.mo.skin
	local themes = characterThemes[skin]

	if not themes then
		if tuned ~= 0 then
			COM_BufInsertText(consoleplayer, defaulttheme)
			tuned = 0
		end
		return
	end

	if consoleplayer.invincibilitytimer and consoleplayer.invincibilitytimer > 0 then
		if tuned ~= 1 then
			COM_BufInsertText(consoleplayer, themes.inv)
			tuned = 1
		end
		return
	end

	if consoleplayer.growshrinktimer and consoleplayer.growshrinktimer > 0 then
		if tuned ~= 2 then
			COM_BufInsertText(consoleplayer, themes.grow)
			tuned = 2
		end
		return
	end

	if tuned ~= 0 then
		COM_BufInsertText(consoleplayer, defaulttheme)
		tuned = 0
	end
end)

// =======================
// GAME QUIT CLEANUP
// =======================
addHook("GameQuit", function()
	if tuned ~= 0 and consoleplayer then
		COM_BufInsertText(consoleplayer, defaulttheme)
		tuned = 0
	end
end)
