// ----------------------------------
// RSDK Project: Sonic 1
// Script Description: Pink Block Object
// Script Author: Christian Whitehead/Simon Thomley
// Unpacked by Rubberduckycooly's script unpacker
// ----------------------------------

// ========================
// Aliases
// ========================

private alias object.propertyValue : object.colorChangeOffset


// ========================
// Function Declarations
// ========================

reserve function PinkBlock_DebugDraw
reserve function PinkBlock_DebugSpawn


// ========================
// Function Definitions
// ========================

private function PinkBlock_DebugDraw
	DrawSprite(0)
	DrawSprite(1)
	DrawSprite(2)
end function


private function PinkBlock_DebugSpawn
	temp5 = TypeName[Pink Block]
	temp4 = 0
	CallFunction(DebugMode_PlaceBlock)
	object[arrayPos0].drawOrder = 4
	object[arrayPos0].groupID = GROUP_BLOCKS
end function


// ========================
// Events
// ========================

event ObjectUpdate
	foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
		CallFunction(SpecialSetup_PlayerBlockCol)
	next
end event


event ObjectDraw
	if object.colorChangeOffset > 0
		temp0 = SpecialSetup_blockTimer
		temp0 >>= 3
		temp1 = object.colorChangeOffset
		temp1 -= temp0
		switch temp1
		case 1
		case 3
			object.type = TypeName[Yellow Block]
			break

		default
			break
		end switch
	end if

	CallFunction(SpecialSetup_GetBlockPos)
	DrawSpriteFX(0, FX_ROTATE, temp0, temp1)
	DrawSpriteXY(1, temp0, temp1)
	
	temp2 = object.rotation
	temp2 >>= 3
	temp2 += 2
	DrawSpriteFX(temp2, FX_ROTATE, temp0, temp1)

	object.type = TypeName[Pink Block]
end event


event ObjectStartup
	LoadSpriteSheet("Special/Objects.gif")
	SpriteFrame(-12, -12, 24, 24, 126, 276)
	SpriteFrame(-10, -8, 20, 16, 151, 276)

	temp0 = 1
	temp1 = 201
	while temp1 < 300
		temp0 = 1
		while temp0 < 500
			SpriteFrame(-12, -12, 24, 24, temp0, temp1)
			temp0 += 25
		loop
		temp1 += 25
	loop

	foreach (TypeName[Pink Block], arrayPos0, ALL_ENTITIES)
		object[arrayPos0].groupID = GROUP_BLOCKS
	next
	
	SetTableValue(TypeName[Pink Block], DebugMode_ObjCount, DebugMode_TypeTable)
	SetTableValue(PinkBlock_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
	SetTableValue(PinkBlock_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
	DebugMode_ObjCount++
end event


// ========================
// Editor Events
// ========================

event RSDKEdit
	if editor.returnVariable == true
		switch editor.variableID
		case EDIT_VAR_PROPVAL // property value
			checkResult = object.propertyValue
			checkResult &= 7
			break
			
		case 0 // colorChangeOffset
			checkResult = object.propertyValue
			checkResult &= 7
			break
			
		end switch
	else
		switch editor.variableID
		case EDIT_VAR_PROPVAL // property value
			object.propertyValue = editor.variableValue
			object.propertyValue &= 7
			break
			
		case 0 // colorChangeOffset
			object.propertyValue = editor.variableValue
			object.propertyValue &= 7
			break
			
		end switch
	end if
end event


event RSDKDraw
	DrawSprite(0)
	DrawSprite(1)
	DrawSprite(2)
end event


event RSDKLoad
	LoadSpriteSheet("Special/Objects.gif")
	SpriteFrame(-12, -12, 24, 24, 126, 276)
	SpriteFrame(-10, -8, 20, 16, 151, 276)
	SpriteFrame(-12, -12, 24, 24, 1, 201)
	
	AddEditorVariable("colorChangeOffset")
	SetActiveVariable("colorChangeOffset")
	AddEnumVariable("Frame 0", 0)
	AddEnumVariable("Frame 1", 1)
	AddEnumVariable("Frame 2", 2)
	AddEnumVariable("Frame 3", 3)
	AddEnumVariable("Frame 4", 4)
	AddEnumVariable("Frame 5", 5)
	AddEnumVariable("Frame 6", 6)
	AddEnumVariable("Frame 7", 7)
end event
