Skip to content
Browse files

Added shift modifier key to allow the building of multiple towers at …

…a time.
  • Loading branch information...
1 parent 9fd187a commit d145a1aed3cccca7497c224feb9241f8ae914963 @lukeman lukeman committed Jun 9, 2008
Showing with 28 additions and 4 deletions.
  1. +4 −0 game/ui_modes.js
  2. +24 −4 ptd.html
View
4 game/ui_modes.js
@@ -138,6 +138,10 @@ var BuildTowerMode = function() {
if (SET.gold >= this.cost) return true;
else return false;
};
+ this.can_leave_mode = function() {
+ //remain in build mode if shift is held down
+ return !shift_down;
+ };
this.name = function() {
return "BuildTowerMode";
};
View
28 ptd.html
@@ -187,10 +187,14 @@
/* Hotkeys! */
special_keys = {
27: 'esc', 9: 'tab', 32:'space', 13: 'return', 8:'backspace', 145: 'scroll', 20: 'capslock',
- 144: 'numlock', 19:'pause', 45:'insert', 36:'home', 46:'del',35:'end', 33: 'pageup',
+ 144: 'numlock', 19:'pause', 45:'insert', 36:'home', 46:'del',35:'end', 33: 'pageup', 16: 'shift',
34:'pagedown', 37:'left', 38:'up', 39:'right',40:'down', 112:'f1',113:'f2', 114:'f3',
115:'f4', 116:'f5', 117:'f6', 118:'f7', 119:'f8', 120:'f9', 121:'f10', 122:'f11', 123:'f12'};
+ /* Modifier keys */
+ var modifierkeys = {};
+ var shift_down = false;
+
//extract hotkeys from the DOM
var hotkeys = {};
$('button .hotkey').each(function(){
@@ -204,16 +208,32 @@
hotkeys["esc"] = unselect;
hotkeys['Z'] = function() {$('#log').empty()};
+ //modifiers to be called on keydown and keyup
+ modifierkeys["shift"] = function() { shift_down = !shift_down; };
+
$(document).bind("keydown", function(e) {
// if the user is holding down ctrl or cmd, let the browser handle it
if (e.metaKey) return true;
-
var key = special_keys[e.keyCode] || String.fromCharCode(e.keyCode);
if (key in hotkeys){
hotkeys[key]();
- return false
+ return false;
+ }
+ if (key in modifierkeys){
+ modifierkeys[key]();
+ return false;
+ }
+ return true;
+ });
+
+ $(document).bind("keyup", function(e) {
+ if (e.metaKey) return true;
+ var key = special_keys[e.keyCode] || String.fromCharCode(e.keyCode);
+ if (key in modifierkeys){
+ modifierkeys[key]();
+ return false;
}
- return true
+ return true;
});

0 comments on commit d145a1a

Please sign in to comment.
Something went wrong with that request. Please try again.