diff --git a/src/game-lib-a-1-event.js b/src/game-lib-a-1-event.js index 6255f75..ae5c0a7 100644 --- a/src/game-lib-a-1-event.js +++ b/src/game-lib-a-1-event.js @@ -93,7 +93,7 @@ GameLib.Event.TOUCH_MOVE = 0x4b; GameLib.Event.TOUCH_CANCEL = 0x4c; GameLib.Event.GET_REMOTE_API_URL = 0x4d; GameLib.Event.GET_GRAPHICS_IMPLEMENTATION = 0x4e; -GameLib.Event.XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX = 0x4f; +GameLib.Event.DELAYED_INSTANCE_ENCOUNTERED = 0x4f; GameLib.Event.GET_CODER_IMPLEMENTATION = 0x50; GameLib.Event.ANIMATION_MESH_ADDED = 0x51; GameLib.Event.ANIMATION_MESH_REMOVED = 0x52; @@ -195,7 +195,7 @@ GameLib.Event.GetEventName = function(number) { case 0x4c : return 'touch_cancel'; case 0x4d : return 'get_remote_api_url'; case 0x4e : return 'get_graphics_implementation'; - case 0x4f : return 'xxxxxxxxxxxxxxxxxxxxxxxxxxx'; + case 0x4f : return 'delayed_instance_encountered'; case 0x50 : return 'get_coder_implementation'; case 0x51 : return 'animation_mesh_added'; case 0x52 : return 'animation_mesh_removed'; diff --git a/src/game-lib-a-component-a.js b/src/game-lib-a-component-a.js index 6a1c959..7a300b3 100644 --- a/src/game-lib-a-component-a.js +++ b/src/game-lib-a-component-a.js @@ -111,6 +111,17 @@ GameLib.Component.prototype.performInstanceCreation = function() { } catch (error) { console.error(error); } + } else { + /** + * Some systems require a restart in order to create the delayed components (like System.Input for + * Edit Controls) - we need to give them the opportunity to restart + */ + GameLib.Event.Emit( + GameLib.Event.DELAYED_INSTANCE_ENCOUNTERED, + { + component : this + } + ) } } }; diff --git a/src/game-lib-system-input.js b/src/game-lib-system-input.js index 0c4a43d..dae5372 100644 --- a/src/game-lib-system-input.js +++ b/src/game-lib-system-input.js @@ -55,6 +55,8 @@ GameLib.System.Input = function( this.keyDown = this.onKeyDown.bind(this); this.keyUp = this.onKeyUp.bind(this); + this.delayedInstanceEncounteredSubscription = null; + this.mouse = new GameLib.Mouse( graphics ) @@ -78,6 +80,13 @@ GameLib.System.Input.prototype.start = function() { this.mouseControls = GameLib.EntityManager.Instance.queryComponents(GameLib.D3.Controls.Mouse); + this.delayedInstanceEncounteredSubscription = GameLib.Event.Subscribe( + GameLib.Event.DELAYED_INSTANCE_ENCOUNTERED, + function() { + this.restart(); + }.bind(this) + ); + /** * If we have touch controls - inject them first so we can override editor controls if necessary */ @@ -588,6 +597,8 @@ GameLib.System.Input.prototype.stop = function() { GameLib.System.prototype.stop.call(this); + this.delayedInstanceEncounteredSubscription.remove(); + if (this.editorControls.length > 0) { /** * Now remove all input capabilities