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

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

// Player Aliases
private alias object.value17 : debugMode.currentSelection


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

reserve function Waterfall_DebugDraw
reserve function Waterfall_DebugSpawn


// ========================
// Static Values
// ========================

private value Waterfall_startDebugID = 0


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

private function Waterfall_DebugDraw
	temp0 = debugMode[0].currentSelection
	temp0 -= Waterfall_startDebugID

	DrawSpriteFX(temp0, FX_FLIP, object.xpos, object.ypos)
end function


private function Waterfall_DebugSpawn
	temp0 = debugMode[0].currentSelection
	temp0 -= Waterfall_startDebugID

	CreateTempObject(TypeName[Waterfall], temp0, object.xpos, object.ypos)
	object[tempObjectPos].direction = object.direction
	object[tempObjectPos].drawOrder = 4
	if object[tempObjectPos].propertyValue == 9
		object[tempObjectPos].frame = 9
	end if
end function


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

event ObjectUpdate
	if object.propertyValue == 9
		if object.state == 1
			temp0 = stage.waterLevel
			temp0 -= 16
			object.iypos = temp0
		end if

		object.animationTimer++
		if object.animationTimer == 6
			object.animationTimer = 0
			object.frame++
			if object.frame == 12
				object.frame = 9
			end if
		end if
	end if
end event


event ObjectDraw
	if object.propertyValue < 9
		DrawSpriteFX(object.propertyValue, FX_FLIP, object.xpos, object.ypos)
	else
		DrawSpriteFX(object.frame, FX_FLIP, object.xpos, object.ypos)
	end if
end event


event ObjectStartup
	LoadSpriteSheet("LZ/Objects.gif")
	SpriteFrame(-5, -16, 13, 32, 191, 140)
	SpriteFrame(-10, -4, 22, 12, 61, 38)
	SpriteFrame(-6, -4, 14, 12, 117, 90)
	SpriteFrame(0, -4, 8, 12, 132, 90)
	SpriteFrame(-6, -4, 14, 12, 117, 103)
	SpriteFrame(0, -4, 8, 12, 132, 103)
	SpriteFrame(0, -4, 8, 12, 191, 76)
	SpriteFrame(-8, -16, 16, 32, 240, 223)
	SpriteFrame(-24, -8, 46, 16, 158, 173)
	SpriteFrame(-20, -16, 39, 32, 118, 161)
	SpriteFrame(-22, -12, 41, 28, 117, 194)
	SpriteFrame(-24, -16, 47, 32, 159, 190)

	foreach (TypeName[Waterfall], arrayPos0, ALL_ENTITIES)
		object[arrayPos0].drawOrder = 4
		if object[arrayPos0].propertyValue == 9
			object[arrayPos0].frame = 9
		end if
	next

	temp0 = 0
	Waterfall_startDebugID = DebugMode_ObjCount
	while temp0 < 10
		SetTableValue(TypeName[Waterfall], DebugMode_ObjCount, DebugMode_TypesTable)
		SetTableValue(Waterfall_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
		SetTableValue(Waterfall_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
		DebugMode_ObjCount++
		temp0++
	loop
end event


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

event RSDKEdit
	if editor.returnVariable == true
		switch editor.variableID
		case EDIT_VAR_PROPVAL // property value
			checkResult = object.propertyValue
			checkResult %= 10
			break
			
		case 0 // frameID
			checkResult = object.propertyValue
			checkResult %= 10
			break
			
		case 0 // matchSurface
			checkResult = object.state
			break
			
		end switch
	else
		switch editor.variableID
		case EDIT_VAR_PROPVAL // property value
			object.propertyValue = editor.variableValue
			object.propertyValue %= 10
			break
			
		case 0 // frameID
			object.propertyValue = editor.variableValue
			object.propertyValue %= 10
			break
			
		case 1 // matchSurface
			CheckNotEqual(editor.variableValue, false)
			object.state = checkResult
			break
			
		end switch
	end if
end event


event RSDKDraw
	DrawSpriteFX(object.propertyValue, FX_FLIP, object.xpos, object.ypos)
end event


event RSDKLoad
	LoadSpriteSheet("LZ/Objects.gif")
	SpriteFrame(-5, -16, 13, 32, 191, 140)
	SpriteFrame(-10, -4, 22, 12, 61, 38)
	SpriteFrame(-6, -4, 14, 12, 117, 90)
	SpriteFrame(0, -4, 8, 12, 132, 90)
	SpriteFrame(-6, -4, 14, 12, 117, 103)
	SpriteFrame(0, -4, 8, 12, 132, 103)
	SpriteFrame(0, -4, 8, 12, 191, 76)
	SpriteFrame(-8, -16, 16, 32, 240, 223)
	SpriteFrame(-24, -8, 46, 16, 158, 173)
	SpriteFrame(-20, -16, 39, 32, 118, 161)
	SpriteFrame(-22, -12, 41, 28, 117, 194)
	SpriteFrame(-24, -16, 47, 32, 159, 190)

	AddEditorVariable("frameID")
	SetActiveVariable("frameID")
	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)
	AddEnumVariable("Frame 8", 8)
	AddEnumVariable("Splash", 9)
	
	AddEditorVariable("matchSurface")
	SetActiveVariable("matchSurface")
	AddEnumVariable("False", 0)
	AddEnumVariable("True", 1)
end event
