"use strict";
cc._RF.push(module, '4ab29OctQtG9od39Mn2GUGz', 'prefabTest');
// scripts/prefabTest/prefabTest.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 (b.hasOwnProperty(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 item_1 = require("./item");
var prefabTestGameData_1 = require("./prefabTestGameData");
var prefabHttpMagr_1 = require("./zip/prefabHttpMagr");
var ZipManager_1 = require("./zip/ZipManager");
var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
var prefabTest = /** @class */ (function (_super) {
    __extends(prefabTest, _super);
    function prefabTest() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this._startView = null;
        _this._startView2 = null;
        _this.sp = null;
        _this.sp2 = null;
        _this.sp3 = null;
        _this.eb = null;
        _this.tipsLab = null;
        _this._itme1 = null;
        _this._itme2 = null;
        _this._itme3 = null;
        return _this;
        // /**
        //  * 创建gif图
        //  * @param word 单词
        //  * @returns 
        //  */
        // createGif(clip, sp, num) {
        //     let key = preGameData.gifRes.getKey(num);
        //     let t_frames: Array<cc.SpriteFrame> = preGameData.gifRes.get(key);
        //     if (this._clip) {
        //         this._clip.decRef();
        //         this._clip = null;
        //     }
        //     this._clip = cc.AnimationClip.createWithSpriteFrames(t_frames, t_frames.length);
        //     this._clip.name = "anim";
        //     this._clip.sample = 60;
        //     this._clip.speed = 0.4;
        //     this._clip.wrapMode = cc.WrapMode.Loop;
        //     this._clip.addRef();
        //     let anim = sp.getComponent(cc.Animation);
        //     if (!anim) {
        //         anim = sp.addComponent(cc.Animation);
        //     }
        //     anim.addClip(this._clip);
        //     anim.play("anim");
        // }
    }
    prefabTest.prototype.onLoad = function () {
        this._itme1 = this.sp.getComponent(item_1.default);
        this._itme2 = this.sp2.getComponent(item_1.default);
        this._itme3 = this.sp3.getComponent(item_1.default);
    };
    /**预加载测试---未发现内存增加 */
    prefabTest.prototype.onPreLoadClick = function () {
        cc.resources.preloadDir("prefabs", function (finish, total, item) {
            cc.log(finish / total);
        }, function (error, items) {
            cc.log(items);
        });
    };
    /**动态生成Prefab---按照要求内存会回收 */
    prefabTest.prototype.onInitStartViewClick = function () {
        var _this = this;
        if (this._startView) {
            this._startView.destroy();
            this._startView = null;
            cc.resources.release("prefabs/startView");
            // cc.assetManager.releaseAll();
            return;
        }
        cc.resources.load("prefabs/startView", cc.Prefab, function (err, prefab) {
            _this._startView = cc.instantiate(prefab);
            _this._startView.setParent(_this.node);
            _this._startView.setPosition(0, 0);
        });
    };
    /**动态生成Prefab---按照要求内存会回收 */
    prefabTest.prototype.onInitStartView2Click = function () {
        var _this = this;
        if (this._startView2) {
            this._startView2.destroy();
            this._startView2 = null;
            cc.resources.release("prefabs/startView2");
            return;
        }
        cc.resources.load("prefabs/startView2", cc.Prefab, function (err, prefab) {
            _this._startView2 = cc.instantiate(prefab);
            _this._startView2.setParent(_this.node);
            _this._startView2.setPosition(0, 0);
        });
    };
    /**下载资源按钮点击 */
    prefabTest.prototype.onDownloadResClick = function () {
        this.downloadRes();
    };
    /**切换场景 */
    prefabTest.prototype.onNextScene = function () {
        cc.director.loadScene("norScene");
    };
    prefabTest.prototype.downloadRes = function () {
        var _this = this;
        this.clearData();
        var num = this.eb.string ? Number(this.eb.string) : 1;
        if (num > 6 || num < 1) {
            this.tipsLab.string = "资源id只能输入1~6";
            return;
        }
        var url = "http://static.tope365.com/xxbg/cocos/gif_" + num + ".zip";
        this.tipsLab.string = "\u4E0B\u8F7D\u4E2D:" + num;
        var data = {
            url: url,
            isZip: true,
        };
        prefabHttpMagr_1.preHttpMgr.get(data, function (zip) {
            _this.tipsLab.string = "\u8D44\u6E90" + num + "\u4E0B\u8F7D\u5B8C\u6210!!,\n\u8D44\u6E90\u89E3\u6790\u4E2D\uFF0C\u8BF7\u7A0D\u540E";
            ZipManager_1.default.loadSubZip(zip, function () {
                // preGameData.zipData.gifMap = zipData.gifMap;
                // cc.log("zipData111=", zipData);
                zip = null;
                // zipData = null;
                // cc.log("zipData222=", zipData);
                // resolve();
                cc.log("11111111111");
                _this.tipsLab.string = "\u8D44\u6E90" + num + "\u89E3\u6790\u5B8C\u6210!!,\n\u8BF7\u70B9\u51FBcreate\u6309\u94AE";
            });
        });
    };
    /**创建gif图 */
    prefabTest.prototype.createGifBtnClick = function () {
        this._itme1.createGif(0);
        this._itme2.createGif(1);
        this._itme3.createGif(2);
    };
    prefabTest.prototype.clearData = function () {
        this._itme1.clearData();
        this._itme2.clearData();
        this._itme3.clearData();
        prefabTestGameData_1.preGameData.clearData();
    };
    prefabTest.prototype.clearDataBtnClick = function () {
        this.clearData();
        this._itme1.removeNode();
        this._itme2.removeNode();
        this._itme3.removeNode();
    };
    __decorate([
        property(cc.Node)
    ], prefabTest.prototype, "sp", void 0);
    __decorate([
        property(cc.Node)
    ], prefabTest.prototype, "sp2", void 0);
    __decorate([
        property(cc.Node)
    ], prefabTest.prototype, "sp3", void 0);
    __decorate([
        property(cc.EditBox)
    ], prefabTest.prototype, "eb", void 0);
    __decorate([
        property(cc.Label)
    ], prefabTest.prototype, "tipsLab", void 0);
    prefabTest = __decorate([
        ccclass
    ], prefabTest);
    return prefabTest;
}(cc.Component));
exports.default = prefabTest;

cc._RF.pop();