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

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

reserve function Cloud_DebugDraw
reserve function Cloud_DebugSpawn


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

private function Cloud_DebugDraw
	DrawSprite(0)
end function


private function Cloud_DebugSpawn
	CreateTempObject(TypeName[Cloud], 0, object.xpos, object.ypos)
	object[tempObjectPos].drawOrder = 2
	object[tempObjectPos].xvel = -0xC000
end function


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

event ObjectUpdate
	object.xpos += object.xvel
	object.xpos += WFZSetup_scrollVelocity.x
end event


event ObjectDraw
	DrawSprite(object.propertyValue)
end event


event ObjectStartup
	LoadSpriteSheet("SCZ/Objects.gif")

	// Cloud frames
	SpriteFrame(-40, -4, 79, 8, 72, 74)
	SpriteFrame(-24, -4, 48, 8, 72, 83)
	SpriteFrame(-8, -4, 16, 8, 121, 83)

	foreach (TypeName[Cloud], arrayPos0, ALL_ENTITIES)
		object[arrayPos0].drawOrder = 2
		switch object[arrayPos0].propertyValue
		case 0
			object[arrayPos0].xvel = -0xC000
			break

		case 1
			object[arrayPos0].xvel = -0x8000
			break

		case 2
			object[arrayPos0].xvel = -0x4000
			break
			
		end switch
	next

	SetTableValue(TypeName[Cloud], DebugMode_ObjCount, DebugMode_TypesTable)
	SetTableValue(Cloud_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
	SetTableValue(Cloud_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 %= 3
			break
			
		case 0 // frameID
			checkResult = object.propertyValue
			checkResult %= 3
			break
			
		end switch
	else
		switch editor.variableID
		case EDIT_VAR_PROPVAL // property value
			object.propertyValue = editor.variableValue
			object.propertyValue %= 3
			break
			
		case 0 // frameID
			object.propertyValue = editor.variableValue
			object.propertyValue %= 3
			break
			
		end switch
	end if
end event


event RSDKDraw
	DrawSprite(object.propertyValue)
end event


event RSDKLoad
	LoadSpriteSheet("SCZ/Objects.gif")
	SpriteFrame(-40, -4, 79, 8, 72, 74)
	SpriteFrame(-24, -4, 48, 8, 72, 83)
	SpriteFrame(-8, -4, 16, 8, 121, 83)

	AddEditorVariable("frameID")
	SetActiveVariable("frameID")
	AddEnumVariable("Long Cloud", 0)
	AddEnumVariable("Medium Cloud", 1)
	AddEnumVariable("Small Cloud", 2)
end event
