// ----------------------------------
// RSDK Project: Sonic 2
// Script Description: Lift End Object
// Script Author: Christian Whitehead/Simon Thomley
// Unpacked by Rubberduckycooly's script unpacker
// ----------------------------------

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

reserve function LiftEnd_DebugDraw
reserve function LiftEnd_DebugSpawn


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

private function LiftEnd_DebugDraw
	temp0 = object.direction
	temp0 &= 1
	DrawSprite(temp0)
end function


private function LiftEnd_DebugSpawn
	CreateTempObject(TypeName[Lift End], 0, object.xpos, object.ypos)
	object[tempObjectPos].drawOrder 	= 4
	object[tempObjectPos].propertyValue = object.direction
	object[tempObjectPos].propertyValue &= 1
end function


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

event ObjectDraw
	DrawSprite(object.propertyValue)
end event


event ObjectStartup
	CheckCurrentStageFolder("Zone05")
	if checkResult == true
		LoadSpriteSheet("HTZ/Objects.gif")

		SpriteFrame(-8, -56, 16, 80, 174, 96) 	// Start Post 			- #0
		SpriteFrame(-8, -54, 16, 78, 174, 177)	// End Post 			- #1
		SpriteFrame(-8, -24, 16, 16, 126, 123)	// Start Ground Cover 	- #2
		SpriteFrame(-9, -24, 16, 16, 108, 123)	// End Ground Cover	 	- #3
	else
		LoadSpriteSheet("MBZ/Objects.gif")

		SpriteFrame(-8, -56, 16, 80, 34, 867)	// Start Post 			- #0
		SpriteFrame(-8, -54, 16, 78, 51, 869)	// End Post 				- #1

		// An odd set of frames
		// While understandably empty, since MBZ doesn't have uneven ground to need these anyway,
		// the data for these frames loosely aligns with HTZ's section of the MBZ sheet
		SpriteFrame(-8, -24, 0, 0, 92, 888)		// Start Ground Cover 	- #2
		SpriteFrame(-9, -24, 0, 0, 92, 888)		// End Ground Cover	 	- #3
	end if

	foreach (TypeName[Lift End], arrayPos0, ALL_ENTITIES)
		object[arrayPos0].drawOrder = 4
	next

	SetTableValue(TypeName[Lift End], DebugMode_ObjCount, DebugMode_TypesTable)
	SetTableValue(LiftEnd_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
	SetTableValue(LiftEnd_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
			break
			
		case 0 // displaySprite
			checkResult = object.propertyValue
			checkResult &= 3
			break
			
		end switch
	else
		switch editor.variableID
		case EDIT_VAR_PROPVAL // property value
			object.propertyValue = editor.variableValue
			break
			
		case 0 // displaySprite
			object.propertyValue = editor.variableValue
			object.propertyValue &= 3
			break
			
		end switch
	end if
end event


event RSDKDraw
	DrawSprite(object.propertyValue)
end event


event RSDKLoad
	CheckCurrentStageFolder("Zone05")
	if checkResult == true
		LoadSpriteSheet("HTZ/Objects.gif")
		SpriteFrame(-8, -56, 16, 80, 174, 96)	// Start Post 			- #0
		SpriteFrame(-8, -54, 16, 78, 174, 177)	// End Post 			- #1
		SpriteFrame(-8, -24, 16, 16, 126, 123)	// Start Ground Cover	- #2
		SpriteFrame(-9, -24, 16, 16, 108, 123)	// End Ground 	Cover	- #3
	else
		LoadSpriteSheet("MBZ/Objects.gif")
		SpriteFrame(-8, -56, 16, 80, 34, 867)	// Start Post 			- #0
		SpriteFrame(-8, -54, 16, 78, 51, 869)	// End Post 			- #1

		// May as well keep these last two frames anyways
		SpriteFrame(-8, -24, 0, 0, 92, 888)		// Start Ground Cover	- #2
		SpriteFrame(-9, -24, 0, 0, 92, 888)		// End Ground 	Cover	- #3
	end if

	AddEditorVariable("displaySprite")
	SetActiveVariable("displaySprite")
	AddEnumVariable("Start Post", 0)
	AddEnumVariable("End Post", 1)
	AddEnumVariable("Start Ground", 2)
	AddEnumVariable("End Ground", 3)
end event
