
                (function() {
                    var nodeEnv = typeof require !== 'undefined' && typeof process !== 'undefined';
                    var __module = nodeEnv ? module : {exports:{}};
                    var __filename = 'preview-scripts/assets/Script/GameOver.js';
                    var __require = nodeEnv ? function (request) {
                        return cc.require(request);
                    } : function (request) {
                        return __quick_compile_project__.require(request, __filename);
                    };
                    function __define (exports, require, module) {
                        if (!nodeEnv) {__quick_compile_project__.registerModule(__filename, module);}"use strict";
cc._RF.push(module, '805c6nf399HWZeuWnNB9CTH', 'GameOver');
// Script/GameOver.ts

"use strict";
// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
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 GameData_1 = require("./GameData");
var serverAPI_1 = require("./crypto/serverAPI");
var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
var NewClass = /** @class */ (function (_super) {
    __extends(NewClass, _super);
    function NewClass() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.count = null;
        _this.time = null;
        _this.selfNode = null;
        _this.one = null;
        _this.two = null;
        _this.three = null;
        _this.four = null;
        _this.five = null;
        return _this;
    }
    // onLoad () {}
    NewClass.prototype.start = function () {
        this.count.string = GameData_1.default._instance.GM_INFO.total;
        if (GameData_1.default._instance.GM_INFO.mean_Time > 10) {
            GameData_1.default._instance.GM_INFO.mean_Time = (parseInt(Math.random() * 10 + "") + 5) / 10;
        }
        this.time.string = GameData_1.default._instance.GM_INFO.mean_Time + "s";
        this.init();
    };
    //初始化数据
    NewClass.prototype.init = function () {
        this.listData = [];
        this.selfData = null;
        this.one.active = false;
        this.two.active = false;
        this.three.active = false;
        this.four.active = false;
        this.five.active = false;
        this.getRank();
    };
    //打开排行榜
    NewClass.prototype.openRank = function () {
        cc.director.loadScene("RankScene");
    };
    //重新开始玩
    NewClass.prototype.again = function () {
        cc.director.loadScene("GameScene");
    };
    //获取排行榜
    NewClass.prototype.getRank = function () {
        var postData = {
            "page": 1,
            "pageSize": 100
        };
        serverAPI_1.default.rankData(2, this.getRankData.bind(this), postData);
    };
    //设置排行信息
    NewClass.prototype.getRankData = function (data) {
        if (data) {
            this.listData = data.data.list;
            this.selfData = data.data.info;
            var rankData = [];
            var self = false;
            if (this.selfData.nickName.length > 4) {
                this.selfData.nickName = this.selfData.nickName.substring(0, 4) + "...";
            }
            this.selfNode.getChildByName("name").getComponent(cc.Label).string = this.selfData.nickName;
            this.selfNode.getChildByName("total").getComponent(cc.Label).string = this.selfData.totalSunCount;
            this.setPic(this.selfNode.getChildByName("pic").getChildByName("icon"), this.selfData.pic);
            for (var i = 0; i <= this.listData.length - 1; i++) {
                rankData.push({ rank: (i + 1), name: this.listData[i].nickName, total: this.listData[i].totalSunCount, pic: this.listData[i].pic });
                if (GameData_1.default._instance.GM_INFO.userId == this.listData[i].userId) {
                    self = true;
                    this.selfNode.getChildByName("rank").getComponent(cc.Label).string = (i + 1) + "";
                }
                if (i == (this.listData.length - 1) && self == false) {
                    this.selfNode.getChildByName("rank").getComponent(cc.Label).string = "99+";
                }
                if (i < 5)
                    this.setRank(i, this.listData[i]);
            }
        }
    };
    //根据内容填充排行榜
    NewClass.prototype.setRank = function (num, data) {
        var hitNode = null;
        if (num == 0) {
            hitNode = this.one;
        }
        else if (num == 1) {
            hitNode = this.two;
        }
        else if (num == 2) {
            hitNode = this.three;
        }
        else if (num == 3) {
            hitNode = this.four;
        }
        else if (num == 4) {
            hitNode = this.five;
        }
        if (hitNode) {
            hitNode.active = true;
            if (data.nickName.length > 4) {
                data.nickName = data.nickName.substring(0, 4) + "...";
            }
            hitNode.getChildByName("name").getComponent(cc.Label).string = data.nickName;
            hitNode.getChildByName("total").getComponent(cc.Label).string = data.totalSunCount;
            this.setPic(hitNode.getChildByName("pic").getChildByName("icon"), data.pic);
        }
    };
    //设置头像
    NewClass.prototype.setPic = function (node, pic) {
        node.active = false;
        var url = pic;
        setTimeout(function () {
            fetch(url)
                .then(function (response) {
                return response.headers.get('Content-Length');
            })
                .then(function (errNo) {
                if (errNo == "5093") {
                    node.active = true;
                }
            })
                .catch(function (error) {
                console.error('Error fetching X-Info:', error);
            });
        }, 100);
        cc.assetManager.loadRemote(url, { ext: '.jpg' }, function (err, texture) {
            if (texture) {
                node.active = true;
                node.getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(texture);
            }
            else {
                console.log(err, texture);
            }
        });
    };
    __decorate([
        property(cc.Label)
    ], NewClass.prototype, "count", void 0);
    __decorate([
        property(cc.Label)
    ], NewClass.prototype, "time", void 0);
    __decorate([
        property(cc.Node)
    ], NewClass.prototype, "selfNode", void 0);
    __decorate([
        property(cc.Node)
    ], NewClass.prototype, "one", void 0);
    __decorate([
        property(cc.Node)
    ], NewClass.prototype, "two", void 0);
    __decorate([
        property(cc.Node)
    ], NewClass.prototype, "three", void 0);
    __decorate([
        property(cc.Node)
    ], NewClass.prototype, "four", void 0);
    __decorate([
        property(cc.Node)
    ], NewClass.prototype, "five", void 0);
    NewClass = __decorate([
        ccclass
    ], NewClass);
    return NewClass;
}(cc.Component));
exports.default = NewClass;

cc._RF.pop();
                    }
                    if (nodeEnv) {
                        __define(__module.exports, __require, __module);
                    }
                    else {
                        __quick_compile_project__.registerModuleFunc(__filename, function () {
                            __define(__module.exports, __require, __module);
                        });
                    }
                })();
//# sourceMappingURL=data:application/json;charset=utf-8;base64,[encoded data, 15344 characters]