Rewrite main loop and input handling to work in browser
Bugfix
Make input handling work in browser
Bugfix