cursors.io show player ids

Show players ids on cursors.io

目前为 2018-07-12 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name cursors.io show player ids
  3. // @namespace q1k
  4. // @version 1.0.2
  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. na(!1)
  433. } else {
  434. a.fillStyle="white";
  435. a.fillRect(0, 0, canvas.width, canvas.height);
  436. a.fillStyle = "#000000";
  437. a.save();
  438. a.globalAlpha = 1;
  439. Ga();
  440. for (n = 0; n < m.length; n++) {
  441. var b = m[n];
  442. if (0 == b.type) {
  443. a.font = b.size + "px NovaSquare";
  444. var c = b.x << 1,
  445. d = b.y << 1;
  446. b.isCentered && (c -= a.measureText(b.text).width / 2);
  447. a.fillStyle = "#000000";
  448. a.fillText(b.text, c, d)
  449. } 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;
  450. 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;
  451. else if (3 == b.type) {
  452. var c = b.x << 1,
  453. d = b.y << 1,
  454. f = b.width << 1,
  455. e = b.height << 1;
  456. a.fillStyle = b.color;
  457. a.globalAlpha = .2;
  458. a.fillRect(c, d, f, e);
  459. a.globalAlpha = .5;
  460. a.fillStyle = "#000000";
  461. 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));
  462. a.globalAlpha = 1
  463. } else if (4 == b.type) {
  464. c = b.x << 1;
  465. d = b.y << 1;
  466. f = b.width << 1;
  467. e = b.height << 1;
  468. a.fillStyle = b.color;
  469. a.strokeStyle = b.color;
  470. a.globalAlpha = 1;
  471. a.fillRect(c, d, f, e);
  472. a.globalAlpha = .2;
  473. a.fillStyle = "#000000";
  474. a.fillRect(c, d, f, e);
  475. a.globalAlpha = 1;
  476. a.fillStyle = b.color;
  477. var h = 150 > t - b.lastClickAt,
  478. g = h ? 8 : 12;
  479. a.fillRect(c + g, d + g, f - 2 * g, e - 2 * g);
  480. a.strokeStyle = "#000000";
  481. a.globalAlpha = .1;
  482. a.beginPath();
  483. a.moveTo(c, d);
  484. a.lineTo(c + g, d + g);
  485. a.moveTo(c + f, d);
  486. a.lineTo(c + f - g, d + g);
  487. a.moveTo(c, d + e);
  488. a.lineTo(c + g, d + e - g);
  489. a.moveTo(c + f, d + e);
  490. a.lineTo(c + f - g, d + e - g);
  491. a.moveTo(c, d);
  492. a.rect(c, d, f, e);
  493. a.rect(c + g, d + g, f - 2 * g, e - 2 * g);
  494. a.stroke();
  495. a.fillStyle = "#000000";
  496. a.globalAlpha = .5;
  497. 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));
  498. h && (a.fillStyle = "#000000", a.globalAlpha = .15, a.fillRect(c + g, d + g, f - 2 * g, e - 2 * g));
  499. a.globalAlpha = 1
  500. }
  501. }
  502. a.restore();
  503. 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)));
  504. if (countlevels>0) {
  505. f = "level: "+countlevels, b = a.measureText(f).width, a.globalAlpha = .5, a.strokeText(f, 790 - b, 560), a.globalAlpha = 1;
  506. a.fillText(f, 790 - b, 560);
  507. }
  508. ma();
  509. if (!C.checked) {
  510. a.save();
  511. a.strokeStyle = "#000000";
  512. a.lineWidth = 1;
  513. t = +new Date;
  514. 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());
  515. a.restore()
  516. }
  517. a.save();
  518. for (var po in v) {
  519. v.hasOwnProperty(po) && a.drawImage(M, qa(v[po].getX()) - 6, ra(v[po].getY()) - 6, 23, 30);
  520. if (showcursorsid) {
  521. if(cursorIDPos==2){
  522. cp=a.measureText(po).width;
  523. a.globalAlpha = .5; a.strokeText( po, qa(v[po].getX()) - cp + cursorIDX, ra(v[po].getY()) + cursorIDY );
  524. a.globalAlpha= 1; a.fillText( po, qa(v[po].getX()) - cp + cursorIDX, ra(v[po].getY()) + cursorIDY );
  525. }
  526. else {
  527. a.globalAlpha = .5; a.strokeText( po, qa(v[po].getX()) + cursorIDX, ra(v[po].getY()) + cursorIDY );
  528. a.globalAlpha= 1; a.fillText( po, qa(v[po].getX()) + cursorIDX, ra(v[po].getY()) + cursorIDY );
  529. }
  530. }
  531.  
  532. }
  533. if (showcursorsid) {
  534. if(cursorIDPos==2){
  535. cp=a.measureText(ga).width;
  536. a.globalAlpha = .5; a.strokeText( ga, qa(k) - cp + cursorIDX, ra(l) + cursorIDY ) ;
  537. a.globalAlpha= 1; a.fillText( ga, qa(k) - cp + cursorIDX, ra(l) + cursorIDY ) ;
  538. }
  539. else {
  540. a.globalAlpha = .5; a.strokeText( ga, qa(k) + cursorIDX, ra(l) + cursorIDY ) ;
  541. a.globalAlpha= 1; a.fillText( ga, qa(k) + cursorIDX, ra(l) + cursorIDY ) ;
  542. }
  543. }
  544.  
  545. a.restore();
  546. na(!0)
  547. }
  548. a.restore();
  549. w.requestAnimationFrame(la)
  550. }
  551.  
  552. function ma() {
  553. a.save();
  554. a.strokeStyle = "#000000";
  555. t = +new Date;
  556. for (var n = 0; n < D.length; n++) {
  557. var b = D[n],
  558. c = (t - b[2]) / 1E3,
  559. d = 1 - 2 * c;
  560. 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())
  561. }
  562. a.restore()
  563. }
  564.  
  565. function na(n) {
  566. if (y) a.save(), a.globalAlpha = 1, a.drawImage(M, A - 5, B - 5);
  567. else {
  568. var b = 0,
  569. c = 0;
  570. 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);
  571. a.save();
  572. 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());
  573. a.globalAlpha = 1;
  574. a.drawImage(Ha, (k << 1) + b - 5, (l << 1) + c - 5, 23, 30)
  575. }
  576. a.restore()
  577. }
  578.  
  579. function ja(a, b) {
  580. this.oldX = this.newX = a;
  581. this.oldY = this.newY = b;
  582. this.time = t
  583. }
  584.  
  585. function oa(a) {
  586. return a * a * (3 - 2 * a)
  587. }
  588.  
  589. function ea(a, b, c, d) {
  590. a |= 0;
  591. b |= 0;
  592. c |= 0;
  593. d |= 0;
  594. if (P(a, b)) return {
  595. x: a,
  596. y: b
  597. };
  598. if (a == c && b == d) return {
  599. x: c,
  600. y: d
  601. };
  602. var f = a,
  603. e = b;
  604. c = c - a | 0;
  605. d = d - b | 0;
  606. var h = 0,
  607. g = 0,
  608. k = 0,
  609. l = 0;
  610. 0 > c ? h = -1 : 0 < c && (h = 1);
  611. 0 > d ? g = -1 : 0 < d && (g = 1);
  612. 0 > c ? k = -1 : 0 < c && (k = 1);
  613. var m = Math.abs(c) | 0,
  614. p = Math.abs(d) | 0;
  615. m <= p && (m = Math.abs(d) | 0, p = Math.abs(c) | 0, 0 > d ? l = -1 : 0 < d && (l = 1), k = 0);
  616. c = m >> 1;
  617. 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);
  618. return {
  619. x: f,
  620. y: e
  621. }
  622. }
  623.  
  624. function fa(a, b, c, d) {
  625. a = ea(a, b, c, d);
  626. return a.x == c && a.y == d
  627. }
  628.  
  629. function P(a, b) {
  630. return 0 > a || 400 <= a || 0 > b || 300 <= b ? !0 : Q[a + 400 * b]
  631. }
  632. var Aa = "file:" == w.location.protocol,
  633. E, a, x, ha = 0,
  634. p = 0,
  635. s = 0,
  636. A = 0,
  637. B = 0,
  638. k = 0,
  639. l = 0,
  640. F = -1,
  641. G = -1,
  642. I = null,
  643. C = null,
  644. M = new Image;
  645. M.src = "img/cursor.png";
  646. var Ha = M,
  647. y = -1 != w.location.search.indexOf("editor"),
  648. D = [],
  649. L = [],
  650. t = 0,
  651. ba = 0,
  652. q = null,
  653. ga = -1,
  654. v = {},
  655. $ = 0,
  656. ia = !1,
  657. W = !1,
  658. N = 0,
  659. O = 0,
  660. da = 0,
  661. V = !1,
  662. H = !y && !0,
  663. Q = new Uint8Array(12E4),
  664. m = [],
  665. K = [],
  666. R = w.devicePixelRatio,
  667. cp = 0;
  668. Array.prototype.remove = function(a) {
  669. a = this.indexOf(a);
  670. return -1 != a ? (this.splice(a, 1), !0) : !1
  671. };
  672. var u = 0;
  673. ja.prototype = {
  674. oldX: 0,
  675. oldY: 0,
  676. newX: 0,
  677. newY: 0,
  678. time: 0,
  679. getX: function() {
  680. var a = this.newX - this.oldX,
  681. b = (t - this.time) / 100,
  682. b = oa(0 >= b ? 0 : 1 <= b ? 1 : b);
  683. return this.oldX + b * a
  684. },
  685. getY: function() {
  686. var a = this.newY - this.oldY,
  687. b = (t - this.time) / 100,
  688. b = oa(0 >= b ? 0 : 1 <= b ? 1 : b);
  689. return this.oldY + b * a
  690. }
  691. };
  692. var pa = function() {
  693. function n() {
  694. var a = 0,
  695. b = 0,
  696. c = p / 10,
  697. d = s / 10;
  698. h < c ? (c = Math.ceil(c), a = Math.floor(h)) : (c = Math.floor(c), a = Math.ceil(h));
  699. g < d ? (d = Math.ceil(d), b = Math.floor(g)) : (d = Math.floor(d), b = Math.ceil(g));
  700. if (a > c) var e = c,
  701. c = a,
  702. a = e;
  703. b > d && (e = d, d = b, b = e);
  704. return {
  705. sx: a,
  706. sy: b,
  707. fx: c,
  708. fy: d
  709. }
  710. }
  711.  
  712. function b() {
  713. e = !0;
  714. h = p / 10;
  715. g = s / 10
  716. }
  717.  
  718. function c(a) {
  719. return "0x" + parseInt(a.slice(1), 16).toString(16).toUpperCase()
  720. }
  721.  
  722. function d(a, b, c, d, e) {
  723. a = {
  724. x: 10 * ~~(k / 10) - ~~(a / 2) + c,
  725. y: 10 * ~~(l / 10) - ~~(b / 2) + d,
  726. width: a,
  727. height: b
  728. };
  729. for (var f in e) e.hasOwnProperty(f) && (a[f] = e[f]);
  730. return a
  731. }
  732.  
  733. function f(a, b) {
  734. for (var c = null, d = Number.POSITIVE_INFINITY, e = 0; e < m.length; e++) {
  735. var f = m[e];
  736. if (f.hasOwnProperty("x") && f.hasOwnProperty("y") && f.hasOwnProperty("width") && f.hasOwnProperty("height")) {
  737. var g = f.x + f.width / 2,
  738. h = f.y + f.height / 2,
  739. g = (a - g) * (a - g) + (b - h) * (b - h);
  740. g < d && (d = g, c = f)
  741. }
  742. }
  743. return c
  744. }
  745. var e = !1,
  746. h = 0,
  747. g = 0,
  748. r = 1,
  749. q = 200,
  750. t = 150,
  751. v = new Uint8Array(1200),
  752. u = "#000000 #FF9999 #9999FF #FFFF99 #99FFFF #FF99FF #3333FF".split(" ");
  753. z.addEventListener("mouseup", function() {
  754. if (e) {
  755. for (var a = n(), b = r, c = a.sy; c < a.fy; ++c)
  756. for (var d = a.sx; d < a.fx; ++d) v[d + 40 * c] = b;
  757. e = !1
  758. }
  759. });
  760. z.addEventListener("mousemove", function() {});
  761. w.generateCode = function() {
  762. 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)
  763. for (var f = 0; 40 > f; ++f)
  764. if (!b[f + 40 * e]) {
  765. var g = v[f + 40 * e];
  766. if (0 != g) {
  767. for (var h = f; 40 > f && v[f + 40 * e] == g && !b[f + 40 * e];) b[f + 40 * e] = !0, ++f;
  768. var k = f--,
  769. n = k - h,
  770. l = e++;
  771. a: for (; 30 > e;) {
  772. for (var p = h; p < k; ++p) {
  773. if (v[p + 40 * e] != g) break a;
  774. if (b[p +
  775. 40 * e]) break a
  776. }
  777. for (p = h; p < k; ++p) b[p + 40 * e] = !0;
  778. ++e
  779. }
  780. k = e - l;
  781. e = l;
  782. d.push({
  783. x: 10 * h,
  784. y: 10 * l,
  785. width: 10 * n,
  786. height: 10 * k,
  787. color: g - 1
  788. })
  789. }
  790. }
  791. 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");
  792. for (b = 0; b < m.length; b++) d = m[b], 0 != d.type && (2 == d.type ? a += "\t\tAddObject(new ObjTeleport(LevelManager::GetNextLevel(this), " +
  793. 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"));
  794. return a += "\t}\n};\n"
  795. };
  796. z.addEventListener("keydown", function(a) {
  797. if (y) {
  798. var b = a.keyCode;
  799. 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, {
  800. type: 4,
  801. color: u[r - 1],
  802. colorCode: r - 1,
  803. count: 5
  804. })) : 90 == b ? m.pop() : 87 == b ? m.push(d(50, 50, -5, -5, {
  805. type: 2,
  806. isBad: !1
  807. })) : 79 == b ? (q = k, t = l) : 78 == b ? 1 >= r || m.push(d(40, 40, 0, 0, {
  808. type: 3,
  809. color: u[r - 1],
  810. colorCode: r - 1,
  811. count: 1
  812. })) : 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)))
  813. }
  814. });
  815. return {
  816. renderEditor: function() {
  817. if (y) {
  818. a.save();
  819. a.fillStyle = "#FF0000";
  820. a.strokeStyle = "#FF0000";
  821. a.lineWidth = 1;
  822. a.globalAlpha = .09;
  823. a.beginPath();
  824. for (var b = 0; 400 > b; b += 10) a.moveTo((b << 1) + .5, 0), a.lineTo((b << 1) + .5, 600);
  825. for (var c = 0; 300 > c; c += 10) a.moveTo(0, (c << 1) + .5), a.lineTo(800, (c << 1) + .5);
  826. a.stroke();
  827. a.lineWidth = 2;
  828. a.beginPath();
  829. a.moveTo(400.5, 0);
  830. a.lineTo(400.5, 600);
  831. a.moveTo(0, 300.5, 0);
  832. a.lineTo(800, 300.5);
  833. a.stroke();
  834. a.lineWidth = 1;
  835. a.globalAlpha = 1;
  836. a.fillStyle = "#000000";
  837. for (var d = n(), c = 0; 300 > c; c += 10)
  838. for (b = 0; 400 > b; b += 10) {
  839. var f = b / 10 | 0,
  840. g = c / 10 | 0,
  841. h = v[f + 40 * g];
  842. e && f >= d.sx && f < d.fx && g >= d.sy && g < d.fy && (h = r);
  843. 0 != h && (a.fillStyle = u[h - 1], a.fillRect(b << 1, c << 1, 20, 20))
  844. }
  845. a.save();
  846. a.globalAlpha = .09;
  847. a.fillStyle = "#0000FF";
  848. a.beginPath();
  849. a.arc(q << 1, t << 1, 20, 0, 2 * Math.PI, !1);
  850. a.fill();
  851. a.restore();
  852. a.save();
  853. a.fillStyle = "#FFFFFF";
  854. a.strokeStyle = "#000000";
  855. a.lineWidth = 2.5;
  856. a.font = "14px NovaSquare";
  857. a.globalAlpha = .5;
  858. a.strokeText("Current color: ", 10, 590);
  859. a.globalAlpha = 1;
  860. a.fillText("Current color: ", 10, 590);
  861. 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));
  862. a.restore();
  863. a.restore()
  864. }
  865. },
  866. initEditor: function() {
  867. x.addEventListener("mousedown", b)
  868. }
  869. }
  870. }(),
  871. Ga = pa.renderEditor,
  872. Ia = pa.initEditor,
  873. Ca = new Uint8Array(12E4);
  874. Array.prototype.remove = function(a) {
  875. a = this.indexOf(a);
  876. return -1 != a ? (this.splice(a, 1), !0) : !1
  877. };
  878. function Au(){
  879. if (tap){
  880. ua(k,l);
  881. }
  882. }
  883. function handleKeydown(e) {
  884. if (e.keyCode == 8 || e.keyCode == 9 || (e.keyCode >= 96 && e.keyCode <= 122)
  885. //|| e.keyCode == 12 || e.keyCode == 45 || (e.keyCode >= 33 && e.keyCode <= 40)
  886. ) {
  887. e.preventDefault();
  888. }switch(e.keyCode) {
  889. case 45: case 96: // numpad 0
  890. tap = !tap;
  891. break;
  892. case 119: // F8
  893. showcursorsid = !showcursorsid; // show/hide cursors ids
  894. break;
  895. case 120: // F9
  896. cursorIDPos+=1;
  897. changeCursorIDpos(cursorIDPos);
  898. break;
  899. default:
  900. return;
  901. }
  902. }
  903. var cursorIDPos=1;
  904. var cursorIDX=-2;
  905. var cursorIDY=24;
  906. function changeCursorIDpos(c) {
  907. switch(c){
  908. case 1: cursorIDX=-2; cursorIDY=24; break;
  909. case 2: cursorIDX=-3; cursorIDY=14; break;
  910. case 3: cursorIDX=-2; cursorIDY=-3; break;
  911. case 4: cursorIDX=10; cursorIDY=14; break;
  912. default: cursorIDX=-2; cursorIDY=24; cursorIDPos=1;
  913. }
  914. }
  915. function start() {
  916. E = z.getElementById("canvas");
  917. a = E.getContext("2d");
  918. x = z.getElementById("canvasContainer") || E;
  919. try {
  920. w.top.location.origin != w.location.origin && aa()
  921. } catch (k) {
  922. aa()
  923. }
  924. E.width = 800 * R;
  925. E.height = 600 * R;
  926. a.scale(R, R);
  927. x.onmousemove = sa;
  928. x.onmousedown = ta;
  929. x.onmouseup = va;
  930. I = z.getElementById("noCursorLock");
  931. C = z.getElementById("noDrawings");
  932. null != localStorage && (I.checked = "1" == w.localStorage.getItem("noCursorLock") ? !0 : !1, C.checked = "1" == w.localStorage.getItem("noDrawings") ? !0 : !1);
  933. w.onbeforeunload = Ba;
  934. x.requestPointerLock = x.requestPointerLock || x.mozRequestPointerLock || x.webkitRequestPointerLock;
  935. E.style.cursor = "none";
  936. Ia();
  937. y || ca();
  938. setInterval(J, 50);
  939. setInterval(Au, 5000);
  940. w.requestAnimationFrame(la);
  941.  
  942. document.onkeydown = handleKeydown;
  943. }
  944. start();
  945. }
  946.  
  947. var tap = false;
  948. var showcursorsid = false;
  949. begin(window, document);
  950.  
  951.