"use strict";
cc._RF.push(module, '9129bZ2zN5I673xCbm79sLC', 'StartScene');
// Script/StartScene.ts

"use strict";
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
var Global_1 = require("./Global");
var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
var StartScene = /** @class */ (function (_super) {
    __extends(StartScene, _super);
    function StartScene() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.paihangbang = null;
        // LIFE-CYCLE CALLBACKS:
        _this.mainNode = null;
        _this.UpAni = null;
        _this.DownAni = null;
        /**
         * 玩家信息
         */
        _this.USERINFO = {
            userId: '12312313',
            score: 0,
        };
        _this.channel = "test";
        return _this;
    }
    StartScene.prototype.onLoad = function () {
        console.log("find --------------------1");
        // // this.LifeDing.zIndex = 5;
        // cc.sys.localStorage.removeItem("info");
        var infostr = cc.sys.localStorage.getItem("info");
        if (infostr == null || infostr == undefined || infostr == "") {
            infostr = { userId: '', score: 0, };
            infostr = JSON.stringify(infostr);
            cc.sys.localStorage.setItem("info", infostr);
        }
        console.log("------------------4 : " + infostr);
        this.USERINFO = JSON.parse(infostr);
        if (this.USERINFO == null || this.USERINFO == undefined) {
            this.USERINFO = {
                userId: '',
                score: 0,
            };
            this.LoadData();
            console.log("------------------5");
            this.USERINFO = JSON.parse(cc.sys.localStorage.getItem("info"));
        }
        Global_1.default.instance.setSN(this);
        Global_1.default.instance.OverFlag = false;
        var startNode = this.node.getChildByName("BgNode").getChildByName("kaiji");
        var Ani = startNode.getComponent(cc.Animation);
        var Anistate = Ani.play("kaiji");
        Anistate.wrapMode = cc.WrapMode.Loop;
        this.UpAni = startNode.getChildByName("Up").getComponent(cc.Animation);
        this.DownAni = startNode.getChildByName("Down").getComponent(cc.Animation);
        console.log("find --------------------1#");
    };
    StartScene.prototype.start = function () {
        var self = this;
        // self.USERINFO.userId = "playerB10";
        // self.USERINFO.score = 0;
        self.scheduleOnce(function () {
            Global_1.default.instance.SetUser(self.USERINFO);
            Global_1.default.instance.Channel = self.channel;
            //this.Login();
        }, 0.5);
    };
    StartScene.prototype.update = function (dt) {
        // cc.systemEvent.on(cc.SystemEvent.EventType.KEY_DOWN,this.onKeyBackSpace,this);
        // cc.systemEvent.on(cc.SystemEvent.EventType.KEY_DOWN,this.onKeyDown,this);
    };
    /**
     * start game
     */
    StartScene.prototype.StartGame = function () {
        var self = this;
        var startTime = Date.now();
        var endTime;
        Global_1.default.instance.OverFlag = false;
        Global_1.default.instance.AniFalg = false;
        Global_1.default.instance.LorR = 0;
        Global_1.default.instance.InitSpeed = 8.5;
        Global_1.default.instance.moveSpeed = 1;
        Global_1.default.instance.FHFallSpeed = 2;
        cc.sys.localStorage.setItem("hfsj", "99");
        self.UpAnistate = self.UpAni.play();
        self.DownAnistate = self.DownAni.play();
        self.scheduleOnce(function () {
            self.node.runAction(cc.sequence(cc.fadeOut(0.5), cc.callFunc(function () {
                cc.director.loadScene("MainScene");
                endTime = Date.now();
                if (endTime - startTime > 330) {
                    self.destroy();
                }
                console.log("场景跳转成功");
            })));
        }, 0.33);
    };
    /**
     * use the backSpace start game
     * @param event
     */
    StartScene.prototype.onKeyBackSpace = function (event) {
        if (event.keyCode == cc.KEY.space) {
            this.StartGame();
        }
    };
    /**
 * 登录
 */
    StartScene.prototype.Login = function () {
        var self = this;
        var channelStr = Global_1.default.instance.Channel;
        var uNam = Global_1.default.instance.GetUSer().userId;
        /* Http.sendRequest("/login",{channel:channelStr,userId:uNam},function(msg){
              console.log("------------------6");
             let code = JSON.parse(msg.code);
             console.log(code);
             if(code!=0){
                 Global.instance.NetStatus = false;
             }
              console.log("------------------7");
             let mmsg = JSON.parse(msg.msg);
             self.USERINFO.userId = mmsg.userId;
             self.USERINFO.score = mmsg.score;
             Global.instance.getLocalScore().BestScore = mmsg.score;
             Global.instance.SetUser(self.USERINFO);
         });*/
        var ux = {
            userId: '',
        };
        ux.userId = channelStr + Global_1.default.instance.GetUSer().userId;
        /* Http.sendRequest("/rank",ux,function(mmsg){
              console.log("------------------8");
             let MM = JSON.parse(mmsg.msg);
             console.log(MM);
             if(Global.instance.GetR()==null||Global.instance.GetR().rank==undefined||Global.instance.GetR().rank<MM.my.rank){
                 Global.instance.SetR(MM.my.rank);
                 Global.instance.SetS(MM.other);
             }
         });*/
    };
    //需要更多源码联系Q:852183691
    //或者
    //关注微信公众号“史于二”
    StartScene.prototype.CheckRank = function () {
        this.destroy();
        cc.director.loadScene("EndScene");
    };
    StartScene.prototype.IdGenerater = function () {
        var str = "";
        var suffix = "";
        var Id;
        var Word;
        for (var i = 0; i < 2; i++) {
            var ranNum = Math.ceil(Math.random() * 25);
            Word = String.fromCharCode(65 + ranNum);
            str += Word;
        }
        for (var i = 0; i < 7; i++) {
            var suffixNum = Math.ceil(Math.random() * 9);
            suffix += suffixNum.toString();
        }
        Id = str + suffix;
        return Id;
    };
    StartScene.prototype.LoadData = function () {
        var self = this;
        var id = self.IdGenerater();
        self.USERINFO.userId = id;
        self.USERINFO.score = 0;
        cc.sys.localStorage.setItem("info", JSON.stringify(self.USERINFO));
        // cc.sys.localStorage.removeItem("info");
        // let url = cc.url.raw("resources/INFO/data.json");
        // let infotem;
        // cc.loader.load(url,function(err,res){
        //     if(err){
        //     console.log("load"+url,err+"err result:"+JSON.stringify(res));
        //     }
        //     infotem = res;
        // });
    };
    __decorate([
        property(cc.Prefab)
    ], StartScene.prototype, "paihangbang", void 0);
    StartScene = __decorate([
        ccclass
    ], StartScene);
    return StartScene;
}(cc.Component));
exports.default = StartScene;
/**
 * 联网登录放在开始游戏的时候，期间获取一次排行数据
 * 这里有一个逻辑上的问题：如果第一次玩的分数是0，就
 */

cc._RF.pop();