cursors.io show player ids FINAL

Show players ids on cursors.io

  1. // ==UserScript==
  2. // @name cursors.io show player ids FINAL
  3. // @namespace q1k
  4. // @version 1.0.3
  5. // @description Show players ids on cursors.io
  6. // @author q1k
  7. // @match http://cursors.io/
  8. // @grant none
  9. // @run-at document-idle
  10. // ==/UserScript==
  11.  
  12.  
  13. function begin(w, z) {
  14. function qa(a) {
  15. return a << 1
  16. }
  17.  
  18. function ra(a) {
  19. return a << 1
  20. }
  21.  
  22. function S() {
  23. return z.pointerLockElement === x || z.mozPointerLockElement === x || z.webkitPointerLockElement === x
  24. }
  25.  
  26. function aa() {
  27. a.fillStyle = "#000000";
  28. a.font = "35px NovaSquare";
  29. a.fillText("Please do not embed our website, thank you.", 400 - a.measureText("Please do not embed our website, thank you.").width / 2, 300);
  30. a.font = "16px NovaSquare";
  31. a.fillText("Play the game on http://cursors.io/", 400 - a.measureText("Play the game on http://cursors.io/").width / 2, 330);
  32. top.location = "http://cursors.io";
  33. throw "Please do not embed our website, thank you.";
  34. }
  35.  
  36. function sa(a) {
  37. T(a)
  38. }
  39.  
  40. function U(a, b) {
  41. F = a;
  42. G = b;
  43. k = p = a;
  44. l = s = b;
  45. A = p << 1;
  46. B = s << 1
  47. }
  48.  
  49. function ta(a) {
  50. if (y) return H = !1, T(a), !1;
  51. S() ? V || (V = !0, U(k, l)) : (V = !1, y || I.checked || x.requestPointerLock && x.requestPointerLock());
  52. if (H) H = !1, J();
  53. else if (T(a), (a.ctrlKey || a.shiftKey) && !C.checked) W = !0, N = k, O = l;
  54. else if (100 < t - ba && p == k && s == l) {
  55. ba = t;
  56. D.push([p << 1, s << 1, t]);
  57. ua(p, s);
  58. var b = [p, s];
  59. K.push(b);
  60. setTimeout(function() {
  61. K.remove(b)
  62. }, 1E3)
  63. }
  64. return !1
  65. }
  66.  
  67. function va(a) {
  68. W = !1
  69. }
  70.  
  71. function ca() {
  72. function a(b, n) {
  73. q = new WebSocket("ws://" + (b || "[" + n + "]") + ":2828");
  74. q.binaryType = "arraybuffer";
  75. q.onopen = wa;
  76. q.onmessage = xa;
  77. q.onclose = ya;
  78. q.onerror = za
  79. }
  80. null == q && (Aa ? a("127.0.0.1", null) : m28n.findServerPreference("cursors", function(b, c) {
  81. null == q && (b || 0 == c.length ? (console.error(b), setTimeout(ca, 1E3)) : a(c[0].ipv4, c[0].ipv6))
  82. }))
  83. }
  84.  
  85. function Ba() {
  86. w.localStorage && I && (w.localStorage.setItem("noCursorLock", I.checked ? "1" : "0"), w.localStorage.setItem("noDrawings", C.checked ? "1" : "0"))
  87. }
  88.  
  89. function T(a) {
  90. if (S()) {
  91. var b = a.webkitMovementX || a.mozMovementX || a.movementX || 0;
  92. a = a.webkitMovementY || a.mozMovementY || a.movementY || 0;
  93. 300 > Math.abs(b) + Math.abs(a) && X(A + b, B + a)
  94. } else a.offsetX ? X(a.offsetX, a.offsetY) : a.layerX && X(a.layerX, a.layerY);
  95. if (y) k = p, l = s;
  96. else if (Y(), !S() || p == k && s == l || (a = b = 0, p > k && (b = 1), s > l && (a = 1), p = k, s = l, A = (p << 1) + b, B = (s << 1) + a), W && (N != k || O != l) && 50 < t - da) {
  97. b = N;
  98. a = O;
  99. var c = k,
  100. d = l;
  101. if (!y && null != q && q.readyState == WebSocket.OPEN) {
  102. var f = new ArrayBuffer(9),
  103. e = new DataView(f);
  104. e.setUint8(0, 3);
  105. e.setUint16(1, b, !0);
  106. e.setUint16(3, a, !0);
  107. e.setUint16(5, c, !0);
  108. e.setUint16(7, d, !0);
  109. q.send(f)
  110. }
  111. N = k;
  112. O = l;
  113. da = t
  114. }
  115. }
  116.  
  117. function X(a, b) {
  118. A = a;
  119. B = b;
  120. p = A >> 1;
  121. s = B >> 1
  122. }
  123.  
  124. function Y() {
  125. var a = k,
  126. b = l;
  127. if (P(k, l)) {
  128. var c;
  129. a: {
  130. c = k;
  131. var d = l,
  132. f = [],
  133. e = new Uint8Array(12E4);f.push([c, d]);e[c + 400 * d] = 1;do {
  134. var h = f.shift(),
  135. g = h[0],
  136. h = h[1];
  137. if (!(0 > g || 0 > h || 400 <= g || 300 <= h)) {
  138. if (!P(g, h)) {
  139. c = {
  140. x: g,
  141. y: h
  142. };
  143. break a
  144. }
  145. e[g - 1 + 400 * h] || (f.push([g - 1, h]), e[g - 1 + 400 * h] = 1);
  146. e[g + 1 + 400 * h] || (f.push([g + 1, h]), e[g + 1 + 400 * h] = 1);
  147. e[g + 400 * (h - 1)] || (f.push([g, h - 1]), e[g + 400 * (h - 1)] = 1);
  148. e[g + 400 * (h + 1)] || (f.push([g, h + 1]), e[g + 400 * (h + 1)] = 1)
  149. }
  150. } while (0 < f.length);c = {
  151. x: c,
  152. y: d
  153. }
  154. }
  155. k = c.x;
  156. l = c.y
  157. }
  158. if (k != p || l != s) c = ea(k, l, p, s), k = c.x, l = c.y;
  159. fa(F, G, a, b) && !fa(F, G, k, l) && (J(a, b), J(k, l));
  160. a: {
  161. for (a = 0; a < m.length; a++)
  162. if (b = m[a], 2 == b.type && !(k < b.x || l < b.y || k >= b.x + b.width || l >= b.y + b.height)) {
  163. a = !0;
  164. break a
  165. }
  166. a = !1
  167. }
  168. a && J()
  169. }
  170.  
  171. var countlevels=-2;
  172. function Z() {
  173. Q.set(Ca);
  174. m = [];
  175. D = [];
  176. L = []
  177. countlevels+=1;
  178. }
  179.  
  180. function wa() {
  181. Z();
  182. console.log("Connected!")
  183. }
  184.  
  185. function ya(a) {
  186. Z();
  187. console.log("Socket closed: " + a.reason)
  188. }
  189.  
  190. function za(a) {
  191. console.log("Socket error")
  192. }
  193.  
  194. function Da(a, b) {
  195. for (var c = "", d = 0, f = 0; 0 != (f = a.getUint8(b)); ++b) d <<= 8, d |= f, f & 128 || (c += String.fromCharCode(d), d = 0);
  196. 0 != d && (c += String.fromCharCode(d));
  197. return [c, b + 1]
  198. }
  199.  
  200. function Ea(a, b) {
  201. setTimeout(function() {
  202. var c = a.getUint16(b, !0),
  203. d = 0;
  204. a: for (; d < c; d++) {
  205. for (var f = a.getUint16(b + 2 + 4 * d, !0), e = a.getUint16(b + 4 + 4 * d, !0), h = 0; h < K.length; h++) {
  206. var g = K[h];
  207. if (g[0] == f && g[1] == e) {
  208. K.splice(h, 1);
  209. continue a
  210. }
  211. }
  212. D.push([f << 1, e << 1, t])
  213. }
  214. }, 100);
  215. return b + 2 + 4 * a.getUint16(b, !0)
  216. }
  217.  
  218. function Fa(a, b) {
  219. !C.checked && setTimeout(function() {
  220. for (var c = a.getUint16(b, !0), d = 0; d < c; d++) {
  221. var f = a.getUint16(b + 2 + 8 * d, !0),
  222. e = a.getUint16(b +
  223. 4 + 8 * d, !0),
  224. h = a.getUint16(b + 6 + 8 * d, !0),
  225. g = a.getUint16(b + 8 + 8 * d, !0);
  226. L.push([f << 1, e << 1, h << 1, g << 1, t])
  227. }
  228. }, 50);
  229. return b + 2 + 8 * a.getUint16(b, !0)
  230. }
  231.  
  232. function xa(a) {
  233. a = a.data;
  234. var b = new DataView(a);
  235. switch (b.getUint8(0)) {
  236. case 0:
  237. ga = b.getUint32(1, !0);
  238. break;
  239. case 1:
  240. var c;
  241. ha = c = b.getUint16(1, !0);
  242. ia = 100 <= c;
  243. var d = [],
  244. f;
  245. for (f in v) v.hasOwnProperty(f) && d.push(f);
  246. for (var e = 0; e < c; e++) {
  247. f = b.getUint32(3 + 8 * e, !0);
  248. var h = b.getUint16(7 + 8 * e, !0),
  249. g = b.getUint16(9 + 8 * e, !0);
  250. if (f != ga)
  251. if (null != v[f]) {
  252. for (var r = 0; r < d.length; r++)
  253. if (d[r] == f) {
  254. d.splice(r, 1);
  255. break
  256. }
  257. f = v[f];
  258. f.oldX = f.getX();
  259. f.oldY = f.getY();
  260. f.newX = h;
  261. f.newY = g;
  262. f.time = t
  263. } else v[f] = new ja(h, g)
  264. }
  265. for (e = 0; e < d.length; e++) delete v[d[e]];
  266. c = Ea(b, 3 + 8 * c);
  267. f = b.getUint16(c, !0);
  268. c += 2;
  269. for (d = 0; d < f; d++) {
  270. a: for (h = b.getUint32(c, !0), e = 0; e < m.length; e++)
  271. if (m[e].id == h) {
  272. var k = m[e];
  273. if (1 == k.type)
  274. for (var h = k.x | 0, g = k.y | 0, r = k.width | 0, k = k.height | 0, l = g; l < g + k; ++l)
  275. for (var p = h; p < h + r; ++p) --Q[p + 400 * l];
  276. m.splice(e, 1);
  277. break a
  278. }c += 4
  279. }
  280. f = b.getUint16(c, !0);
  281. c += 2;
  282. for (d = 0; d < f; d++) {
  283. a: {
  284. e = b.getUint32(c, !0);
  285. for (h = 0; h < m.length; h++)
  286. if (m[h].id == e) {
  287. e = m[h];
  288. break a
  289. }
  290. e = {
  291. id: e
  292. };m.push(e)
  293. }
  294. c += 4;c = ka(b, c, e)
  295. }
  296. c = Fa(b, c);
  297. if (a.byteLength < c + 4) break;
  298. $ = b.getUint32(c, !0);
  299. break;
  300. case 4:
  301. Z();
  302. U(b.getUint16(1, !0), b.getUint16(3, !0));
  303. f = b.getUint16(5, !0);
  304. c = 7;
  305. for (d = 0; d < f; d++) e = {}, e.id = b.getUint32(c, !0), c += 4, c = ka(b, c, e), m.push(e);
  306. a.byteLength >= c + 4 ? u = Math.max(u, b.getUint32(c, !0)) : a.byteLength >= c + 2 && (u = Math.max(u, b.getUint16(c, !0)));
  307. Y();
  308. break;
  309. case 5:
  310. U(b.getUint16(1, !0), b.getUint16(3, !0)), 9 <= b.byteLength ? u = Math.max(u, b.getUint32(5, !0)) : 7 <= b.byteLength && (u = Math.max(u, b.getUint16(5, !0))), Y()
  311. }
  312. }
  313.  
  314. function J(a, b) {
  315. if (!y && !H && null != q && q.readyState == WebSocket.OPEN && ("undefined" == typeof a && (a = k), "undefined" == typeof b && (b = l), a != F || b != G)) {
  316. var c = new ArrayBuffer(9),
  317. d = new DataView(c);
  318. d.setUint8(0, 1);
  319. d.setUint16(1, a, !0);
  320. d.setUint16(3, b, !0);
  321. d.setUint32(5, u, !0);
  322. q.send(c);
  323. F = a;
  324. G = b
  325. }
  326. }
  327.  
  328. function ua(a, b) {
  329. if (!y && null != q && q.readyState == WebSocket.OPEN) {
  330. var c = new ArrayBuffer(9),
  331. d = new DataView(c);
  332. d.setUint8(0, 2);
  333. d.setUint16(1, a, !0);
  334. d.setUint16(3, b, !0);
  335. d.setUint32(5, u, !0);
  336. q.send(c)
  337. }
  338. }
  339.  
  340. function ka(a, b, c) {
  341. function d() {
  342. c.x = a.getUint16(b, !0);
  343. b += 2;
  344. c.y = a.getUint16(b, !0);
  345. b += 2;
  346. c.width = a.getUint16(b, !0);
  347. b += 2;
  348. c.height = a.getUint16(b, !0);
  349. b += 2
  350. }
  351.  
  352. function f() {
  353. for (var d = a.getUint32(b, !0).toString(16); 6 > d.length;) d = "0" + d;
  354. b += 4;
  355. c.color = "#" + d
  356. }
  357. var e = a.getUint8(b);
  358. b += 1;
  359. c.type = e;
  360. switch (e) {
  361. case 255:
  362. break;
  363. case 0:
  364. c.x = a.getUint16(b, !0);
  365. b += 2;
  366. c.y = a.getUint16(b, !0);
  367. b += 2;
  368. c.size = a.getUint8(b);
  369. b += 1;
  370. c.isCentered = !!a.getUint8(b);
  371. b += 1;
  372. e = Da(a, b);
  373. c.text = e[0];
  374. b = e[1];
  375. break;
  376. case 1:
  377. d();
  378. var h = !c.color;
  379. f();
  380. var e = c.x | 0,
  381. g = c.y | 0,
  382. k = c.width | 0,
  383. l = c.height | 0;
  384. if (h)
  385. for (h = g; h < g + l; ++h)
  386. for (var m = e; m < e + k; ++m) ++Q[m + 400 * h];
  387. break;
  388. case 2:
  389. d();
  390. c.isBad = !!a.getUint8(b);
  391. b += 1;
  392. break;
  393. case 3:
  394. d();
  395. c.count = a.getUint16(b, !0);
  396. b += 2;
  397. f();
  398. break;
  399. case 4:
  400. d();
  401. c.count ? c.count > a.getUint16(b, !0) && (c.lastClickAt = t) : c.lastClickAt = 0;
  402. c.count = a.getUint16(b, !0);
  403. b += 2;
  404. f();
  405. break;
  406. default:
  407. throw Error("Unknown object type " + e);
  408. }
  409. return b
  410. }
  411.  
  412. function la() {
  413. a.clearRect(0, 0, 800, 600);
  414. a.save();
  415. if (null != q && q.readyState != WebSocket.OPEN || H) {
  416. var n;
  417. if (null == q) n = "Click to begin";
  418. else switch (q.readyState) {
  419. case WebSocket.CONNECTING:
  420. n = "Connecting";
  421. break;
  422. case WebSocket.CLOSING:
  423. case WebSocket.CLOSED:
  424. n = "Lost connection to server";
  425. break;
  426. default:
  427. n = "Click to begin"
  428. }
  429. a.font = "60px NovaSquare";
  430. a.fillText(n, 400 - a.measureText(n).width / 2, 315);
  431. ma();
  432. a.font = 20 + "px NovaSquare";
  433. f = "-> show player ids with F8 <-";
  434. a.fillText(f, 400 - a.measureText(f).width / 2, 345);
  435. na(!1)
  436. } else {
  437. a.fillStyle="white";
  438. a.fillRect(0, 0, canvas.width, canvas.height);
  439. a.fillStyle = "#000000";
  440. a.save();
  441. a.globalAlpha = 1;
  442. Ga();
  443. for (n = 0; n < m.length; n++) {
  444. var b = m[n];
  445. if (0 == b.type) {
  446. a.font = b.size + "px NovaSquare";
  447. var c = b.x << 1,
  448. d = b.y << 1;
  449. b.isCentered && (c -= a.measureText(b.text).width / 2);
  450. a.fillStyle = "#000000";
  451. a.fillText(b.text, c, d)
  452. } else if (1 == b.type) a.fillStyle = b.color, a.fillRect(b.x << 1, b.y << 1, b.width << 1, b.height << 1), a.strokeStyle = "#000000", a.globalAlpha = .2, a.lineWidth = 2, a.strokeRect((b.x << 1) + 1, (b.y << 1) + 1, (b.width << 1) - 2, (b.height << 1) - 2), a.globalAlpha = 1;
  453. else if (2 == b.type) a.fillStyle = b.isBad ? "#FF0000" : "#00FF00", a.globalAlpha = .2, a.fillRect(b.x << 1, b.y << 1, b.width << 1, b.height << 1), a.globalAlpha = 1;
  454. else if (3 == b.type) {
  455. var c = b.x << 1,
  456. d = b.y << 1,
  457. f = b.width << 1,
  458. e = b.height << 1;
  459. a.fillStyle = b.color;
  460. a.globalAlpha = .2;
  461. a.fillRect(c, d, f, e);
  462. a.globalAlpha = .5;
  463. a.fillStyle = "#000000";
  464. 40 > b.width || 40 > b.height ? (a.font = "30px NovaSquare", a.fillText(b.count, c + f / 2 - a.measureText(b.count).width / 2, d + e / 2 + 10)) : (a.font = "60px NovaSquare", a.fillText(b.count, c + f / 2 - a.measureText(b.count).width / 2, d + e / 2 + 20));
  465. a.globalAlpha = 1
  466. } else if (4 == b.type) {
  467. c = b.x << 1;
  468. d = b.y << 1;
  469. f = b.width << 1;
  470. e = b.height << 1;
  471. a.fillStyle = b.color;
  472. a.strokeStyle = b.color;
  473. a.globalAlpha = 1;
  474. a.fillRect(c, d, f, e);
  475. a.globalAlpha = .2;
  476. a.fillStyle = "#000000";
  477. a.fillRect(c, d, f, e);
  478. a.globalAlpha = 1;
  479. a.fillStyle = b.color;
  480. var h = 150 > t - b.lastClickAt,
  481. g = h ? 8 : 12;
  482. a.fillRect(c + g, d + g, f - 2 * g, e - 2 * g);
  483. a.strokeStyle = "#000000";
  484. a.globalAlpha = .1;
  485. a.beginPath();
  486. a.moveTo(c, d);
  487. a.lineTo(c + g, d + g);
  488. a.moveTo(c + f, d);
  489. a.lineTo(c + f - g, d + g);
  490. a.moveTo(c, d + e);
  491. a.lineTo(c + g, d + e - g);
  492. a.moveTo(c + f, d + e);
  493. a.lineTo(c + f - g, d + e - g);
  494. a.moveTo(c, d);
  495. a.rect(c, d, f, e);
  496. a.rect(c + g, d + g, f - 2 * g, e - 2 * g);
  497. a.stroke();
  498. a.fillStyle = "#000000";
  499. a.globalAlpha = .5;
  500. 50 > b.width || 50 > b.height ? (a.font = "35px NovaSquare", a.fillText(b.count, c + f / 2 - a.measureText(b.count).width / 2, d + e / 2 + 13)) : (a.font = "45px NovaSquare", a.fillText(b.count, c + f / 2 - a.measureText(b.count).width / 2, d + e / 2 + 16));
  501. h && (a.fillStyle = "#000000", a.globalAlpha = .15, a.fillRect(c + g, d + g, f - 2 * g, e - 2 * g));
  502. a.globalAlpha = 1
  503. }
  504. }
  505. a.restore();
  506. y || (a.font = "12px NovaSquare", a.strokeStyle = "#000000", a.fillStyle = "#FFFFFF", a.lineWidth = 2.5, n = ia ? "Area too full, not all cursors are shown" : 30 < ha ? "Area too full, drawing is disabled" : "Use shift+click to draw", a.globalAlpha = .5, a.strokeText(n, 10, 590), a.globalAlpha = 1, a.fillText(n, 10, 590), 0 != $ && (n = $ + " players online", b = a.measureText(n).width, a.globalAlpha = .5, a.strokeText(n, 790 - b, 590), a.globalAlpha = 1, a.fillText(n, 790 - b, 590)));
  507. if (countlevels>0) {
  508. f = "level: "+countlevels, b = a.measureText(f).width, a.globalAlpha = .5, a.strokeText(f, 790 - b, 560), a.globalAlpha = 1;
  509. a.fillText(f, 790 - b, 560);
  510. }
  511. ma();
  512. if (!C.checked) {
  513. a.save();
  514. a.strokeStyle = "#000000";
  515. a.lineWidth = 1;
  516. t = +new Date;
  517. for (n = 0; n < L.length; n++) b = L[n], c = 10 - (t - b[4]) / 1E3, 0 >= c ? (L.splice(n, 1), --n) : (1 < c && (c = 1), a.globalAlpha = .3 * c, a.beginPath(), a.moveTo(b[0] - .5, b[1] - .5), a.lineTo(b[2] - .5, b[3] - .5), a.stroke());
  518. a.restore()
  519. }
  520. a.save();
  521. for (var po in v) {
  522. v.hasOwnProperty(po) && a.drawImage(M, qa(v[po].getX()) - 6, ra(v[po].getY()) - 6, 23, 30);
  523. if (showcursorsid) {
  524. if(cursorIDPos==2){
  525. cp=a.measureText(po).width;
  526. a.globalAlpha = .5; a.strokeText( po, qa(v[po].getX()) - cp + cursorIDX, ra(v[po].getY()) + cursorIDY );
  527. a.globalAlpha= 1; a.fillText( po, qa(v[po].getX()) - cp + cursorIDX, ra(v[po].getY()) + cursorIDY );
  528. }
  529. else {
  530. a.globalAlpha = .5; a.strokeText( po, qa(v[po].getX()) + cursorIDX, ra(v[po].getY()) + cursorIDY );
  531. a.globalAlpha= 1; a.fillText( po, qa(v[po].getX()) + cursorIDX, ra(v[po].getY()) + cursorIDY );
  532. }
  533. }
  534.  
  535. }
  536. if (showcursorsid) {
  537. if(cursorIDPos==2){
  538. cp=a.measureText(ga).width;
  539. a.globalAlpha = .5; a.strokeText( ga, qa(k) - cp + cursorIDX, ra(l) + cursorIDY ) ;
  540. a.globalAlpha= 1; a.fillText( ga, qa(k) - cp + cursorIDX, ra(l) + cursorIDY ) ;
  541. }
  542. else {
  543. a.globalAlpha = .5; a.strokeText( ga, qa(k) + cursorIDX, ra(l) + cursorIDY ) ;
  544. a.globalAlpha= 1; a.fillText( ga, qa(k) + cursorIDX, ra(l) + cursorIDY ) ;
  545. }
  546. }
  547.  
  548. a.restore();
  549. na(!0)
  550. }
  551. a.restore();
  552. w.requestAnimationFrame(la)
  553. }
  554.  
  555. function ma() {
  556. a.save();
  557. a.strokeStyle = "#000000";
  558. t = +new Date;
  559. for (var n = 0; n < D.length; n++) {
  560. var b = D[n],
  561. c = (t - b[2]) / 1E3,
  562. d = 1 - 2 * c;
  563. 0 >= d ? (D.splice(n, 1), --n) : (c *= 50, a.beginPath(), a.globalAlpha = .3 * d, a.arc(b[0], b[1], c, 0, 2 * Math.PI, !1), a.stroke())
  564. }
  565. a.restore()
  566. }
  567.  
  568. function na(n) {
  569. if (y) a.save(), a.globalAlpha = 1, a.drawImage(M, A - 5, B - 5);
  570. else {
  571. var b = 0,
  572. c = 0;
  573. p != k || s != l ? (a.save(), n && (a.globalAlpha = .2, a.fillStyle = "#FF0000", a.beginPath(), a.arc(A + 2, B + 8, 20, 0, 2 * Math.PI, !1), a.fill()), a.globalAlpha = .5, a.drawImage(M, A - 5, B - 5, 23, 30), a.restore()) : (b = A & 1, c = B & 1);
  574. a.save();
  575. n && (a.globalAlpha = .2, a.fillStyle = "#FFFF00", a.beginPath(), a.arc((k << 1) + b + 2, (l << 1) + c + 8, 20, 0, 2 * Math.PI, !1), a.fill());
  576. a.globalAlpha = 1;
  577. a.drawImage(Ha, (k << 1) + b - 5, (l << 1) + c - 5, 23, 30)
  578. }
  579. a.restore()
  580. }
  581.  
  582. function ja(a, b) {
  583. this.oldX = this.newX = a;
  584. this.oldY = this.newY = b;
  585. this.time = t
  586. }
  587.  
  588. function oa(a) {
  589. return a * a * (3 - 2 * a)
  590. }
  591.  
  592. function ea(a, b, c, d) {
  593. a |= 0;
  594. b |= 0;
  595. c |= 0;
  596. d |= 0;
  597. if (P(a, b)) return {
  598. x: a,
  599. y: b
  600. };
  601. if (a == c && b == d) return {
  602. x: c,
  603. y: d
  604. };
  605. var f = a,
  606. e = b;
  607. c = c - a | 0;
  608. d = d - b | 0;
  609. var h = 0,
  610. g = 0,
  611. k = 0,
  612. l = 0;
  613. 0 > c ? h = -1 : 0 < c && (h = 1);
  614. 0 > d ? g = -1 : 0 < d && (g = 1);
  615. 0 > c ? k = -1 : 0 < c && (k = 1);
  616. var m = Math.abs(c) | 0,
  617. p = Math.abs(d) | 0;
  618. m <= p && (m = Math.abs(d) | 0, p = Math.abs(c) | 0, 0 > d ? l = -1 : 0 < d && (l = 1), k = 0);
  619. c = m >> 1;
  620. for (d = 0; d <= m && !P(a, b); d++) f = a, e = b, c += p, c >= m ? (c -= m, a += h, b += g) : (a += k, b += l);
  621. return {
  622. x: f,
  623. y: e
  624. }
  625. }
  626.  
  627. function fa(a, b, c, d) {
  628. a = ea(a, b, c, d);
  629. return a.x == c && a.y == d
  630. }
  631.  
  632. function P(a, b) {
  633. return 0 > a || 400 <= a || 0 > b || 300 <= b ? !0 : Q[a + 400 * b]
  634. }
  635. var Aa = "file:" == w.location.protocol,
  636. E, a, x, ha = 0,
  637. p = 0,
  638. s = 0,
  639. A = 0,
  640. B = 0,
  641. k = 0,
  642. l = 0,
  643. F = -1,
  644. G = -1,
  645. I = null,
  646. C = null,
  647. M = new Image;
  648. M.src = "img/cursor.png";
  649. var Ha = M,
  650. y = -1 != w.location.search.indexOf("editor"),
  651. D = [],
  652. L = [],
  653. t = 0,
  654. ba = 0,
  655. q = null,
  656. ga = -1,
  657. v = {},
  658. $ = 0,
  659. ia = !1,
  660. W = !1,
  661. N = 0,
  662. O = 0,
  663. da = 0,
  664. V = !1,
  665. H = !y && !0,
  666. Q = new Uint8Array(12E4),
  667. m = [],
  668. K = [],
  669. R = w.devicePixelRatio,
  670. cp = 0;
  671. Array.prototype.remove = function(a) {
  672. a = this.indexOf(a);
  673. return -1 != a ? (this.splice(a, 1), !0) : !1
  674. };
  675. var u = 0;
  676. ja.prototype = {
  677. oldX: 0,
  678. oldY: 0,
  679. newX: 0,
  680. newY: 0,
  681. time: 0,
  682. getX: function() {
  683. var a = this.newX - this.oldX,
  684. b = (t - this.time) / 100,
  685. b = oa(0 >= b ? 0 : 1 <= b ? 1 : b);
  686. return this.oldX + b * a
  687. },
  688. getY: function() {
  689. var a = this.newY - this.oldY,
  690. b = (t - this.time) / 100,
  691. b = oa(0 >= b ? 0 : 1 <= b ? 1 : b);
  692. return this.oldY + b * a
  693. }
  694. };
  695. var pa = function() {
  696. function n() {
  697. var a = 0,
  698. b = 0,
  699. c = p / 10,
  700. d = s / 10;
  701. h < c ? (c = Math.ceil(c), a = Math.floor(h)) : (c = Math.floor(c), a = Math.ceil(h));
  702. g < d ? (d = Math.ceil(d), b = Math.floor(g)) : (d = Math.floor(d), b = Math.ceil(g));
  703. if (a > c) var e = c,
  704. c = a,
  705. a = e;
  706. b > d && (e = d, d = b, b = e);
  707. return {
  708. sx: a,
  709. sy: b,
  710. fx: c,
  711. fy: d
  712. }
  713. }
  714.  
  715. function b() {
  716. e = !0;
  717. h = p / 10;
  718. g = s / 10
  719. }
  720.  
  721. function c(a) {
  722. return "0x" + parseInt(a.slice(1), 16).toString(16).toUpperCase()
  723. }
  724.  
  725. function d(a, b, c, d, e) {
  726. a = {
  727. x: 10 * ~~(k / 10) - ~~(a / 2) + c,
  728. y: 10 * ~~(l / 10) - ~~(b / 2) + d,
  729. width: a,
  730. height: b
  731. };
  732. for (var f in e) e.hasOwnProperty(f) && (a[f] = e[f]);
  733. return a
  734. }
  735.  
  736. function f(a, b) {
  737. for (var c = null, d = Number.POSITIVE_INFINITY, e = 0; e < m.length; e++) {
  738. var f = m[e];
  739. if (f.hasOwnProperty("x") && f.hasOwnProperty("y") && f.hasOwnProperty("width") && f.hasOwnProperty("height")) {
  740. var g = f.x + f.width / 2,
  741. h = f.y + f.height / 2,
  742. g = (a - g) * (a - g) + (b - h) * (b - h);
  743. g < d && (d = g, c = f)
  744. }
  745. }
  746. return c
  747. }
  748. var e = !1,
  749. h = 0,
  750. g = 0,
  751. r = 1,
  752. q = 200,
  753. t = 150,
  754. v = new Uint8Array(1200),
  755. u = "#000000 #FF9999 #9999FF #FFFF99 #99FFFF #FF99FF #3333FF".split(" ");
  756. z.addEventListener("mouseup", function() {
  757. if (e) {
  758. for (var a = n(), b = r, c = a.sy; c < a.fy; ++c)
  759. for (var d = a.sx; d < a.fx; ++d) v[d + 40 * c] = b;
  760. e = !1
  761. }
  762. });
  763. z.addEventListener("mousemove", function() {});
  764. w.generateCode = function() {
  765. for (var a = "class Level? : public Level {\npublic:\n\tLevel?() : Level(" + q + ", " + t + "){}\n\n\tvoid OnInit(){\n", a = a + ("\t\tstd::vector<LevelObject*> wallByColor[" + u.length + "];\n"), b = new Uint8Array(1200), d = [], e = 0; 30 > e; ++e)
  766. for (var f = 0; 40 > f; ++f)
  767. if (!b[f + 40 * e]) {
  768. var g = v[f + 40 * e];
  769. if (0 != g) {
  770. for (var h = f; 40 > f && v[f + 40 * e] == g && !b[f + 40 * e];) b[f + 40 * e] = !0, ++f;
  771. var k = f--,
  772. n = k - h,
  773. l = e++;
  774. a: for (; 30 > e;) {
  775. for (var p = h; p < k; ++p) {
  776. if (v[p + 40 * e] != g) break a;
  777. if (b[p +
  778. 40 * e]) break a
  779. }
  780. for (p = h; p < k; ++p) b[p + 40 * e] = !0;
  781. ++e
  782. }
  783. k = e - l;
  784. e = l;
  785. d.push({
  786. x: 10 * h,
  787. y: 10 * l,
  788. width: 10 * n,
  789. height: 10 * k,
  790. color: g - 1
  791. })
  792. }
  793. }
  794. for (b = 0; b < d.length; b++) e = d[b], 0 == e.color ? a += "\t\tAddObject(new ObjWall(" + e.x + ", " + e.y + ", " + e.width + ", " + e.height + ", 0x000000));\n" : (f = c(u[e.color]), a += "\t\twallByColor[" + e.color + "].push_back(AddObject(new ObjWall(" + e.x + ", " + e.y + ", " + e.width + ", " + e.height + ", " + f + ")));\n");
  795. for (b = 0; b < m.length; b++) d = m[b], 0 != d.type && (2 == d.type ? a += "\t\tAddObject(new ObjTeleport(LevelManager::GetNextLevel(this), " +
  796. d.x + ", " + d.y + ", " + d.width + ", " + d.height + "));\n" : 3 == d.type ? (a += "\t\tAddObject(new ObjAreaCounter(wallByColor[" + d.colorCode + "], " + d.x + ", " + d.y + ", " + d.width + ", " + d.height + ", ", a += d.count + ", " + c(d.color) + "));\n") : 4 == d.type && (a += "\t\tAddObject(new ObjClickBox(wallByColor[" + d.colorCode + "], " + d.x + ", " + d.y + ", " + d.width + ", " + d.height + ", ", a += d.count + ", 1000, " + c(d.color) + "));\n"));
  797. return a += "\t}\n};\n"
  798. };
  799. z.addEventListener("keydown", function(a) {
  800. if (y) {
  801. var b = a.keyCode;
  802. 65 == b ? (--r, 0 > r && (r = u.length)) : 83 == b ? (++r, r > u.length && (r = 0)) : 66 == b ? 1 >= r || m.push(d(40, 40, 5, 5, {
  803. type: 4,
  804. color: u[r - 1],
  805. colorCode: r - 1,
  806. count: 5
  807. })) : 90 == b ? m.pop() : 87 == b ? m.push(d(50, 50, -5, -5, {
  808. type: 2,
  809. isBad: !1
  810. })) : 79 == b ? (q = k, t = l) : 78 == b ? 1 >= r || m.push(d(40, 40, 0, 0, {
  811. type: 3,
  812. color: u[r - 1],
  813. colorCode: r - 1,
  814. count: 1
  815. })) : 37 == b ? (b = f(p, s), null != b && (a.shiftKey ? b.width -= 10 : (b.x -= 10, b.width += 10), 0 == b.width && m.splice(m.indexOf(b), 1))) : 39 == b ? (b = f(p, s), null != b && (a.shiftKey ? (b.x += 10, b.width -= 10) : b.width += 10, 0 == b.width && m.splice(m.indexOf(b), 1))) : 38 == b ? (b = f(p, s), null != b && (a.shiftKey ? b.height -= 10 : (b.y -= 10, b.height += 10), 0 == b.height && m.splice(m.indexOf(b), 1))) : 40 == b && (b = f(p, s), null != b && (a.shiftKey ? (b.y += 10, b.height -= 10) : b.height += 10, 0 == b.height && m.splice(m.indexOf(b), 1)))
  816. }
  817. });
  818. return {
  819. renderEditor: function() {
  820. if (y) {
  821. a.save();
  822. a.fillStyle = "#FF0000";
  823. a.strokeStyle = "#FF0000";
  824. a.lineWidth = 1;
  825. a.globalAlpha = .09;
  826. a.beginPath();
  827. for (var b = 0; 400 > b; b += 10) a.moveTo((b << 1) + .5, 0), a.lineTo((b << 1) + .5, 600);
  828. for (var c = 0; 300 > c; c += 10) a.moveTo(0, (c << 1) + .5), a.lineTo(800, (c << 1) + .5);
  829. a.stroke();
  830. a.lineWidth = 2;
  831. a.beginPath();
  832. a.moveTo(400.5, 0);
  833. a.lineTo(400.5, 600);
  834. a.moveTo(0, 300.5, 0);
  835. a.lineTo(800, 300.5);
  836. a.stroke();
  837. a.lineWidth = 1;
  838. a.globalAlpha = 1;
  839. a.fillStyle = "#000000";
  840. for (var d = n(), c = 0; 300 > c; c += 10)
  841. for (b = 0; 400 > b; b += 10) {
  842. var f = b / 10 | 0,
  843. g = c / 10 | 0,
  844. h = v[f + 40 * g];
  845. e && f >= d.sx && f < d.fx && g >= d.sy && g < d.fy && (h = r);
  846. 0 != h && (a.fillStyle = u[h - 1], a.fillRect(b << 1, c << 1, 20, 20))
  847. }
  848. a.save();
  849. a.globalAlpha = .09;
  850. a.fillStyle = "#0000FF";
  851. a.beginPath();
  852. a.arc(q << 1, t << 1, 20, 0, 2 * Math.PI, !1);
  853. a.fill();
  854. a.restore();
  855. a.save();
  856. a.fillStyle = "#FFFFFF";
  857. a.strokeStyle = "#000000";
  858. a.lineWidth = 2.5;
  859. a.font = "14px NovaSquare";
  860. a.globalAlpha = .5;
  861. a.strokeText("Current color: ", 10, 590);
  862. a.globalAlpha = 1;
  863. a.fillText("Current color: ", 10, 590);
  864. 0 == r ? a.fillText("ESR", 105, 590) : (a.fillStyle = "#000000", a.fillRect(104, 575, 22, 22), a.fillStyle = u[r - 1], a.fillRect(105, 576, 20, 20));
  865. a.restore();
  866. a.restore()
  867. }
  868. },
  869. initEditor: function() {
  870. x.addEventListener("mousedown", b)
  871. }
  872. }
  873. }(),
  874. Ga = pa.renderEditor,
  875. Ia = pa.initEditor,
  876. Ca = new Uint8Array(12E4);
  877. Array.prototype.remove = function(a) {
  878. a = this.indexOf(a);
  879. return -1 != a ? (this.splice(a, 1), !0) : !1
  880. };
  881. function Au(){
  882. if (tap){
  883. ua(k,l);
  884. }
  885. }
  886. function handleKeydown(e) {
  887. if (e.keyCode == 8 || e.keyCode == 9 || (e.keyCode >= 96 && e.keyCode <= 122)
  888. //|| e.keyCode == 12 || e.keyCode == 45 || (e.keyCode >= 33 && e.keyCode <= 40)
  889. ) {
  890. e.preventDefault();
  891. }switch(e.keyCode) {
  892. case 45: case 96: // numpad 0
  893. tap = !tap;
  894. break;
  895. case 119: // F8
  896. showcursorsid = !showcursorsid; // show/hide cursors ids
  897. break;
  898. case 120: // F9
  899. cursorIDPos+=1;
  900. changeCursorIDpos(cursorIDPos);
  901. break;
  902. default:
  903. return;
  904. }
  905. }
  906. var cursorIDPos=1;
  907. var cursorIDX=-2;
  908. var cursorIDY=24;
  909. function changeCursorIDpos(c) {
  910. switch(c){
  911. case 1: cursorIDX=-2; cursorIDY=24; break;
  912. case 2: cursorIDX=-3; cursorIDY=14; break;
  913. case 3: cursorIDX=-2; cursorIDY=-3; break;
  914. case 4: cursorIDX=10; cursorIDY=14; break;
  915. default: cursorIDX=-2; cursorIDY=24; cursorIDPos=1;
  916. }
  917. }
  918. function start() {
  919. E = z.getElementById("canvas");
  920. a = E.getContext("2d");
  921. x = z.getElementById("canvasContainer") || E;
  922. try {
  923. w.top.location.origin != w.location.origin && aa()
  924. } catch (k) {
  925. aa()
  926. }
  927. E.width = 800 * R;
  928. E.height = 600 * R;
  929. a.scale(R, R);
  930. x.onmousemove = sa;
  931. x.onmousedown = ta;
  932. x.onmouseup = va;
  933. I = z.getElementById("noCursorLock");
  934. C = z.getElementById("noDrawings");
  935. null != localStorage && (I.checked = "1" == w.localStorage.getItem("noCursorLock") ? !0 : !1, C.checked = "1" == w.localStorage.getItem("noDrawings") ? !0 : !1);
  936. w.onbeforeunload = Ba;
  937. x.requestPointerLock = x.requestPointerLock || x.mozRequestPointerLock || x.webkitRequestPointerLock;
  938. E.style.cursor = "none";
  939. Ia();
  940. y || ca();
  941. setInterval(J, 50);
  942. setInterval(Au, 5000);
  943. w.requestAnimationFrame(la);
  944.  
  945. document.onkeydown = handleKeydown;
  946. }
  947. start();
  948. }
  949.  
  950. var tap = false;
  951. var showcursorsid = false;
  952. begin(window, document);
  953.  
  954.