Clicking outside viewport (or on backpack, etc) no longer fires your weapon.
authordsc <david.schoonover@gmail.com>
Fri, 21 Jan 2011 00:17:35 +0000 (16:17 -0800)
committerdsc <david.schoonover@gmail.com>
Fri, 21 Jan 2011 00:17:35 +0000 (16:17 -0800)
src/tanks/game.cjs
src/tanks/thing/player.cjs
src/tanks/ui/main.cjs

index 5fea328..cb81a02 100644 (file)
@@ -91,10 +91,11 @@ Y.subclass('Game', {
     },
     
     destroy : function destroy(){
+        this.stop();
+        this.player.destroy();
         Thing.removeEventListener('created', this.addUnit);
         Thing.removeEventListener('destroy', this.killUnit);
         this.root.remove();
-        this.stop();
         this.resetGlobals();
     },
     
index f2b0965..a8fc6f5 100644 (file)
@@ -41,6 +41,12 @@ Tank.subclass('Player', {
         this.queue = [];
         this.activeKeys = new Y.YArray();
         
+        this.keydown   = this.keydown.bind(this);
+        this.keyup     = this.keyup.bind(this);
+        this.mousedown = this.mousedown.bind(this);
+        this.mouseup   = this.mouseup.bind(this);
+        this.mousemove = this.mousemove.bind(this);
+        
         this.replayMode = !!replay;
         
         if (this.replayMode) {
@@ -48,22 +54,28 @@ Tank.subclass('Player', {
             this.nextMove = replay.shift();
             
         } else {
-            this.keydown   = this.keydown.bind(this);
-            this.keyup     = this.keyup.bind(this);
-            this.mousedown = this.mousedown.bind(this);
-            this.mouseup   = this.mouseup.bind(this);
-            this.mousemove = this.mousemove.bind(this);
             
             $(document)
                 .bind('keydown',   this.keydown)
                 .bind('keyup',     this.keyup)
+                .bind('mousemove', this.mousemove);
+            $('#viewport')
                 .bind('mousedown', this.mousedown)
-                .bind('mouseup',   this.mouseup)
-                .bind('mousemove', this.mousemove)
-                ;
+                .bind('mouseup',   this.mouseup);
         }
     },
     
+    destroy : function destroy(){
+        $(document)
+            .unbind('keydown',   this.keydown)
+            .unbind('keyup',     this.keyup)
+            .unbind('mousemove', this.mousemove);
+        $('#viewport')
+            .unbind('mousedown', this.mousedown)
+            .unbind('mouseup',   this.mouseup);
+        return Tank.fn.destroy.call(this);
+    },
+    
     setReplay : function setReplay(replay){
         this.replayMode = true;
         this.replay     = replay
index a2fbafb..06c4b19 100644 (file)
@@ -20,8 +20,6 @@ var Y            = require('Y').Y
 ,   game        = null
 ,   overlay     = null
 ;
-function stopProp(evt){ evt.stopPropagation(); }
-
 qkv = Y(window.location.search.slice(1)).fromKV();
 hkv = Y(window.location.hash.slice(1)).fromKV();
 
@@ -37,7 +35,7 @@ function main(){
     
     overlay = $('#overlay');
     updateOverlay( config.get('ui.overlayOnPause') );
-    config.addEventListener('set:ui.overlayOnPause', function(evt){ updateOverlay(evt.newval); });
+    config.addEventListener('set:ui.overlayOnPause',     function(evt){ updateOverlay(evt.newval); });
     config.addEventListener('set:ui.debug.showFpsGraph', function(evt){ updateUI('#info', evt.newval); });
     
     // Player.addEventListener('create', function(evt){ P = evt.data.instance; });
@@ -51,10 +49,6 @@ function main(){
     $(document).bind('keydown', 'ctrl+i', function(evt){ updateUI('#info',   TOGGLE); });
     $(document).bind('keydown', 'ctrl+c', function(evt){ updateUI('#config', TOGGLE); });
     
-    // Don't fire on clicks in the debug menu
-    $('.debug').bind('mousedown', stopProp);
-    $('.debug').bind('click',     stopProp);
-    
     // Create #pause box
     $('#loading').clone()
         .attr('id', 'pause')