-- WARNING:
-- uses abstract layoutConnector puzzle!
-- ----------------------------------------------------------------------------
assert(LayoutConnector ~= nil)
setmetatable(layoutWoods1Battery, LayoutConnector)
-- ----------------------------------------------------------------------------
layoutWoods1Battery.mIOs = 
{
	[objectIoWireBatteryLocation] =
	{
		links = {objectHoWiresBattery},
		cursor = kCursorDefault
	}
}
-- ----------------------------------------------------------------------------
layoutWoods1Battery.mFirstTime = true
-- ----------------------------------------------------------------------------
function layoutWoods1Battery:onConstruct()

	local connections =
	{
		[objectWireDConnection4] = {objectIoWireSourceD, objectIoWireDestinationD, true},
		[objectWireDConnection3] = {objectIoWireSourceD, objectIoWireDestinationC},
		[objectWireDConnection2] = {objectIoWireSourceD, objectIoWireDestinationB},
		[objectWireDConnection1] = {objectIoWireSourceD, objectIoWireDestinationA},
		
		[objectWireCConnection4] = {objectIoWireSourceC, objectIoWireDestinationD},
		[objectWireCConnection3] = {objectIoWireSourceC, objectIoWireDestinationC},
		[objectWireCConnection2] = {objectIoWireSourceC, objectIoWireDestinationB, true},
		[objectWireCConnection1] = {objectIoWireSourceC, objectIoWireDestinationA},
		
		[objectWireBConnection4] = {objectIoWireSourceB, objectIoWireDestinationD},
		[objectWireBConnection3] = {objectIoWireSourceB, objectIoWireDestinationC},
		[objectWireBConnection2] = {objectIoWireSourceB, objectIoWireDestinationB},
		[objectWireBConnection1] = {objectIoWireSourceB, objectIoWireDestinationA, true},
		
		[objectWireAConnection4] = {objectIoWireSourceA, objectIoWireDestinationD},
		[objectWireAConnection3] = {objectIoWireSourceA, objectIoWireDestinationC, true},
		[objectWireAConnection2] = {objectIoWireSourceA, objectIoWireDestinationB},
		[objectWireAConnection1] = {objectIoWireSourceA, objectIoWireDestinationA,},						
	}
	
	LayoutConnector.onConstruct(self)
	LayoutConnector.setup(self, connections)

end
-- ----------------------------------------------------------------------------
function layoutWoods1Battery:onInitialize()

	LayoutConnector.onInitialize(self)
	
	objectIoWireBatteryLocation:ss(kActive)
	objectWiresBatteryConnectionTop:ss(kInactive)
	objectIoWireSourceA:ss(kIdle)
	objectIoWireSourceB:ss(kIdle)
	objectIoWireSourceC:ss(kIdle)
	objectIoWireSourceD:ss(kIdle)
	objectIoWireDestinationA:ss(kInactive)
	objectIoWireDestinationB:ss(kInactive)
	objectIoWireDestinationC:ss(kInactive)
	objectIoWireDestinationD:ss(kInactive)
	objectWireDConnection4:ss(kInactive)
	objectWireDConnection3:ss(kInactive)
	objectWireDConnection2:ss(kInactive)
	objectWireDConnection1:ss(kInactive)
	objectWireCConnection4:ss(kInactive)
	objectWireCConnection3:ss(kInactive)
	objectWireCConnection2:ss(kInactive)
	objectWireCConnection1:ss(kInactive)
	objectWireBConnection4:ss(kInactive)
	objectWireBConnection3:ss(kInactive)
	objectWireBConnection2:ss(kInactive)
	objectWireBConnection1:ss(kInactive)
	objectWireAConnection4:ss(kInactive)
	objectWireAConnection3:ss(kInactive)
	objectWireAConnection2:ss(kInactive)
	objectWireAConnection1:ss(kInactive)	

end
-- ----------------------------------------------------------------------------
function layoutWoods1Battery:onShow()
	
	LayoutConnector.onShow(self)
	
	if (self.mFirstTime) then
		if (not objectHoWiresBattery:isFound() and
		    not objectHoWiresBattery:isSelected()) then
		   think("MESSAGE_WIRES") 
		end
		self.mFirstTime = false
	end

end
-- ----------------------------------------------------------------------------
function layoutWoods1Battery:onUsedAll(object, props)

	LayoutConnector.onUsedAll(self, object, props)
	
	if (object == objectIoWireBatteryLocation) then
		objectWiresBatteryConnectionTop:ss(kActive)
		objectIoWireSourceA:ss(kActive)
		objectIoWireSourceB:ss(kActive)
		objectIoWireSourceC:ss(kActive)
		objectIoWireSourceD:ss(kActive)	
		objectBatteryFixed:ss(kIdle)
		objectBatterySparks:ss(kDone)
	end

end
-- ----------------------------------------------------------------------------
function layoutWoods1Battery:onQuickPlay()

	LayoutConnector.onQuickPlay(self)

	-- need wires in inventory
	objectHoWiresBattery:ss(kFound)

end
-- ----------------------------------------------------------------------------
function layoutWoods1Battery:onSolveStart()

	LayoutConnector.onSolveStart(self)
	
	self:animate("CloseBattery_blocking",
		{ delay = 2000 },
		{ call = layoutWoods1Battery.solveFinish }
	)		

end
-- ----------------------------------------------------------------------------
function layoutWoods1Battery:onSolveFinish()

	objectPoiBattery:ss(kInactive)
	
	Layout.onSolveFinish(self)
	
end
-- ----------------------------------------------------------------------------
function layoutWoods1Battery:isSkippable()
	return objectHoWiresBattery:isUsed()
end
-- ----------------------------------------------------------------------------
function layoutWoods1Battery:playConnectSound(connection)
	playAudioTrack("ELECTRIC_SHOCK")
	
	assert(connection)
	assert(self.mConnections[connection])
	assert(self.mConnections[connection][2])
	local destination = self.mConnections[connection][2]
	
	destination:newChildParticle( { x=-25, y=-25, library="PARTICLE_BASEMENT_FUSEBOX_SPARKLE", section="particles", play=true, removeWhenFinished=true } )
end
-- ----------------------------------------------------------------------------
function layoutWoods1Battery:playDisconnectSound(connection)
end