-- ************************************ Station ************************************ --
DiapersStockStation = deriveLuaClass("DiapersStockStation", "WorkStation")

function DiapersStockStation:init(desc)
	self.workAnimationFrameTime = 100
	DiapersStockStation.superInit(desc)
end

function DiapersStockStation:onLevelInitialized()
	level:getSpriteExt("diaper_stock"):setFrame(self.stock-1)
end

function DiapersStockStation:hasWorkToDo()
	return true
end

function DiapersStockStation:addToStationTask()
	if (DiapersStockStation.super.addToStationTask(self)) then
		return true
	end
	self:stopFaultySelectionBlink()
	return false
end

function DiapersStockStation:onDisplayStockChange()
	if (self.stock == 0) then
		level:getSpriteExt("diaper_stock").visible = false
	else
		level:getSpriteExt("diaper_stock").visible = true
		level:getSpriteExt("diaper_stock"):setFrame(self.stock-1)
		self:removeOverhead()
	end
end

function DiapersStockStation:onWorkStart(task)
	local r = DiapersStockStation.super.onWorkStart(self, task)
	if (self.stock == self.maxStock) then
		return false
	end
	hero:playAnimation(self.workAnimation, -1, "default", self.workAnimationFrameTime)
	task.duration = self.workDuration
	self:playSample("SND_RESTOCK_DIAPERS:sound")
	return r
end

function DiapersStockStation:onWorkFinish(task)
	DiapersStockStation.super.onWorkFinish(self, task)
	self:resetStock()
	self:onDisplayStockChange()
end
