local CharacterInfoTemplates = {}

-------------------------------------------------------------------------------
-- COMICS FRAME FUNCTIONS
-------------------------------------------------------------------------------

function CreateComicsFrame(characterName, caption, sound, ...)
    return ComicsFrame(characterName, caption, sound, ...)
end
-------------------------------------------------------------------------------

function CreateComicsAnimationFrame(characterName, caption, sound, animation, ...)
    local frame = ComicsFrame(characterName, caption, sound, ...)
    frame:SetAnimation(animation)
	
	return frame
end
-------------------------------------------------------------------------------

function CreateComicsVideoFrame(characterName, caption, sound, videoInfo, ...)
    local frame = ComicsFrame(characterName, caption, sound, ...)
    
    local speechVideoPath, idleVideoPath
    
    local softEdges = false
    local alpha     = false
    
    local x = SCR_W/2
    local y = SCR_H/2
    local sx = 1
    local sy = 1
    local softSizeX = 20
    local softSizeY = 20
    
    if type(videoInfo) == 'string' then
        speechVideoPath = videoInfo
        
    elseif type(videoInfo) == 'table' then
        speechVideoPath = videoInfo.path
        idleVideoPath   = videoInfo.path_idle
        
        x  = videoInfo.x  or x
        y  = videoInfo.y  or y
        
        if videoInfo.scale then
            sx = videoInfo.scale
            sy = videoInfo.scale
        end
        
        sx = videoInfo.sx or sx
        sy = videoInfo.sy or sy
        
        softSizeX = videoInfo.softSizeX or softSizeX
        softSizeY = videoInfo.softSizeY or softSizeY
        
        if videoInfo.isAlpha ~= nil then
            alpha = videoInfo.isAlpha
        end
        
        if videoInfo.isSoftEdges ~= nil then
            softEdges = videoInfo.isSoftEdges
        end
    end
    
    if speechVideoPath then
        frame:CreateSpeechVideo(speechVideoPath, alpha, softEdges, x, y, sx, sy, softSizeX, softSizeY)
    end
    
    if idleVideoPath then
        frame:CreateIdleVideo(idleVideoPath, alpha, softEdges, x, y, sx, sy)
    end
	
	return frame
end
-------------------------------------------------------------------------------



-------------------------------------------------------------------------------
-- COMCIS FUNCTIONS
-------------------------------------------------------------------------------

function GetCharacterInfo(name)
    if CharacterInfoTemplates[name] then
        return CharacterInfoTemplates[name]
    end

    local info      = {}
    info.character  = name
    info.font       = COMICS_FONT
    info.color      = '0xFFFFFFFF'
    info.scale      = 0.55
    info.width      = 960
    info.height     = 110
    info.spacing    = 0.8
    info.tracking   = 0
	info.alignment  = HGETEXT_TOP + HGETEXT_JUSTIFIED
	info.x          = -480
	info.y          = -40
	info.z          = 2
	
	if name == 'Villain' then
    elseif name == 'Mike' then
    elseif name == '' then
	end

    CharacterInfoTemplates[name] = info
    return info
end
-----------------------------------------------------------------------------------

function UpdateComicsRequest()
    local level  = GetCurrentLevel()
    local comics = level.comics
    
    if comics and comics:IsVisible() then
        if not comics:IsChangingFrame() then
            
            if comics:IsCtcVisible() and (not comics.changeFrameCondition or comics:changeFrameCondition(comics)) then
                comics:ShowNextFrame()
                
                level.updateComicsTimerAction = nil
            end
        elseif not level.updateComicsTimerAction then
            level.updateComicsTimerAction = level.timer:Add(UpdateComicsRequest, 0.05)
        end
    end
end
-----------------------------------------------------------------------------------

function IsComicsShown(name)
    return HasGameState(COMICS_SHOWN, name)
end
-----------------------------------------------------------------------------------