"use strict";
cc._RF.push(module, '1dc93b4fehOrpGgTkihBH4g', 'JiaZai');
// Script/JiaZai.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 GameManager_1 = require("./GameManager");
var NumberToImage_1 = require("./NumberToImage");
var MiniGameSdk_1 = require("./Sdk/MiniGameSdk");
var lq_collide_system_1 = require("./lq_collide_system/lq_collide_system");
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.node1 = null;
        _this.node2 = null;
        _this.node3 = null;
        _this.Block_Color = [];
        _this.custom = null;
        _this.level = null;
        _this.coin = null;
        _this.Stamina = null;
        return _this;
        // update (dt) {}
    }
    // LIFE-CYCLE CALLBACKS:
    NewClass.prototype.onLoad = function () {
        cc.game.setFrameRate(63);
        lq_collide_system_1.LQCollideSystem.is_enable = true;
        // console.log("加载关卡配置2");
        // window.initMgr();
        GameManager_1.default._instance.Block_Color = this.Block_Color;
        if (cc.fx.GameConfig.GM_INFO.first) {
            console.log("————————准备注册事件", cc.fx.GameConfig.GM_INFO.openid);
            if (cc.fx.GameConfig.GM_INFO.openid != "") {
                console.log("————————发送注册事件");
                cc.fx.GameTool.shushu_Track("register");
            }
            cc.fx.AudioManager._instance.playEffect("zhuan1", null);
            this.node.getChildByName("zhuanchang").active = true;
            this.node.getChildByName("zhuanchang").getComponent(sp.Skeleton).setAnimation(1, "up", false);
            setTimeout(function () {
                cc.fx.GameConfig.GM_INFO.first = false;
                cc.director.loadScene("GameScene");
            }, 1000);
        }
    };
    NewClass.prototype.start = function () {
        // console.log("已经进入Home界面");
        // console.log("金币",cc.fx.GameConfig.GM_INFO.coin);
        // console.log("关卡",cc.fx.GameConfig.GM_INFO.level+1);
        var _this = this;
        cc.fx.GameTool.getHealth(null);
        // cc.fx.GameConfig.LEVEL_INFO_init(false,0);
        setTimeout(function () {
            NumberToImage_1.default.numberToImageNodes((cc.fx.GameConfig.GM_INFO.level + 1), 25, 15, "big_", _this.level, false);
            NumberToImage_1.default.numberToImageNodes(cc.fx.GameConfig.GM_INFO.coin, 30, 15, "coin_", _this.coin, true);
            _this.setHealthInfo();
        }, 0);
        if (cc.fx.GameConfig.GM_INFO.gameState) {
            this.node.getChildByName("zhuanchang").active = true;
            setTimeout(function () {
                cc.fx.AudioManager._instance.playEffect("zhuan2", null);
                _this.node.getChildByName("zhuanchang").getComponent(sp.Skeleton).setAnimation(1, "down", false);
                _this.node.getChildByName("zhuanchang").getComponent(sp.Skeleton).setCompleteListener(function (entry) {
                    if (entry.animation.name === "down" && !cc.fx.GameConfig.GM_INFO.first) {
                        // 动画播放结束后执行的逻辑
                        _this.node.getChildByName("zhuanchang").active = false;
                    }
                });
            }, 500);
        }
        else {
            if (!cc.fx.GameConfig.GM_INFO.first)
                this.node.getChildByName("zhuanchang").active = false;
        }
    };
    //开始倒计时
    NewClass.prototype.startTimeCutDown = function () {
        this.scheduleCallback = function () {
            var _this = this;
            if (this.pause)
                return;
            if (cc.fx.GameConfig.GM_INFO.min_Time <= 0) {
                this.stopTimeCutDown();
                var timeTemp = cc.fx.GameTool.getTimeMargin(cc.fx.GameConfig.GM_INFO.min_Time);
                this.Stamina.getChildByName("time").getComponent(cc.Label).string = timeTemp;
                cc.fx.GameTool.setUserHealth(1, function (data) {
                    cc.fx.GameTool.getHealth(null);
                    _this.setHealthInfo();
                });
            }
            else {
                cc.fx.GameConfig.GM_INFO.min_Time -= 1;
                var timeTemp = cc.fx.GameTool.getTimeMargin(cc.fx.GameConfig.GM_INFO.min_Time);
                this.Stamina.getChildByName("time").getComponent(cc.Label).string = timeTemp;
            }
        }.bind(this);
        this.schedule(this.scheduleCallback, 1);
    };
    // 停止倒计时
    NewClass.prototype.stopTimeCutDown = function () {
        if (this.scheduleCallback) {
            this.unschedule(this.scheduleCallback);
        }
    };
    NewClass.prototype.setHealthInfo = function () {
        if (cc.fx.GameConfig.GM_INFO.hp == 5) {
            this.Stamina.getChildByName("man").active = true;
            this.Stamina.getChildByName("health").active = false;
            this.Stamina.getChildByName("time").active = false;
        }
        else {
            this.Stamina.getChildByName("man").active = false;
            this.Stamina.getChildByName("health").active = true;
            NumberToImage_1.default.numberToImageNodes((cc.fx.GameConfig.GM_INFO.hp), 25, 15, "coin_", this.Stamina.getChildByName("health"), false);
            this.Stamina.getChildByName("time").active = true;
            if (cc.fx.GameConfig.GM_INFO.min_Time != 0) {
                var time = cc.fx.GameTool.getTimeMargin(cc.fx.GameConfig.GM_INFO.min_Time);
                this.Stamina.getChildByName("time").getComponent(cc.Label).string = time;
                this.startTimeCutDown();
            }
        }
    };
    NewClass.prototype.startGame = function () {
        cc.fx.AudioManager._instance.playEffect("anniu_Big", null);
        if (cc.fx.GameConfig.GM_INFO.hp < 1) {
            MiniGameSdk_1.MiniGameSdk.API.showToast("体力值不足");
            return;
        }
        if (this.node.getChildByName("Load").getChildByName("startBtn").getComponent("btnControl")._touch) {
            this.node.getChildByName("Load").getChildByName("startBtn").getComponent("btnControl").setTouch(false);
            // if(this.custom.string != ""){
            //     cc.fx.GameConfig.GM_INFO.level = parseInt(this.custom.string) - 1;
            //     // cc.fx.StorageMessage.setStorage("level",cc.fx.GameConfig.GM_INFO.level.toString()); 
            //     cc.fx.GameConfig.LEVEL_INFO_init(true);
            // }
            // else{
            cc.fx.AudioManager._instance.playEffect("zhuan1", null);
            this.node.getChildByName("zhuanchang").active = true;
            this.node.getChildByName("zhuanchang").getComponent(sp.Skeleton).setAnimation(1, "up", false);
            cc.fx.GameConfig.LEVEL_INFO_init(true, 1000);
            // }
        }
    };
    //打开商店
    NewClass.prototype.openShop = function () {
        var _this = this;
        // 加载 shop  bundle
        cc.assetManager.loadBundle('shop', function (err, bundle) {
            bundle.load('prefab/shop', cc.Prefab, function (err, prefab) {
                if (err) {
                    cc.error(err.message || err);
                    return;
                }
                if (prefab) {
                    var shopNode = cc.instantiate(prefab);
                    _this.node.addChild(shopNode);
                    console.log("shopNode parent:", shopNode.parent);
                }
            });
        });
    };
    NewClass.prototype.closeRank = function () {
        this.node.getChildByName("Rank").active = false;
    };
    NewClass.prototype.openRank = function () {
        this.node.getChildByName("Rank").active = true;
    };
    NewClass.prototype.openReward = function () {
        this.node.getChildByName("Reward").active = true;
    };
    NewClass.prototype.clickShop = function () {
        // 假设已经获取到了 userId 和 productId
        var userId = cc.fx.GameConfig.GM_INFO.openid;
        var productId = '1';
        console.log("即将创建createorder");
        //@ts-ignore
        wx.cloud.callFunction({
            name: "createOrder",
            data: {
                "userId": userId,
                "productId": productId,
            },
            success: function (res) {
                // 取得云函数返回的订单信息
                console.log("createOrder结果:", res.result);
                var payment = res.result.paymentResult.payment;
                console.log("payment:", payment);
                // 调起微信客户端支付
                //@ts-ignore
                // 调起微信客户端支付
                //@ts-ignore
                wx.requestPayment({
                    // 时间戳，从 1970 年 1 月 1 日 00:00:00 至今的秒数，即当前的时间
                    timeStamp: payment.timeStamp,
                    // 随机字符串，长度为32个字符以下
                    nonceStr: payment.nonceStr,
                    // 统一下单接口返回的 prepay_id 参数值
                    package: payment.package,
                    // 签名算法，暂支持 MD5、HMAC-SHA256
                    signType: payment.signType || 'MD5',
                    // 支付签名
                    paySign: payment.paySign,
                    success: function (res) {
                        /* 成功回调 */
                        console.log("支付成功", res);
                    },
                    fail: function (res) {
                        /* 失败回调 */
                        console.log("支付失败", res);
                    },
                    complete: function (res) {
                        console.log("支付完成", res);
                    }
                });
            },
        });
    };
    NewClass.prototype.openPause = function () {
        cc.fx.AudioManager._instance.playEffect("anniu_little", null);
        console.log(cc.fx.GameConfig.GM_INFO);
        if (cc.fx.GameConfig.GM_INFO.openid == undefined) {
            console.log(cc.fx.GameConfig.GM_INFO.openid);
            cc.fx.GameConfig.GM_INFO.openid = "";
        }
        this.node.getChildByName("Pause").active = true;
        this.node.getChildByName("Pause").getChildByName("openID").getComponent(cc.Label).string = cc.fx.GameConfig.GM_INFO.openid;
    };
    NewClass.prototype.closePause = function () {
        cc.fx.AudioManager._instance.playEffect("anniu_little", null);
        this.node.getChildByName("Pause").active = false;
    };
    NewClass.prototype.closeReward = function () {
        this.node.getChildByName("Reward").active = false;
    };
    NewClass.prototype.openStamina = function () {
        this.node.getChildByName("Stamina").active = true;
    };
    NewClass.prototype.closeStamina = function () {
        this.node.getChildByName("Stamina").active = false;
    };
    __decorate([
        property(cc.Node)
    ], NewClass.prototype, "node1", void 0);
    __decorate([
        property(cc.Node)
    ], NewClass.prototype, "node2", void 0);
    __decorate([
        property(cc.Node)
    ], NewClass.prototype, "node3", void 0);
    __decorate([
        property({ type: [cc.SpriteAtlas], tooltip: "方块颜色" })
    ], NewClass.prototype, "Block_Color", void 0);
    __decorate([
        property(cc.EditBox)
    ], NewClass.prototype, "custom", void 0);
    __decorate([
        property(cc.Node)
    ], NewClass.prototype, "level", void 0);
    __decorate([
        property(cc.Node)
    ], NewClass.prototype, "coin", void 0);
    __decorate([
        property(cc.Node)
    ], NewClass.prototype, "Stamina", void 0);
    NewClass = __decorate([
        ccclass
    ], NewClass);
    return NewClass;
}(cc.Component));
exports.default = NewClass;

cc._RF.pop();