class 'VideoHelpers'

function VideoHelpers:__init(is_movie)
	self.is_movie		= is_movie or false
end

function VideoHelpers:Create(video_path, sound_path, is_alpha, is_cycled, parent)
	self.video_path 	= video_path
	self.sound_path 	= sound_path
	
	self.is_alpha 		= is_alpha or false
	self.is_cycled 		= is_cycled or false
	
	self.parent			= parent and parent or play_field
	
	self.x				= 512
	self.y				= 384
	self.z				= 99
	
	self.scale			= 1
	self.scale_x		= 1
	self.scale_y		= 1
	
	self.smooth			= 0
	self.duration		= nil
	
	self.is_cutscene	= false
	
	self.callback		= nil
	self.callback_delay = 0
	
	self.is_destroy		= false
	
	if self.is_movie then
		self.video = CreateMovieEntity()
		self.video:SetRepeat(self.is_cycled)
		local video = CreateVideoEntity(self.video_path, '', false)
		self.duration = video:GetDuration()
		video:DestroyVideo()
		video = nil
		self.video:SetDestroyOnEnd(self.is_destroy)
	else
		self.video = CreateVideoEntity(self.video_path, self.sound_path, self.is_alpha)
		self.video:SetLoop(self.is_cycled)
		self.duration = self.video:GetDuration()
	end
	
	self.video:AttachTo(self.parent)
	self.video:SetXY(self.x, self.y)
	self.video:SetZ(self.z)
	
end

function VideoHelpers:Play()
	assert(self.video)
	local level = GetCurrentLevel()
	
	if self.is_cutscene then
		level.mouseBlocker:Push()
		level:ShowCutsceneBars()
		level.timer:Add(function()
							level.mouseBlocker:Pop()
							level:HideCutsceneBars()
						end,
						self.duration)
	end
	
	if self.is_movie then
		self.video:PlayMovie(self.video_path, self.sound_path)
	else
		self.video:PlayVideo()
		if self.is_destroy and not self.is_cycled then
			level.timer:Add(function()
								self.video:Destroy()
							end, self.duration + 0.1)
		end
	end

	if not self.is_cycled and self.smooth > 0 then
		self.video:ChangeOpacity(1, 0, self.smooth, self.duration - self.smooth)
	end

	if self.callback then
		level.timer:Add(self.callback, self.duration + self.callback_delay)
	end
end

function VideoHelpers:Stop()
	assert(self.video)
	
	if self.is_movie then
		self.video:StopMovie()
	else
		self.video:StopVideo()
	end
end

function VideoHelpers:SetXY(x, y)
	self.x = x or 512
	self.y = y or 384
	
	assert(self.video)
	
	self.video:SetXY(self.x, self.y)
end

function VideoHelpers:SetX(x)
	self.x = x or 512
	
	assert(self.video)
	
	self.video:SetX(self.x)
end

function VideoHelpers:SetY(y)
	self.y = y or 384
	
	assert(self.video)
	
	self.video:SetY(self.y)
end

function VideoHelpers:SetScrXY(x, y)
	self.scr_x = x or 512
	self.scr_y = y or 384
	
	assert(self.video)
	
	self.video:SetScrXY(self.scr_x, self.scr_y)
end

function VideoHelpers:SetZ(z)
	self.z = z or 99
	
	assert(self.video)
	
	self.video:SetZ(self.z)
end

function VideoHelpers:GetX()
	return self.x
end

function VideoHelpers:GetY()
	return self.y
end

function VideoHelpers:GetZ()
	return self.z
end

function VideoHelpers:SetScale(scale)
	self.scale = scale or 1
	
	assert(self.video)
	
	self.video:SetScale(self.scale)
end

function VideoHelpers:SetScaleX(scale)
	self.scale_x = scale or 1
	
	assert(self.video)
	
	self.video:SetScaleX(self.scale_x)
end

function VideoHelpers:SetScaleY(scale)
	self.scale_y = scale or 1
	
	assert(self.video)
	
	self.video:SetScaleY(self.scale_y)
end

function VideoHelpers:GetScale()
	return	self.scale
end

function VideoHelpers:GetScaleX()
	return	self.scale_x
end

function VideoHelpers:GetScaleY()
	return	self.scale_y
end

function VideoHelpers:SetSmooth(time)
	self.smooth = time or 0
end

function VideoHelpers:SetDuration(time)
	self.duration = time or self.duration
end

function VideoHelpers:GetDuration()
	return self.duration
end

function VideoHelpers:SetCutscene(is_cutscene)
	self.is_cutscene = is_cutscene or false
end

function VideoHelpers:CallBack(callback, delay)
	self.callback = callback
	self.callback_delay = delay or 0
end

function VideoHelpers:AttachTo(parent)
	assert(self.video)
	
	self.parent = parent or play_field
	self.video:AttachTo(self.parent)
end

function VideoHelpers:DestroyOnEnd(is_destroy)
	self.is_destroy = is_destroy or false
	if self.is_movie then
		assert(self.video)
		self.video:SetDestroyOnEnd(self.is_destroy)
	end
end

function VideoHelpers:SetHideOnStop(is_hideOnStop)
    if not self.is_movie then
        assert(self.video)
		self.video:SetHideOnStop(is_hideOnStop)
    end
end

function VideoHelpers:SetOnFirstFrame()
    if not self.is_movie then
        assert(self.video)
		self.video:SetOnFirstFrame()
    end
end

function VideoHelpers:Seek(time)
    if not self.is_movie then
        assert(self.video)
		self.video:Seek(time)
    end
end

function VideoHelpers:SetBlendMode(mode)
	assert(self.video)
	self.video:SetBlendMode(mode)
end

function VideoHelpers:IsPlaying()
    assert(self.video)
	return self.video:IsPlaying()
end

function VideoHelpers:SetSoftEdges(do_soft)
    assert(self.video)
	return self.video:SetSoftEdges(do_soft)
end