"use strict";
cc._RF.push(module, '87a44m5f/pPAKIrsyArSr/V', 'Wall');
// Script/Wall.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 });
exports.WallColor = exports.WallType = exports.WallSpecial = void 0;
var Map_1 = require("./Map");
var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
var WallSpecial;
(function (WallSpecial) {
    /*普通门*/
    WallSpecial[WallSpecial["\u666E\u901A\u95E8"] = 0] = "\u666E\u901A\u95E8";
    /*星星门*/
    WallSpecial[WallSpecial["\u661F\u661F\u95E8"] = 1] = "\u661F\u661F\u95E8";
    /*开关门*/
    WallSpecial[WallSpecial["\u5F00\u5173\u95E8"] = 2] = "\u5F00\u5173\u95E8";
    /*冻结门 */
    WallSpecial[WallSpecial["\u51BB\u7ED3\u95E8"] = 3] = "\u51BB\u7ED3\u95E8";
})(WallSpecial = exports.WallSpecial || (exports.WallSpecial = {}));
var WallType;
(function (WallType) {
    /*普通地块 */
    WallType[WallType["\u95E8\u6A2A\u5411\u4E0B"] = 0] = "\u95E8\u6A2A\u5411\u4E0B";
    /*起点地块 */
    WallType[WallType["\u95E8\u6A2A\u5411\u4E0A"] = 1] = "\u95E8\u6A2A\u5411\u4E0A";
    /*湿地 */
    WallType[WallType["\u95E8\u7AD6\u5411\u53F3"] = 2] = "\u95E8\u7AD6\u5411\u53F3";
    /*山峰 */
    WallType[WallType["\u95E8\u7AD6\u5411\u5DE6"] = 3] = "\u95E8\u7AD6\u5411\u5DE6";
    /*终点地块 */
    WallType[WallType["\u5899\u6A2A\u5411\u4E0B"] = 4] = "\u5899\u6A2A\u5411\u4E0B";
    /*息壤 */
    WallType[WallType["\u5899\u6A2A\u5411\u4E0A"] = 5] = "\u5899\u6A2A\u5411\u4E0A";
    /*加固 */
    WallType[WallType["\u5899\u7AD6\u5411\u53F3"] = 6] = "\u5899\u7AD6\u5411\u53F3";
    /*加固 */
    WallType[WallType["\u5899\u7AD6\u5411\u5DE6"] = 7] = "\u5899\u7AD6\u5411\u5DE6";
})(WallType = exports.WallType || (exports.WallType = {}));
var WallColor;
(function (WallColor) {
    /*普通地块 */
    WallColor[WallColor["\u7D2B\u8272"] = 0] = "\u7D2B\u8272";
    /*湿地 */
    WallColor[WallColor["\u9EC4\u8272"] = 1] = "\u9EC4\u8272";
    /*山峰 */
    WallColor[WallColor["\u7EFF\u8272"] = 2] = "\u7EFF\u8272";
    /*终点地块 */
    WallColor[WallColor["\u84DD\u8272"] = 3] = "\u84DD\u8272";
    /*息壤 */
    WallColor[WallColor["\u7C89\u8272"] = 4] = "\u7C89\u8272";
    /*加固 */
    WallColor[WallColor["\u6A58\u9EC4\u8272"] = 5] = "\u6A58\u9EC4\u8272";
    /*加固 */
    WallColor[WallColor["\u9752\u8272"] = 6] = "\u9752\u8272";
    /*加固 */
    WallColor[WallColor["\u767D\u8272"] = 7] = "\u767D\u8272";
    /*普通地块 */
    WallColor[WallColor["\u7EA2\u8272"] = 8] = "\u7EA2\u8272";
    /*普通地块 */
    WallColor[WallColor["\u7070\u8272"] = 9] = "\u7070\u8272";
})(WallColor = exports.WallColor || (exports.WallColor = {}));
var Wall = /** @class */ (function (_super) {
    __extends(Wall, _super);
    function Wall() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.number = null;
        _this.type = WallType.墙横向下;
        _this.special = WallSpecial.普通门;
        _this.color = WallColor.紫色;
        _this.wall_SpriteFrames = null;
        _this.down_SpriteFrames = null;
        return _this;
        // update (dt) {}
    }
    // LIFE-CYCLE CALLBACKS:
    // onLoad () {}
    Wall.prototype.start = function () {
        // console.log(this.type);
    };
    Wall.prototype.jsonDeepClone = function (obj) {
        return JSON.parse(JSON.stringify(obj));
    };
    Wall.prototype.init = function (wall_Info, posX, posY, direction) {
        this.wall_Info = this.jsonDeepClone(wall_Info);
        // this.open = true;
        if (wall_Info == null) {
            this.posX = posX;
            this.posY = posY;
            if (direction)
                this.direction = direction;
            // console.log("门方向赋值",direction);
            if (direction == "up") {
                this.node.parent.zIndex = 100 + this.posX - this.posY * 3;
            }
            else if (direction == "down" || direction == "right" ||
                direction == "rightdown" || direction == "downright"
                || direction == "rightup" || direction == "upright") {
                this.node.parent.zIndex = 30 + this.posX - this.posY * 3;
            }
            else if (direction == "left" || direction == "leftdown" || direction == "downleft") {
                this.node.parent.zIndex = 70 + this.posX - this.posY * 3;
            }
            else
                this.node.parent.zIndex = 70 + this.posX - this.posY * 3;
            Map_1.default._instance.mapBlocksWall[this.posX][this.posY].getComponent("MapBlock").block_Id = "Wall";
            //console.log(this.posX,this.posY,MapConroler._instance.mapBlocksWall[this.posX][this.posY].getComponent("MapBlock").block_Id);
            // console.log(this.posX,this.posY,this.node.zIndex);
            //this.node.getChildByName("num").getComponent(cc.Label).string = direction;
            //this.node.getChildByName("num").getComponent(cc.Label).string = ":" + this.node.parent.zIndex;
        }
        if (wall_Info != null) {
            this.color = wall_Info.color;
            this.special = wall_Info.special;
            this.initType();
            if (wall_Info.length > 0) {
                this.initColor(wall_Info.length);
            }
            else
                this.node.removeComponent("cc.Sprite");
            if (this.posX != null) {
                Map_1.default._instance.mapBlocksWall[this.posX][this.posY].getComponent("MapBlock").block_Id = "Wall";
                //console.log(this.posX,this.posY,MapConroler._instance.mapBlocksWall[this.posX][this.posY].getComponent("MapBlock").block_Id);
            }
        }
        // setTimeout(() => {
        //     this.node.getChildByName("num").getComponent(cc.Label).string = ":" + this.node.parent.zIndex;
        // }, 1000);
    };
    //创建门的颜色
    Wall.prototype.initColor = function (length) {
        var direction = this.node.parent.name;
        var double = 0;
        if (direction == "left" || direction == "right") {
            double = 3;
        }
        // debugger;
        if (this.wall_SpriteFrames) {
            var name = this.color + "color" + (length + double);
            var spriteFrame = this.wall_SpriteFrames._spriteFrames[name];
            this.node.getComponent(cc.Sprite).spriteFrame = spriteFrame;
        }
        if (this.down_SpriteFrames) {
            var name2 = this.color + "down" + (length + double);
            var downFrame = this.down_SpriteFrames._spriteFrames[name2];
            this.node.parent.getChildByName("down").getComponent(cc.Sprite).spriteFrame = downFrame;
        }
    };
    //创建特殊类型门
    Wall.prototype.initType = function () {
        switch (this.special) {
            case WallSpecial.星星门:
                var star = cc.instantiate(Map_1.default._instance.Block_Prop[this.special]);
                star.parent = this.node.parent;
                // console.log("门的方向",this.direction,"长度",this.wall_Info.length);
                // star.scaleX = star.scaleY = 0.5;
                if (this.wall_Info.length > 0) {
                    if (this.direction == "right" || this.direction == "left") {
                        star.children[this.wall_Info.length + 2].active = true;
                    }
                    else if (this.direction == "up" || this.direction == "down") {
                        star.children[this.wall_Info.length - 1].active = true;
                    }
                }
                star.setPosition(this.node.width / 2 + this.node.x, this.node.height / 2 + this.node.y);
                break;
            case WallSpecial.开关门:
                var name = "open" + this.wall_Info.length;
                this.openNode = this.node.parent.getChildByName("open").getChildByName(name);
                this.openNode.active = true;
                if (this.wall_Info.lock == false) {
                    this.open = true;
                    this.openNode.children[0].scaleX *= 0.01;
                    this.openNode.children[1].scaleX *= 0.01;
                }
                else {
                    this.open = false;
                }
                break;
            case WallSpecial.冻结门:
                var freeze = "freeze" + this.wall_Info.length;
                this.freezeNode = this.node.parent.getChildByName("freeze").getChildByName(freeze);
                this.freezeNode.active = true;
                if (this.wall_Info.freeze) {
                    this.freezeNode.getChildByName("num").getComponent(cc.Label).string = this.wall_Info.freeze + "";
                }
                break;
        }
    };
    //播放星星门通过
    Wall.prototype.playStarDoor = function () {
        if (this.node.parent.getChildByName("star")) {
            var star = this.node.parent.getChildByName("star");
            for (var i = 0; i < star.children.length; i++) {
                if (star.children[i].active == true) {
                    var starChild = star.children[i];
                    for (var j = 0; j < starChild.children.length; j++) {
                        starChild.children[j].active = true;
                        starChild.children[j].getComponent(sp.Skeleton).setAnimation(1, "taopao1", false);
                    }
                }
            }
        }
    };
    //改变开关门状态
    Wall.prototype.changeLock = function () {
        this.open = !this.open;
        console.log("开关门状态改变", this.open);
        if (!this.openNode.active) {
            this.openNode.active = true;
        }
        var fill = this.openNode.children[0].scaleX == 1 ? 0.01 : 1;
        if (this.openNode.children[0].scaleX < 0)
            fill = -fill;
        // console.log("目标",fill);
        cc.tween(this.openNode.children[0])
            .to(0.3, { scaleX: this.openNode.children[0].scaleX < 0 ? -fill : fill })
            .call(function () {
            // console.log("左边完成");
        })
            .start();
        cc.tween(this.openNode.children[1])
            .to(0.3, { scaleX: this.openNode.children[1].scaleX < 0 ? -fill : fill })
            .call(function () {
            // console.log("右边完成");
        })
            .start();
    };
    Wall.prototype.changeFreeze = function () {
        var numStr = this.freezeNode.getChildByName("num").getComponent(cc.Label);
        var num = parseInt(numStr.string);
        num -= 1;
        this.freezeNode.getChildByName("num").getComponent(cc.Label).string = num + "";
        if (num == 0) {
            this.freezeNode.parent.active = false;
        }
    };
    Wall.prototype.downDoor = function () {
        if (this.openNode) {
            if (this.openNode.children[0].scaleX == 1)
                return;
        }
        if (this.freezeNode) {
            if (this.freezeNode.active == true)
                return;
        }
        this.node.opacity = 0;
        if (this.special == WallSpecial.星星门) {
            this.node.parent.getChildByName("star").y -= 10;
        }
        this.node.parent.getChildByName("down").active = true;
    };
    Wall.prototype.upDoor = function () {
        if (this.special == WallSpecial.星星门) {
            this.node.parent.getChildByName("star").y += 10;
        }
        this.node.parent.getChildByName("down").active = false;
        this.node.opacity = 250;
    };
    __decorate([
        property(cc.Label)
    ], Wall.prototype, "number", void 0);
    __decorate([
        property({
            tooltip: '墙或者门的方向',
            type: cc.Enum(WallType),
        })
    ], Wall.prototype, "type", void 0);
    __decorate([
        property({
            tooltip: '墙或者门的方向',
            type: cc.Enum(WallSpecial),
        })
    ], Wall.prototype, "special", void 0);
    __decorate([
        property({
            tooltip: '门的颜色',
            type: cc.Enum(WallColor),
        })
    ], Wall.prototype, "color", void 0);
    __decorate([
        property(cc.SpriteAtlas)
    ], Wall.prototype, "wall_SpriteFrames", void 0);
    __decorate([
        property(cc.SpriteAtlas)
    ], Wall.prototype, "down_SpriteFrames", void 0);
    Wall = __decorate([
        ccclass
    ], Wall);
    return Wall;
}(cc.Component));
exports.default = Wall;

cc._RF.pop();