1
1

KeySetter.ts 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. module Controls.KeyHandler.KeySetter {
  2. let resolver;
  3. let div = document.createElement("div");
  4. function printTable() {
  5. let p = document.createElement("p");
  6. p.classList.add("content");
  7. p.appendChild(document.createTextNode("Each row usually has a purpose, though any row will do if there are not enough keys in the ideal row."));
  8. Elements.CurrentTurnHandler.print(p);
  9. p = document.createElement("p");
  10. p.classList.add("content");
  11. p.appendChild(document.createTextNode("Row 1 is preferred for Choices and Room Objects. Row 2 is used for commands relating to the selected thing (Take, Wear). Row 3 is used for commands that you do without targets (Get Up, Wait, Save game)."));
  12. Elements.CurrentTurnHandler.print(p);
  13. p = document.createElement("p");
  14. p.classList.add("content");
  15. p.appendChild(document.createTextNode("Select the row you wish to edit and press keys to add them to the list. You can press Backspace to clear it."));
  16. Elements.CurrentTurnHandler.print(p);
  17. for (let i = 1; i <= Controls.KeyHandler.keyRows; i++) {
  18. let p = document.createElement("p");
  19. p.classList.add("content");
  20. p.appendChild(document.createTextNode("Row " + i + ": "));
  21. let input = document.createElement("input");
  22. input.classList.add("keySelectorInput");
  23. p.appendChild(input);
  24. let updateInput = () => {
  25. let keys = <Array<KeyCode>> Controls.KeyHandler["keyCodes" + i].getValue();
  26. let values = [];
  27. keys.forEach(key => {
  28. values.push(key.representation)
  29. });
  30. input.value = values.join("; ");
  31. };
  32. updateInput();
  33. let inputF = (ev : KeyboardEvent) => {
  34. Controls.KeyHandler.addKey(i, ev);
  35. updateInput();
  36. ev.stopPropagation();
  37. ev.preventDefault();
  38. };
  39. input.addEventListener("keydown", inputF);
  40. input.addEventListener("keyup", (ev) => {ev.stopPropagation();});
  41. Elements.CurrentTurnHandler.print(p);
  42. }
  43. }
  44. function printConfirm () {
  45. (new Say("Confirm")).getHTML("p", ["choice"]).then(elementArray => {
  46. elementArray[0].addEventListener("click", () => {
  47. resolver();
  48. });
  49. Controls.KeyHandler.applyCode(elementArray[0], Controls.KeyHandler.getSecondKeyCode());
  50. Elements.CurrentTurnHandler.print(elementArray[0]);
  51. });
  52. }
  53. function reset () {
  54. Elements.CurrentTurnHandler.clear();
  55. Elements.CurrentTurnHandler.print(div);
  56. printTable();
  57. Elements.CurrentTurnHandler.print(document.createElement("br"));
  58. Elements.CurrentTurnHandler.print(document.createElement("br"));
  59. printConfirm();
  60. }
  61. export async function setKeys () {
  62. Elements.startMenu();
  63. let promise = new Promise(resolve => {
  64. resolver = resolve;
  65. });
  66. reset();
  67. await promise;
  68. Elements.endMenu();
  69. }
  70. }