Skip to content

Commit

Permalink
Prevent key clicks from moving the window around. Make sure we don't …
Browse files Browse the repository at this point in the history
…take actions or prevent keystrokes if we're focused on the chat input.
  • Loading branch information
alecpm committed Aug 15, 2023
1 parent 0e05a3a commit 338af7b
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 9 deletions.
1 change: 1 addition & 0 deletions dlgr/griduniverse/config.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ rows = 100
window_rows = 20
window_columns = 20
use_identicons = true
show_chatroom = true

[HIT Configuration]
title = Griduniverse
Expand Down
24 changes: 21 additions & 3 deletions dlgr/griduniverse/static/scripts/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -732,10 +732,17 @@ function bindGameKeys(socket) {
}
}

function isChatting() {
return $("#message").is(':focus');
}

directions.forEach(function(direction) {
Mousetrap.bind(
direction,
function(e) {
if (isChatting()) {
return;
}
e.preventDefault();
if (direction === lastDirection) {
return;
Expand All @@ -756,6 +763,9 @@ function bindGameKeys(socket) {
Mousetrap.bind(
direction,
function(e) {
if (isChatting()) {
return;
}
e.preventDefault();
if (direction) {
clearInterval(repeatIntervalId);
Expand All @@ -767,7 +777,11 @@ function bindGameKeys(socket) {

});

Mousetrap.bind("space", function () {
Mousetrap.bind("space", function (e) {
if (isChatting()) {
return;
}
e.preventDefault();
var msg_type;
var ego = players.ego();
var position = ego.position;
Expand Down Expand Up @@ -808,7 +822,11 @@ function bindGameKeys(socket) {
socket.send(msg);
});

Mousetrap.bind("d", function () {
Mousetrap.bind("d", function (e) {
if (isChatting()) {
return;
}
e.preventDefault();
var ego = players.ego();
var position = ego.position;
var currentItem = ego.currentItem;
Expand Down Expand Up @@ -1398,7 +1416,7 @@ $(document).ready(function() {
return Math.floor(pix / (settings.block_size + settings.padding));
};

$("form").submit(function() {
$("form").on('submit', function() {
var chatmessage = $("#message").val().trim(),
msg;

Expand Down
24 changes: 21 additions & 3 deletions dlgr/griduniverse/static/scripts/dist/bundle.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dlgr/griduniverse/static/scripts/dist/bundle.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dlgr/griduniverse/static/scripts/dist/difi.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dlgr/griduniverse/static/scripts/dist/questionnaire.js.map

Large diffs are not rendered by default.

0 comments on commit 338af7b

Please sign in to comment.