"use strict"; cc._RF.push(module, '3a2c06C7rJLFo4tXxLrJ+Pu', 'MapManager'); // scripts/kernel/battle/map/MapManager.ts "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.MapManager = void 0; var MapData_1 = require("./MapData"); var MapView_1 = require("./MapView"); var MapManager = /** @class */ (function () { function MapManager() { this._cache = new Map(); } Object.defineProperty(MapManager, "ins", { get: function () { if (this._ins == null) { this._ins = new MapManager(); } return this._ins; }, enumerable: false, configurable: true }); /** * * @param mapFileName * @param finishCallBack 加载完毕回调,参数 data:MapData * @param thisObj */ MapManager.prototype.loadMap = function (mapFileName, finishCallBack, thisObj) { var _this = this; var mapUrl = "map/" + mapFileName; if (this._cache.has(mapUrl)) { finishCallBack.call(thisObj, this._cache.get(mapUrl).clone()); } else { cc.resources.load(mapUrl, cc.TiledMapAsset, function (error, assets) { if (!error) { var mapNode = new cc.Node('tiledmapNode:' + mapUrl); var tiled = mapNode.addComponent(cc.TiledMap); tiled.tmxAsset = assets; var data = new MapData_1.MapData(); data.init(tiled); _this._cache.set(mapUrl, data); // cc.resources.release(mapUrl, cc.TiledMapAsset); //释放资源,只保留mapData数据 //释放后每次加载新地图都会把图集再加载一次,先不释放 finishCallBack.call(thisObj, data.clone()); } else { cc.error(error.message); } }); } }; /**传入数据,产生一个显示对象 */ MapManager.prototype.renderMap = function (data, prefabCollection, preview) { if (preview === void 0) { preview = false; } var view = new MapView_1.MapView('mapView_' + data.id.toString()); view.init(data, prefabCollection, preview); return view; }; MapManager._ins = null; return MapManager; }()); exports.MapManager = MapManager; cc._RF.pop();