cursors.io show player ids

Show players ids on cursors.io

目前為 2018-06-25 提交的版本,檢視 最新版本

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