UNPKG

@senspark/ee

Version:

utility library for cocos creator

52 lines (51 loc) 1.78 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var ProfileManager = /** @class */ (function () { function ProfileManager() { var _this = this; if (CC_EDITOR) { this.listener = new Editor.IpcListener(); this.listener.on('ee:profile_manager:set_data', function (event, key, data) { _this.saveData(key, data); }); this.listener.on('ee:profile_manager:get_data', function (event, key, reply) { var data = _this.loadData(key); Editor.Ipc.sendToAll(reply, data); }); } } ProfileManager.getInstance = function () { return this.sharedInstance || (this.sharedInstance = new this()); }; ProfileManager.prototype.setProfile = function (profile) { this.profile = profile; }; ProfileManager.prototype.getProfile = function () { return this.profile; }; ProfileManager.prototype.loadData = function (key) { if (this.profile === undefined) { return undefined; } return this.profile.data[key]; }; ProfileManager.prototype.saveData = function (key, data) { if (this.profile === undefined) { return; } this.profile.data[key] = data; this.profile.save(); }; return ProfileManager; }()); exports.ProfileManager = ProfileManager; if (CC_EDITOR) { /** Loads saved profile for the editor. */ Editor.Profile.load('profile://project/ee.json', function (err, profile) { if (profile !== null) { var manager = ProfileManager.getInstance(); manager.setProfile(profile); Editor.Ipc.sendToAll('ee:profile_manager_loaded'); } }); }