Input.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. const Input = {};
  2. const inputs = require('../inputs/inputs');
  3. Input.process = function processInput (scene) {
  4. /*
  5. if (game.gamestate.inputsDisabled === true) {
  6. return false;
  7. }
  8. */
  9. const Game = require('./Game');
  10. if (Game.servermode) {
  11. // console.log('server only')
  12. return;
  13. }
  14. if (Game.clientMode) {
  15. return;
  16. }
  17. let Things = scene.Things;
  18. for (let player in inputs) {
  19. for (let input in inputs[player]) {
  20. if (!Things[player] || !Things[player].inputs) {
  21. continue;
  22. }
  23. if (scene.input) {
  24. var key = scene.input.keyboard.addKey(inputs[player][input]);
  25. Things[player].inputs = Things[player].inputs || {};
  26. if (key.isDown) {
  27. Things[player].inputs[input] = true;
  28. } else {
  29. Things[player].inputs[input] = false;
  30. }
  31. }
  32. }
  33. }
  34. }
  35. Input.removeAll = function removeAllInput (game) {
  36. const Things = require('./Things');
  37. for (let player in inputs) {
  38. for (let input in inputs[player]) {
  39. if (!Things[player] || !Things[player].inputs) {
  40. continue;
  41. }
  42. console.log('iiii', input, player, inputs[player][input])
  43. console.log(inputs[player][input])
  44. var key = game.input.keyboard.removeKey(inputs[player][input]);
  45. }
  46. }
  47. }
  48. module.exports = Input;