//游戏端配置
let gameConfig = {
    limitFpsFlag: $LIMIT_FPS_FLAG$,//限制帧率[bool]
    limitFps: $LIMIT_FPS$,//帧率值[number]
}

//banner条广告参数
let bannerParam = {
    enable: $BANNER_ENABLE$,//开关,[bool]
    interval: $BANNER_INTERVAL$,//刷新间隔（单位秒）不小于30s[number]
    posId: $BANNER_POS_ID$,//banner广告位ID,[string]
    bottom: $BANNER_BOTTOM$,//1表示底部banner，0表示顶部banner[number]
}

//插页广告参数
let intersParam = {
    enable: $INTERS_ENABLE$,//开关[bool]
    cooldown: $INTERS_COOL_DOWN$,//插屏冷却时间（单位秒）[number]
    posId: $INTERS_POS_ID$,//插屏广告位ID[string]
}

//视频广告参数
let videoParam = {
    enable: $VIDEO_ENABLE$,//开关[bool]
    resetIntersCool: $VIDEO_RESET_INTERS_COOL$,//视频播放后x秒不弹插页,-1为不控制[number]
    posId: $VIDEO_POS_ID$,//视频广告位ID[string]
}


//隐私协议文案
let privacyMessage = `$PRIVACY_MESSAGE$`;

//事件上报参数
let trackParam = {
    //友盟appkey
    umaAppKey: `$UMA_APP_KEY$`,
    //是否开启事件上报
    enableTrackPlugin: $ENABLE_TRACK$,
}

//设置帧率
if (gameConfig.limitFpsFlag) {
    console.log('限制帧率', gameConfig.limitFps);
    qg.setPreferredFramesPerSecond(gameConfig.limitFps);
}

//请求调试服务器
function requestTPDebugger() {
    console.log('请求TPDebugger调试服务器...');
    var done = false;
    let xhr = new XMLHttpRequest();
    xhr.timeout = 3000;
    xhr.open('GET', 'http://127.0.0.1:51824/home');
    xhr.onload = () => {
        if (done) {
            return;
        }
        done = true;
        if (xhr.status == 200 && xhr.responseText && xhr.responseText == 'ok') {
            console.log('TPDebugger调试服务器 开启！TP_DEBUG_MODE= TRUE');
            //开启调试服务器
            window['TP_DEBUG_MODE'] = "on";

        } else {
            console.log('TPDebugger调试服务器 关闭！TP_DEBUG_MODE = FALSE');
            //关闭调试
            window['TP_DEBUG_MODE'] = "off";
        }
    };
    xhr.onerror = () => {
        console.log('TPDebugger调试服务器请求失败！ TP_DEBUG_MODE = FALSE');
        if (done) {
            return;
        }
        done = true;
        window['TP_DEBUG_MODE'] = "off";
    }
    xhr.ontimeout = () => {
        console.log('TPDebugger调试服务器 超时！TP_DEBUG_MODE = FALSE');
        //关闭调试
        if (done) {
            return;
        }
        done = true;
        window['TP_DEBUG_MODE'] = "off";
    };
    xhr.send();
}

requestTPDebugger();

window['minisdkConfig'] = { gameConfig, bannerParam, intersParam, videoParam, privacyMessage, trackParam }
console.log('minisdkConfig 注入成功');