-- WARNING:
-- uses abstract LayoutJigsaw puzzle!
-- ----------------------------------------------------------------------------
assert(LayoutJigsaw ~= nil)
setmetatable(layoutCarMirror, LayoutJigsaw)
-- ----------------------------------------------------------------------------
layoutCarMirror.mGroups =
{
	[objectHoCarMirrorGroup] =
	{
		children = {objectCarMirrorPiece0, objectCarMirrorPiece1, objectCarMirrorPiece2,
					objectCarMirrorPiece3, objectCarMirrorPiece4, objectCarMirrorPiece5,
					objectCarMirrorPiece6, objectCarMirrorPiece7, objectCarMirrorPiece8,
					objectCarMirrorPiece9},
		inventory = true,
		shoppinglist = false,
	}
}
-- ----------------------------------------------------------------------------
function layoutCarMirror:onConstruct()

	local pieces = 
	{
		objectCarMirrorNotfixedpiece0, objectCarMirrorNotfixedpiece1, objectCarMirrorNotfixedpiece2, 
		objectCarMirrorNotfixedpiece3, objectCarMirrorNotfixedpiece4, objectCarMirrorNotfixedpiece5, 
		objectCarMirrorNotfixedpiece6, objectCarMirrorNotfixedpiece7, objectCarMirrorNotfixedpiece8,	
		objectCarMirrorNotfixedpiece9, 
	}
	
	local correct =
	{
		objectCarMirrorFixpiece0, objectCarMirrorFixpiece1, objectCarMirrorFixpiece2,
		objectCarMirrorFixpiece3, objectCarMirrorFixpiece4, objectCarMirrorFixpiece5,
		objectCarMirrorFixpiece6, objectCarMirrorFixpiece7, objectCarMirrorFixpiece8,
		objectCarMirrorFixpiece9,
	}
	
	local find =
	{
		objectCarMirrorPiece0, objectCarMirrorPiece1, objectCarMirrorPiece2,
		objectCarMirrorPiece3, objectCarMirrorPiece4, objectCarMirrorPiece5,
		objectCarMirrorPiece6, objectCarMirrorPiece7, objectCarMirrorPiece8,
		objectCarMirrorPiece9,
	}
	
	local mirror = 
	{
		objectCarMirrorSmallFixpiece0, objectCarMirrorSmallFixpiece1, objectCarMirrorSmallFixpiece2,
		objectCarMirrorSmallFixpiece3, objectCarMirrorSmallFixpiece4, objectCarMirrorSmallFixpiece5,
		objectCarMirrorSmallFixpiece6, objectCarMirrorSmallFixpiece7, objectCarMirrorSmallFixpiece8,
		objectCarMirrorSmallFixpiece9,
	}
	
	LayoutJigsaw.onConstruct(self)
	LayoutJigsaw.setup(self, pieces, correct, nil, mirror, objectHoCarMirrorGroup, objectCarMirrorBackground, objectIoCarMirrorRotateButton)

end
-- ----------------------------------------------------------------------------
function layoutCarMirror:onInitialize()

	LayoutJigsaw.onInitialize(self)

	objectCarMirrorBackground:ss(kActive)
	objectCarMirrorSolved:ss(kInactive)
	objectCarMirrorShine:ss(kDone)
	
	for i, piece in ipairs(self.mPieces) do
		piece:relocatePivotPoint("center")
	end
	
	objectCarMirrorNotfixedpiece0:setRotation(math.pi)
	objectCarMirrorNotfixedpiece0:setX(46)
	objectCarMirrorNotfixedpiece0:setY(14)
	objectCarMirrorNotfixedpiece1:setRotation(math.pi * 1.5)
	objectCarMirrorNotfixedpiece1:setX(-17)
	objectCarMirrorNotfixedpiece1:setY(109)	
	objectCarMirrorNotfixedpiece2:setRotation(math.pi * 1.5)
	objectCarMirrorNotfixedpiece2:setX(590)
	objectCarMirrorNotfixedpiece2:setY(104)		
	objectCarMirrorNotfixedpiece3:setRotation(math.pi)
	objectCarMirrorNotfixedpiece3:setX(294)
	objectCarMirrorNotfixedpiece3:setY(338)		
	objectCarMirrorNotfixedpiece4:setRotation(math.pi)
	objectCarMirrorNotfixedpiece4:setX(110)
	objectCarMirrorNotfixedpiece4:setY(65)		
	objectCarMirrorNotfixedpiece5:setRotation(math.pi * 0.5)
	objectCarMirrorNotfixedpiece5:setX(581)
	objectCarMirrorNotfixedpiece5:setY(356)		
	objectCarMirrorNotfixedpiece6:setRotation(math.pi)
	objectCarMirrorNotfixedpiece6:setX(24)
	objectCarMirrorNotfixedpiece6:setY(337)		
	objectCarMirrorNotfixedpiece7:setRotation(math.pi * 1.5)
	objectCarMirrorNotfixedpiece7:setX(572)
	objectCarMirrorNotfixedpiece7:setY(213)		
	objectCarMirrorNotfixedpiece8:setRotation(math.pi)
	objectCarMirrorNotfixedpiece8:setX(399)
	objectCarMirrorNotfixedpiece8:setY(374)		
	objectCarMirrorNotfixedpiece9:setRotation(math.pi)		
	objectCarMirrorNotfixedpiece9:setX(390)
	objectCarMirrorNotfixedpiece9:setY(29)		
	
	for i, piece in ipairs(self.mPieces) do
		piece:relocatePivotPoint("topleft")
	end	

end
-- ----------------------------------------------------------------------------
function layoutCarMirror:onSolve()

	LayoutJigsaw.onSolve(self)

	objectCarMirrorSolved:ss(kIdle)
	
end
-- ----------------------------------------------------------------------------
function layoutCarMirror:onSolveStart()

	LayoutJigsaw.onSolveStart(self)

	self:animate("CloseMirror_blocking",
		{ delay = 2000 },
		{ call = layoutCarMirror.solveFinish }
	)

end
-- ----------------------------------------------------------------------------
function layoutCarMirror:isSkippable()
	return objectHoCarMirrorGroup:isUsed()
end
-- ----------------------------------------------------------------------------
function layoutCarMirror:onQuickPlay()
	objectHoCarMirrorGroup:ss(kFound)
end
-- ----------------------------------------------------------------------------
function layoutCarMirror:playPlacedSound()
	playAudioTrack("MIRROR_PIECE_PLACED")
end
-- ----------------------------------------------------------------------------
function layoutCarMirror:playConnectSound()
	playAudioTrack("MIRROR_PIECE_PLACED")
end