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

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

reserve function BridgeEnd_DebugDraw
reserve function BridgeEnd_DebugSpawn


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

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


private function BridgeEnd_DebugSpawn
	CreateTempObject(TypeName[Bridge 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
	LoadSpriteSheet("GHZ/Objects.gif")

	// Sprite frames
	SpriteFrame(-16, -8, 32, 16, 18, 1)
	SpriteFrame(-16, -8, 32, 16, 51, 1)

	// Set all Bridge End objects to have a drawOrder of 4, one above the standard of 3
	// (This object was made while v4 spec was still being developed, foreaches didn't exist back when this object was made so a v3-styled loop is used instead)
	arrayPos0 = 32
	while arrayPos0 < 0x420
		if object[arrayPos0].type == TypeName[Bridge End]
			object[arrayPos0].drawOrder = 4
		end if
		
		arrayPos0++
	loop

	// Add this object to the debug mode list
	SetTableValue(TypeName[Bridge End], DebugMode_ObjCount, DebugMode_TypesTable)
	SetTableValue(BridgeEnd_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
	SetTableValue(BridgeEnd_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 &= 1
			break
			
		case 0 // direction
			checkResult = object.propertyValue
			checkResult &= 1
			break
			
		end switch
	else
		switch editor.variableID
		case EDIT_VAR_PROPVAL // property value
			object.propertyValue = editor.variableValue
			object.propertyValue &= 1
			break
			
		case 0 // direction
			object.propertyValue = editor.variableValue
			object.propertyValue &= 1
			break
			
		end switch
	end if
end event


event RSDKDraw
	DrawSprite(object.propertyValue)
end event


event RSDKLoad
	LoadSpriteSheet("GHZ/Objects.gif")
	SpriteFrame(-16, -8, 32, 16, 18, 1)
	SpriteFrame(-16, -8, 32, 16, 51, 1)

	AddEditorVariable("direction")
	SetActiveVariable("direction")
	AddEnumVariable("Left", 0)
	AddEnumVariable("Right", 1)
end event
