1
1

Controls.ts 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. module Controls {
  2. export function createBigButton (text : string, resolve : (t : string) => void) {
  3. let p = document.createElement("p");
  4. p.classList.add("choice");
  5. p.appendChild(document.createTextNode(text));
  6. p.addEventListener("click", () => {
  7. resolve(text);
  8. });
  9. Controls.KeyHandler.applyCode(p, Controls.KeyHandler.getFirstKeyCode());
  10. return p;
  11. }
  12. export async function giveChoices (big? : boolean, ...choices : Array<string>) {
  13. let buttons;
  14. let chosenPromise = <Promise<string>> new Promise((async (resolve) => {
  15. Controls.KeyHandler.reset();
  16. let say = new Say();
  17. choices.forEach(choice => {
  18. say.add(createBigButton(choice, resolve))
  19. });
  20. buttons = await say.getHTMLContent();
  21. Elements.CurrentTurnHandler.print(...(buttons));
  22. }));
  23. let chosen = await chosenPromise;
  24. Elements.CurrentTurnHandler.unprint(...buttons);
  25. return [chosen, choices.indexOf(chosen)];
  26. }
  27. }