main.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. var settings = new Settings();
  2. var debug = false;
  3. var isStatsOn = false;
  4. var authWindow;
  5. var app;
  6. var runLoop = function() {
  7. app.update();
  8. app.draw();
  9. }
  10. var initApp = function() {
  11. if (app!=null) { return; }
  12. app = new App(settings, document.getElementById('canvas'));
  13. window.addEventListener('resize', app.resize, false);
  14. document.addEventListener('mousemove', app.mousemove, false);
  15. document.addEventListener('mousedown', app.mousedown, false);
  16. document.addEventListener('mouseup', app.mouseup, false);
  17. document.addEventListener('touchstart', app.touchstart, false);
  18. document.addEventListener('touchend', app.touchend, false);
  19. document.addEventListener('touchcancel', app.touchend, false);
  20. document.addEventListener('touchmove', app.touchmove, false);
  21. document.addEventListener('keydown', app.keydown, false);
  22. document.addEventListener('keyup', app.keyup, false);
  23. setInterval(runLoop,30);
  24. }
  25. var forceInit = function() {
  26. initApp()
  27. document.getElementById('unsupported-browser').style.display = "none";
  28. return false;
  29. }
  30. if(Modernizr.canvas && Modernizr.websockets) {
  31. initApp();
  32. } else {
  33. document.getElementById('unsupported-browser').style.display = "block";
  34. document.getElementById('force-init-button').addEventListener('click', forceInit, false);
  35. }
  36. var addStats = function() {
  37. if (isStatsOn) { return; }
  38. // Draw fps
  39. var stats = new Stats();
  40. document.getElementById('fps').appendChild(stats.domElement);
  41. setInterval(function () {
  42. stats.update();
  43. }, 1000/60);
  44. // Array Remove - By John Resig (MIT Licensed)
  45. Array.remove = function(array, from, to) {
  46. var rest = array.slice((to || from) + 1 || array.length);
  47. array.length = from < 0 ? array.length + from : from;
  48. return array.push.apply(array, rest);
  49. };
  50. isStatsOn = true;
  51. }
  52. //document.addEventListener('keydown',function(e) {
  53. // if(e.which == 27) {
  54. // addStats();
  55. // }
  56. //})
  57. if(debug) { addStats(); }
  58. $(function() {
  59. $('a[rel=external]').click(function(e) {
  60. e.preventDefault();
  61. window.open($(this).attr('href'));
  62. });
  63. });
  64. document.body.onselectstart = function() { return false; }