import { Engine } from './Engine' ; import { Entity } from './Entity' ; /**
 * Systems are logic bricks in your application.
 * If you want to manipulate entities and their components - it is the right place for that.
 */ export abstract class System { private _priority : number = 0 ; private _engine ? : Engine ; /**
     * Gets an  Engine instance that system attached to
     *  returns { Engine } throws public get engine ( ) : Engine { if ( this . _engine === undefined ) throw new Error ( `Property "engine" can't be accessed when system is not added to the engine` ) ; return this . _engine ; } /**
     * Gets an  Entity instance that is shared across all systems and can be used as a config.
     *  return { Entity } protected get sharedConfig ( ) : Entity { if ( this . _engine === undefined ) throw new Error ( `Property "sharedConfig" can't be accessed when system is not added to the engine` ) ; return this . _engine . sharedConfig ; } /**
     * Gets a priority of the system
     */ public get priority ( ) : number { return this . _priority ; } param dt public update ( dt ) { } /**
     * This method will be called after the system will be added to the Engine.
     */ public onAddedToEngine ( ) { } /**
     * Callback that will be invoked after removing system from engine
     */ public onRemovedFromEngine ( ) { } /**
     * Dispatches a message, that can be caught via  Engine .
     * It's the best way to send a message outside. This mechanism allows you not to invent the signals/dispatchers
     * mechanism for your systems, to report an event. For example, you can dispatch that the game round has been
     * completed.
     *
     *  param { T } message throws example public dispatch < T > ( message ) { if ( this . _engine === undefined ) { throw new Error ( 'Dispatching a message can\'t be done while system is not attached to the engine' ) ; } this . engine . dispatch ( message ) ; } internal public setEngine ( engine ) { this . _engine = engine ; } internal public setPriority ( priority ) { this . _priority = priority ; } }