From 9589e9d78cbfbadf77baaa1bcead90b6620f5987 Mon Sep 17 00:00:00 2001 From: dsc Date: Thu, 20 Jan 2011 16:17:35 -0800 Subject: [PATCH] Clicking outside viewport (or on backpack, etc) no longer fires your weapon. --- src/tanks/game.cjs | 3 ++- src/tanks/thing/player.cjs | 28 ++++++++++++++++++++-------- src/tanks/ui/main.cjs | 8 +------- 3 files changed, 23 insertions(+), 16 deletions(-) diff --git a/src/tanks/game.cjs b/src/tanks/game.cjs index 5fea328..cb81a02 100644 --- a/src/tanks/game.cjs +++ b/src/tanks/game.cjs @@ -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(); }, diff --git a/src/tanks/thing/player.cjs b/src/tanks/thing/player.cjs index f2b0965..a8fc6f5 100644 --- a/src/tanks/thing/player.cjs +++ b/src/tanks/thing/player.cjs @@ -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 diff --git a/src/tanks/ui/main.cjs b/src/tanks/ui/main.cjs index a2fbafb..06c4b19 100644 --- a/src/tanks/ui/main.cjs +++ b/src/tanks/ui/main.cjs @@ -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') -- 1.7.0.4