let gameConfig = require("GameConfig");
let library = require("../Library");
let webView = require("../WebView");
cc.Class({
    extends: cc.Component,

    properties: {
        gameStates: {
            default: null,
            type: cc.Node,
            serializable: true,
        },
        playerStates0:{
            default: null,
            type: cc.Node,
            serializable: true,
        },
        miss: {
            default: null,
            type: cc.Label,
            serializable: true,
        },
        hit: {
            default: null,
            type: cc.Label,
            serializable: true,
        },
        kCal: {
            default: null,
            type: cc.Label,
            serializable: true,
        },
        time: {
            default: null,
            type: cc.Label,
            serializable: true,
        },
        resultBarSp:{
            default: null,
            type: cc.Node,
            serializable: true,
        },
        winBarFrame:{
            default: null,
            type: cc.SpriteFrame,
            serializable: true,
        },
        defeatBarFrame:{
            default: null,
            type: cc.SpriteFrame,
            serializable: true,
        },
    },
    setResult()
    {
        this.gStatesScp = this.gameStates.getComponent('GameStates');
        this.pStatesScp0 = this.gStatesScp.playerStatesArr[0];
        this.pStatesScp1 = this.gStatesScp.playerStatesArr[1];
        if(this.pStatesScp0.hit>this.pStatesScp1.hit)
        {
            this.resultBarSp.spriteFrame = this.winBarFrame;
        }
        else
        {
            this.resultBarSp.spriteFrame = this.defeatBarFrame;
        }

        // this.miss.string = this.pStatesScp0.miss;
        this.hit.string = this.pStatesScp0.hit;
        this.kCal.string = 'Burn Calories: '+(this.pStatesScp0.hit*gameConfig.kCalPerTime).toFixed(4);
        this.time.string = 'Time: '+library.formatSeconds(gameConfig.roundTime-this.gStatesScp.currentTime);

        if(!cc.sys.isMobile) return;
        let kCal = this.pStatesScp0.hit*webView.kCalUnit;
        webView.uploadInfo(this.pStatesScp0.hit,this.gStatesScp.currentTime, kCal);
    }
});
