var Constants = require('Constants'); var tiledMapUnit = cc.Class({ name: "tiledMapUnit", properties: () => ({ //获取id getBuildingID: { get: function () { return this._id; } }, //占位的起始点,左下角的tiled getIsItOccupyPosition: { get: function () { return this._isItOccupyPosition; } }, // isItOccupyPosition: [cc.Boolean], getTiledPosition: { get: function () { return this._tiledStartPosition; } }, //占位的区域,比如是3*3 ,起点往后各占3格 getOccupyingArea: { get: function () { return cc.v2(this._row, this._column); } }, //对象的siblingIndex getSiblingIndex: { get: function () { return this._getSiblingIndex; } }, //对象的ZIndex getZIndex: { get: function () { return this._ZIndex; } }, //约定的index 的数组 getIndexArray: { get: function () { return this._tiledIndexArray; } }, //目标的buildingsInfo脚本 getBuildingsInfo: { get: function () { return this._buildingsInfo; } } }), //记录对象的id,唯一的 //只设置一次 onSetBuildingID(id) { this._id = id; }, //设置对象的siblingIndex onSetSiblingIndex(_siblingIndex) { this._getSiblingIndex = _siblingIndex; }, //根据约定值取出渲染的index onGetSblingIndexFromIndex(_stargetIndex) { if (!this._tiledIndexArray) return false; let length = this._tiledIndexArray.length; for (let i = 0; i < length; i++) { if (targetIndex === this._tiledIndexArray[i]) return this._getSiblingIndex; } return false; }, //设置对象的ZIndex onSetZIndex(_ZIndex) { this._ZIndex = _ZIndex; }, //根据约定值取出渲染的ZIndex onGetZIndexFromIndex(_stargetIndex) { if (!this._tiledIndexArray) return false; let length = this._tiledIndexArray.length; for (let i = 0; i < length; i++) { if (targetIndex === this._tiledIndexArray[i]) return this._ZIndex; } return false; }, //记录初始tile位置 onSetStartTiledPos(tiledPos) { this._tiledStartPosition = tiledPos; }, //Init Occupy State onSetOccupyState(value) { this._isItOccupyPosition = value; }, //左边记为列 右边为行 onSetOccupyingArea(x, y) { this._row = x; this._column = y; }, //记录约定数组 onSetIndexArray(index) { this._tiledIndexArray = index; }, //记录目标的buildingsInfo脚本 onSetBuildingsInfo(buildingsInfo) { this._buildingsInfo = buildingsInfo; }, //约定的index是否存在这里 onIndexExistInThis(targetIndex) { if (!this._tiledIndexArray) return false; let length = this._tiledIndexArray.length; for (let i = 0; i < length; i++) { if (targetIndex === this._tiledIndexArray[i]) return true; } return false; } }); module.exports = tiledMapUnit;