require "common"

function PlayComics( comics )
    if comics == nil then
        return 
    end
    local objComics = obj( comics, obj( "comics" ) )
    local objAnim = obj( "anmcomicscript", objComics )
    call( objAnim, "play" )
    set( objComics, "visible", true )
    set( "game.locations", "enabled", false )
    call( "ComicsTrack", "Play" )
    call( "gametracks", "Stop" )
    call( "menutrack", "Stop" )
    while (get( objAnim, "playing" ) == "true") do
        wait( 0.01 )
    end
    call( "ComicsTrack", "Stop" )
    log( "stopped comics" .. comics )
    set( "game.locations", "enabled", true )
    set( objComics, "visible", false )
end

function GetLocationProgress( sLocation )
    local objVarRoot = obj( "variables.locations" )
    local objVar = nil
    for i, v in ipairs( children( objVarRoot ) ) do
        if (get( v, "name" ) == sLocation ) then
            objVar = v
            break
        end
    end
    if (objVar == nil) then
        objVar = create( "var", sLocation, objVarRoot )
        set( objVar, "value", 0 )
    end
    return tonumber( get( objVar, "value" ) )
end

function SetLocationProgress( sLocation, nProgress )
    local objVarRoot = obj( "variables.locations" )
    local objVar = obj( sLocation, objVarRoot )
    set( objVar, "value", nProgress )
end


