-- WARNING:
-- uses abstract layoutRotascope puzzle!
-- ----------------------------------------------------------------------------
assert(LayoutRotascope ~= nil)
setmetatable(layoutBoathouseRotascope, LayoutRotascope)
-- ----------------------------------------------------------------------------
layoutBoathouseRotascope.mHOs = 
{
	[objectHoRotascopePiece01] = 
	{
		siblings = {objectHoRotascopePiece01Lit, objectHoRotascopePiece01Pocket},
	},
	[objectCryptHookmanLetterPiece02] = 
	{
		siblings = {objectCryptHookmanLetterPiece02Lit, objectCryptHookmanLetterPiece02Pocket},
	},	
}
-- ----------------------------------------------------------------------------
layoutBoathouseRotascope.mFirstTime = true
-- ----------------------------------------------------------------------------
function layoutBoathouseRotascope:onConstruct()

	local pivots = 
	{
		objectBoatIoRotateAreaCenter, objectBoatIoRotateAreaLeft, objectBoatIoRotateAreaRight,
		objectBoatIoRotateAreaTop,
	}
	
	local elipses = 
	{
		objectBoatRotascopePiece01, objectBoatRotascopePiece02, objectBoatRotascopePiece03, 
		objectBoatRotascopePiece04, objectBoatRotascopePiece05, objectBoatRotascopePiece06, 
		objectBoatRotascopePiece07, objectBoatRotascopePiece08, objectBoatRotascopePiece09,	
	}
	
	local pins = 
	{
		objectBoatTurningScrewCenter, objectBoatTurningScrewLeft, objectBoatTurningScrewRight,
		objectBoatTurningScrewTop,
	}
	
	objectBoatRotascopePiece01.alts = {objectBoatRotascopePiece08, objectBoatRotascopePiece09}
	objectBoatRotascopePiece02.alts = {objectBoatRotascopePiece06, objectBoatRotascopePiece07}
	objectBoatRotascopePiece03.alts = {objectBoatRotascopePiece04, objectBoatRotascopePiece05}
	objectBoatRotascopePiece04.alts = {objectBoatRotascopePiece03, objectBoatRotascopePiece05}
	objectBoatRotascopePiece05.alts = {objectBoatRotascopePiece04, objectBoatRotascopePiece03}
	objectBoatRotascopePiece06.alts = {objectBoatRotascopePiece02, objectBoatRotascopePiece07}
	objectBoatRotascopePiece07.alts = {objectBoatRotascopePiece06, objectBoatRotascopePiece02}
	objectBoatRotascopePiece08.alts = {objectBoatRotascopePiece01, objectBoatRotascopePiece09}
	objectBoatRotascopePiece09.alts = {objectBoatRotascopePiece08, objectBoatRotascopePiece01}
	
	LayoutRotascope.onConstruct(self)
	LayoutRotascope.setup(self, pivots, elipses, pins, objectBoatIoResetButton)
	self.mColor = false
	
	objectHoRotascopePiece01:ss(kInactive)
	objectCryptHookmanLetterPiece02:ss(kInactive)

end
-- ----------------------------------------------------------------------------
function layoutBoathouseRotascope:onInitialize()

	LayoutRotascope.onInitialize(self)
	
	objectBoatRotascopeOpen:ss(kInactive)
	objectBoatGreenLight:ss(kInactive)
	
end
-- ----------------------------------------------------------------------------
function layoutBoathouseRotascope:onShow()

	LayoutRotascope.onShow(self)
	
	if (self.mFirstTime) then	
		if (not layoutCryptRotascope:isSeen()) then
			think("MESSAGE_ODD_PUZZLE_BOX")
		else
			think("MESSAGE_OTHER_PUZZLE_BOX")
		end
		self.mFirstTime = false
	end
	
	if (self:isSolved()) then
		if (objectCryptHookmanLetterPiece02:isHidden()) then
			objectCryptHookmanLetterPiece02:ss(kActive)
		end
	end

end
-- ----------------------------------------------------------------------------
function layoutBoathouseRotascope:onSolve()

	LayoutRotascope.onSolve(self)
	
	objectBoatRedLight:ss(kDone)
	objectBoatGreenLight:ss(kActive)

end
-- ----------------------------------------------------------------------------
function layoutBoathouseRotascope:onSolveStart()

	LayoutRotascope.onSolveStart(self)
	
	objectBoatLockPin:animate("MovePin",
		{ delay = 2000 },
		{ dx = 0, dy = 45, duration = 1000, style="easeInOut" }
	)
	
	objectBoatRotascopeOpen:ss(kIdle)
	objectBoatRotascopeOpen:setAlpha(0)
	objectBoatRotascopeOpen:animate("FadeInRotascopeOpen",
		{ delay = 3500 },
		{ alpha = 1, duration = 1000 }
	)
	
	local fadeInObjects = 
	{
		objectHoRotascopePiece01,objectHoRotascopePiece01Lit, objectHoRotascopePiece01Pocket,
		objectCryptHookmanLetterPiece02, objectCryptHookmanLetterPiece02Lit, objectCryptHookmanLetterPiece02Pocket,
	}
	
	for i, object in ipairs(fadeInObjects) do
		if (object:isInactive()) then
			object:ss(kIdle)
		end
		if (object:isHidden()) then
			object:ss(kActive)
		end
		object:setAlpha(0)
		object:animate("FadeIn" .. object:name(),
			{ delay = 3500 },
			{ alpha = 1, duration = 1000 }
		)			
	end
	
	self:animate("BlockBoatRotascope_blocking",
		{ delay = 2000 },
		{ command="playTrack track=UNLOCKED", target=self },
		{ delay = 3000 },
		{ call = layoutBoathouseRotascope.solveFinish }
	)
	
end
-- ----------------------------------------------------------------------------
function layoutBoathouseRotascope:onSolveFinish()

	LayoutRotascope.onSolveFinish(self)

	think("MESSAGE_OPEN_BOATHOUSE_ROTASCOPE")

end
-- ----------------------------------------------------------------------------
function layoutBoathouseRotascope:onAnimationFinish(animationName)

	LayoutRotascope.onAnimationFinish(self, animationName)
	
	if (animationName == "BlockBoatRotascope_blocking") then
		objectPoiRotascopeBoathouseOpen:ss(kActive)
		objectPoiRotascopeBoathouseClosed:ss(kDone)
	end

end
-- ----------------------------------------------------------------------------
function layoutBoathouseRotascope:playRotateSound()
	playAudioTrack("ROTATE_DISC")
end