@robotlegsjs/phaser
Version:
RobotlegsJS integration with Phaser Scene Manager
52 lines • 2.65 kB
JavaScript
;
// ------------------------------------------------------------------------------
// Copyright (c) 2017-present, RobotlegsJS. All Rights Reserved.
//
// NOTICE: You are permitted to use, modify, and distribute this file
// in accordance with the terms of the license agreement accompanying it.
// ------------------------------------------------------------------------------
Object.defineProperty(exports, "__esModule", { value: true });
exports.SceneManagerExtension = void 0;
var ISceneManager_1 = require("./api/ISceneManager");
var SceneManager_1 = require("./impl/SceneManager");
var SceneRegistry_1 = require("./impl/SceneRegistry");
/**
* This extension install a Scene Manager into the context
*/
var SceneManagerExtension = /** @class */ (function () {
function SceneManagerExtension() {
}
/*============================================================================*/
/* Public Functions */
/*============================================================================*/
/**
* @inheritDoc
*/
SceneManagerExtension.prototype.extend = function (context) {
context.whenInitializing(this._whenInitializing.bind(this));
context.whenDestroying(this._whenDestroying.bind(this));
this._injector = context.injector;
// Just one Container Registry
SceneManagerExtension._containerRegistry =
SceneManagerExtension._containerRegistry || new SceneRegistry_1.SceneRegistry();
this._injector
.bind(SceneRegistry_1.SceneRegistry)
.toConstantValue(SceneManagerExtension._containerRegistry);
// But you get your own View Manager
this._injector.bind(ISceneManager_1.ISceneManager).to(SceneManager_1.SceneManager).inSingletonScope();
};
/*============================================================================*/
/* Private Functions */
/*============================================================================*/
SceneManagerExtension.prototype._whenInitializing = function () {
this._sceneManager = this._injector.get(ISceneManager_1.ISceneManager);
};
SceneManagerExtension.prototype._whenDestroying = function () {
this._sceneManager.removeAllHandlers();
this._injector.unbind(ISceneManager_1.ISceneManager);
this._injector.unbind(SceneRegistry_1.SceneRegistry);
};
return SceneManagerExtension;
}());
exports.SceneManagerExtension = SceneManagerExtension;
//# sourceMappingURL=SceneManagerExtension.js.map