12345678910111213141516171819202122232425262728293031323334 |
- module Controls {
- export function createBigButton (text : string, resolve : (t : string) => void) {
- let p = document.createElement("p");
- p.classList.add("choice");
- p.appendChild(document.createTextNode(text));
- p.addEventListener("click", () => {
- resolve(text);
- });
- Controls.KeyHandler.applyCode(p, Controls.KeyHandler.getFirstKeyCode());
- return p;
- }
- export async function giveChoices (big? : boolean, ...choices : Array<string>) {
- let buttons;
- let chosenPromise = <Promise<string>> new Promise((async (resolve) => {
- Controls.KeyHandler.reset();
- let say = new Say();
- choices.forEach(choice => {
- say.add(createBigButton(choice, resolve))
- });
- buttons = await say.getHTMLContent();
- Elements.CurrentTurnHandler.print(...(buttons));
- }));
- let chosen = await chosenPromise;
- Elements.CurrentTurnHandler.unprint(...buttons);
- return [chosen, choices.indexOf(chosen)];
- }
- }
|