repo: janusweb
action: commit
revision: 
path_from: 
revision_from: 7e53e8054b73cd1beae6c6fa8cdaa6c47977e920:
path_to: 
revision_to: 
git.thebackupbox.net
janusweb
git clone git://git.thebackupbox.net/janusweb
commit 7e53e8054b73cd1beae6c6fa8cdaa6c47977e920
Author: James Baicoianu 
Date:   Tue Oct 31 23:17:18 2017 -0700

    Only register/unregister event listeners once per start/stop

diff --git a/scripts/room.js b/scripts/room.js
index f5cc077250e3084d1dce423c1f7e7aeecf281662..
index ..21b248eff285488c24ad92fd29ed02eb3303b13a 100644
--- a/scripts/room.js
+++ b/scripts/room.js
@@ -700,6 +700,16 @@ elation.require([
       if (!this.enabled) {
         this.enabled = true;
         this.engine.systems.ai.add(this);
+
+        elation.events.add(window, 'click', this.onClick);
+        elation.events.add(window, 'keydown', this.onKeyDown);
+        elation.events.add(window, 'keyup', this.onKeyUp);
+        elation.events.add(this.engine.client.container, 'mousedown,touchstart', this.onMouseDown);
+        elation.events.add(this.engine.client.container, 'mouseup,touchend', this.onMouseUp);
+        elation.events.add(this, 'click', this.onObjectClick);
+        elation.events.add(this, 'dragover', this.handleDragOver);
+        elation.events.add(this, 'drop', this.handleDrop);
+
         elation.events.fire({type: 'room_enable', data: this});
       }
       elation.events.add(this, 'thing_think', this.onScriptTick);
@@ -707,14 +717,6 @@ elation.require([
         elation.events.add(this.engine.systems.admin, 'admin_edit_change', elation.bind(this, this.onRoomEdit));
       }
       //this.showDebug();
-      elation.events.add(window, 'click', this.onClick);
-      elation.events.add(window, 'keydown', this.onKeyDown);
-      elation.events.add(window, 'keyup', this.onKeyUp);
-      elation.events.add(this.engine.client.container, 'mousedown,touchstart', this.onMouseDown);
-      elation.events.add(this.engine.client.container, 'mouseup,touchend', this.onMouseUp);
-      elation.events.add(this, 'click', this.onObjectClick);
-      elation.events.add(this, 'dragover', this.handleDragOver);
-      elation.events.add(this, 'drop', this.handleDrop);
     }
     this.disable = function() {
       var keys = Object.keys(this.children);
@@ -728,16 +730,17 @@ elation.require([
         this.engine.systems.ai.remove(this);
         elation.events.fire({type: 'room_disable', data: this});
         this.enabled = false;
+
+        elation.events.remove(this, 'thing_think', this.onScriptTick);
+        elation.events.remove(window, 'click', this.onClick);
+        elation.events.remove(window, 'keydown', this.onKeyDown);
+        elation.events.remove(window, 'keyup', this.onKeyUp);
+        elation.events.remove(this.engine.client.container, 'mousedown,touchstart', this.onMouseDown);
+        elation.events.remove(this.engine.client.container, 'mouseup,touchend', this.onMouseUp);
+        elation.events.remove(this, 'click', this.onObjectClick);
+        elation.events.remove(this, 'dragover', this.handleDragOver);
+        elation.events.remove(this, 'drop', this.handleDrop);
       }
-      elation.events.remove(this, 'thing_think', this.onScriptTick);
-      elation.events.remove(window, 'click', this.onClick);
-      elation.events.remove(window, 'keydown', this.onKeyDown);
-      elation.events.remove(window, 'keyup', this.onKeyUp);
-      elation.events.remove(this.engine.client.container, 'mousedown,touchstart', this.onMouseDown);
-      elation.events.remove(this.engine.client.container, 'mouseup,touchend', this.onMouseUp);
-      elation.events.remove(this, 'click', this.onObjectClick);
-      elation.events.remove(this, 'dragover', this.handleDragOver);
-      elation.events.remove(this, 'drop', this.handleDrop);
     }
     this.setTitle = function(title) {
       if (!title) title = 'Untitled Page';

-----END OF PAGE-----