jsge
Version:
Javascript Game Engine
278 lines (243 loc) • 9.84 kB
HTML
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="expires" content="Wen, 05 Jun 2024 07:01:00 GMT">
<title>JSDoc: Source: base/ISystem.js</title>
<script src="scripts/prettify/prettify.js"> </script>
<script src="scripts/prettify/lang-css.js"> </script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>
<body>
<div id="main">
<h1 class="stage-title">Source: base/ISystem.js</h1>
<section>
<article>
<pre class="prettyprint source linenums"><code>import { CONST, ERROR_CODES, WARNING_CODES } from "../constants.js";
import { Exception, Warning } from "./Exception.js";
import { INetwork } from "./INetwork.js";
import { ISystemAudio } from "./ISystemAudio.js";
import { SystemSettings } from "../configs.js";
import AssetsManager from "../../modules/assetsm/src/AssetsManager.js";
import { DrawObjectFactory } from "./DrawObjectFactory.js";
import { GameStage } from "./GameStage.js";
import { IRender } from "./IRender.js";
import { IExtension } from "./IExtension.js";
/**
* Public interface for a System<br>
* Can be used to start/stop GameStage render, <br>
* And provides access to SystemSettings, INetwork and ISystemAudio <br>
* IRender, DrawObjectFactory, AssetsManager and external modules
* accessible via GameStage.iSystem and System.system
* @see {@link System} a part of System class instance
* @see {@link GameStage} a part of GameStage class instance
*/
export class ISystem {
/**
* @type {Object}
*/
#systemSettings;
/**
* @type {IExtension}
*/
#iExtension;
/**
* @type {INetwork | null}
*/
#systemServerConnection;
/**
* @type {ISystemAudio}
*/
#systemAudioInterface;
/**
* @type {AssetsManager}
*/
#iLoader = new AssetsManager();
/**
* @type {IRender}
*/
#iRender;
/**
* @type {DrawObjectFactory}
*/
#drawObjectFactory = new DrawObjectFactory(this.#iLoader);
#modules = new Map();
/**
* @type {Map<string, Object>}
*/
#registeredStagesReference;
/**
* @type {EventTarget}
*/
#emitter = new EventTarget();
/**
* @hideconstructor
*/
constructor(systemSettings, registeredStages, canvasContainer) {
if (!systemSettings) {
Exception(ERROR_CODES.CREATE_INSTANCE_ERROR, "systemSettings should be passed to class instance");
}
this.#systemSettings = systemSettings;
this.#systemAudioInterface = new ISystemAudio(this.iLoader);
this.#systemServerConnection = systemSettings.network.enabled ? new INetwork(systemSettings) : null;
this.#iRender = new IRender(this.systemSettings, this.iLoader, canvasContainer);
this.#iExtension = new IExtension(this);
this.#registeredStagesReference = registeredStages;
// broadcast render events
this.#iRender.addEventListener(CONST.EVENTS.SYSTEM.RENDER.START, () => this.emit(CONST.EVENTS.SYSTEM.RENDER.START));
this.#iRender.addEventListener(CONST.EVENTS.SYSTEM.RENDER.END, () => this.emit(CONST.EVENTS.SYSTEM.RENDER.END));
}
/**
*
* @param {string} eventName
* @param {...any} eventParams
*/
emit = (eventName, ...eventParams) => {
const event = new Event(eventName);
event.data = [...eventParams];
this.#emitter.dispatchEvent(event);
};
/**
*
* @param {string} eventName
* @param {*} listener
* @param {*=} options
*/
addEventListener = (eventName, listener, options) => {
this.#emitter.addEventListener(eventName, listener, options);
};
/**
*
* @param {string} eventName
* @param {*} listener
* @param {*=} options
*/
removeEventListener = (eventName, listener, options) => {
this.#emitter.removeEventListener(eventName, listener, options);
};
/**
* @returns { INetwork | null }
*/
get iNetwork () {
return this.#systemServerConnection;
}
/**
* @returns { SystemSettings }
*/
get systemSettings() {
return this.#systemSettings;
}
/**
* @returns { ISystemAudio }
*/
get audio() {
return this.#systemAudioInterface;
}
/**
* @returns {AssetsManager}
*/
get iLoader() {
return this.#iLoader;
}
/**
* @returns {IRender}
*/
get iRender() {
return this.#iRender;
}
/**
* @returns {DrawObjectFactory}
*/
get drawObjectFactory() {
return this.#drawObjectFactory;
}
/**
* @returns {IExtension}
*/
get iExtension() {
return this.#iExtension;
}
/**
* @returns {Map<string, Object>}
*/
get modules() {
return this.#modules;
}
/**
*
* @param {string} moduleKey
* @param {Object} moduleClass
* @param {...any} args
* @returns {Object}
*/
installModule = (moduleKey, moduleClass, ...args) => {
const moduleInstance = new moduleClass(this, ...args);
if (this.#modules.has(moduleKey)) {
Warning(WARNING_CODES.MODULE_ALREADY_INSTALLED, "module " + moduleKey + " is already installed");
return this.#modules.get(moduleKey);
} else {
this.#modules.set(moduleKey, moduleInstance);
}
return moduleInstance;
};
/**
* @method
* @param {string} gameStageName
* @param {Object} [options] - options
*/
startGameStage = (gameStageName, options) => {
if (this.#registeredStagesReference.has(gameStageName)) {
if (this.#iRender._isRenderActive() === true) {
this.#iRender._stopRender();
Exception(ERROR_CODES.ANOTHER_STAGE_ACTIVE, " Can't start the stage " + gameStageName + " while, another stage is active");
} else {
const stage = this.#registeredStagesReference.get(gameStageName),
pageData = stage.stageData;
this.#drawObjectFactory._attachPageData(pageData);
if (stage.isInitiated === false) {
stage._init();
}
//stage._attachCanvasToContainer(this.#canvasContainer);
stage._start(options);
pageData._processPendingRenderObjects();
this.emit(CONST.EVENTS.SYSTEM.START_PAGE);
this.#iRender._startRender(pageData);
}
} else {
Exception(ERROR_CODES.VIEW_NOT_EXIST, "Stage " + gameStageName + " is not registered!");
}
};
/**
* @method
* @param {string} gameStageName
*/
stopGameStage = (gameStageName) => {
if (this.#registeredStagesReference.has(gameStageName)) {
this.emit(CONST.EVENTS.SYSTEM.STOP_PAGE);
this.drawObjectFactory._detachPageData();
this.#iRender._stopRender();
this.#registeredStagesReference.get(gameStageName)._stop();
} else {
Exception(ERROR_CODES.STAGE_NOT_EXIST, "GameStage " + gameStageName + " is not registered!");
}
};
}</code></pre>
</article>
</section>
</div>
<nav>
<div class="switcher"><ul><li class="active"><a href="/">1.5.9</a></li></div>
<h2><a href="/">Home</a></h2><h3>Classes</h3><ul><li><a href="DrawCircleObject.html">DrawCircleObject</a></li><li><a href="DrawConusObject.html">DrawConusObject</a></li><li><a href="DrawImageObject.html">DrawImageObject</a></li><li><a href="DrawLineObject.html">DrawLineObject</a></li><li><a href="DrawObjectFactory.html">DrawObjectFactory</a></li><li><a href="DrawPolygonObject.html">DrawPolygonObject</a></li><li><a href="DrawRectObject.html">DrawRectObject</a></li><li><a href="DrawShapeObject.html">DrawShapeObject</a></li><li><a href="DrawTextObject.html">DrawTextObject</a></li><li><a href="DrawTiledLayer.html">DrawTiledLayer</a></li><li><a href="GameStage.html">GameStage</a></li><li><a href="GameStageData.html">GameStageData</a></li><li><a href="IExtension.html">IExtension</a></li><li><a href="INetwork.html">INetwork</a></li><li><a href="IRender.html">IRender</a></li><li><a href="ISystem.html">ISystem</a></li><li><a href="ISystemAudio.html">ISystemAudio</a></li><li><a href="RenderLoop.html">RenderLoop</a></li><li><a href="RenderLoopDebug.html">RenderLoopDebug</a></li><li><a href="System.html">System</a></li><li><a href="SystemSettings.html">SystemSettings</a></li></ul><h3>Tutorials</h3><ul><li><a href="tutorial-application_scheme.html">Application Scheme</a></li><li><a href="tutorial-assets_manager.html">Assets Manager</a></li><li><a href="tutorial-common_issues.html">Common Issues</a></li><li><a href="tutorial-how_to_add_and_use_audio.html">How to add and use audio</a></li><li><a href="tutorial-how_to_do_animations.html">How to Create Animations</a></li><li><a href="tutorial-how_to_load_and_use_tilemaps.html">How to Load and Use Tilemaps</a></li><li><a href="tutorial-quick_start.html">Quick Start</a></li><li><a href="tutorial-spine_animations.html">How to Add Spine Animations</a></li><li><a href="tutorial-stages_lifecycle.html">Stages Lifecycle</a></li></ul>
</nav>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.4</a> on Wed Jun 18 2025 06:53:54 GMT+0000 (Coordinated Universal Time)
</footer>
<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>