Guest User

Untitled

a guest
Apr 16th, 2018
1,289
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 197.50 KB | None | 0 0
  1. /******/ (function(modules) { /******/ /******/ var installedModules = {};/******//******/ /******/ function __webpack_require__(moduleId) {
  2. /******/
  3. /******/
  4. /******/ if(installedModules[moduleId]) {
  5. /******/ return installedModules[moduleId].exports;
  6. /******/ }
  7. /******/
  8. /******/ var module = installedModules[moduleId] = {
  9. /******/ i: moduleId,
  10. /******/ l: false,
  11. /******/ exports: {}
  12. /******/ };
  13. /******/
  14. /******/
  15. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  16. /******/
  17. /******/
  18. /******/ module.l = true;
  19. /******/
  20. /******/
  21. /******/ return module.exports;
  22. /******/ }
  23. /******/
  24. /******/
  25. /******/
  26. /******/ __webpack_require__.m = modules;
  27. /******/
  28. /******/
  29. /******/ __webpack_require__.c = installedModules;
  30. /******/
  31. /******/
  32. /******/ __webpack_require__.d = function(exports, name, getter) {
  33. /******/ if(!__webpack_require__.o(exports, name)) {
  34. /******/ Object.defineProperty(exports, name, {
  35. /******/ configurable: false,
  36. /******/ enumerable: true,
  37. /******/ get: getter
  38. /******/ });
  39. /******/ }
  40. /******/ };
  41. /******/
  42. /******/
  43. /******/ __webpack_require__.n = function(module) {
  44. /******/ var getter = module && module.__esModule ?
  45. /******/ function getDefault() { return module['default']; } :
  46. /******/ function getModuleExports() { return module; };
  47. /******/ __webpack_require__.d(getter, 'a', getter);
  48. /******/ return getter;
  49. /******/ };
  50. /******/
  51. /******/
  52. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  53. /******/
  54. /******/
  55. /******/ __webpack_require__.p = "/";
  56. /******/
  57. /******/
  58. /******/ return __webpack_require__(__webpack_require__.s = 3);
  59. /******/ })
  60. /************************************************************************/
  61. /******/ ([
  62. /* 0 */
  63. /***/ (function(module, exports, __webpack_require__) {
  64.  
  65. "use strict";
  66.  
  67.  
  68. Object.defineProperty(exports, "__esModule", {
  69. value: true
  70. });
  71. exports.eventSys = exports.PublicAPI = undefined;
  72.  
  73. var _events = __webpack_require__(17);
  74.  
  75. var PublicAPI = exports.PublicAPI = window.OWOP = window.WorldOfPixels = {};
  76. var eventSys = exports.eventSys = new _events.EventEmitter();
  77.  
  78. /***/ }),
  79. /* 1 */
  80. /***/ (function(module, exports, __webpack_require__) {
  81.  
  82. "use strict";
  83.  
  84.  
  85. Object.defineProperty(exports, "__esModule", {
  86. value: true
  87. });
  88. exports.options = exports.PUBLIC_EVENTS = exports.EVENTS = exports.RANK = exports.protocol = undefined;
  89.  
  90. var _global = __webpack_require__(0);
  91.  
  92. var _misc = __webpack_require__(2);
  93.  
  94. var _toolset = __webpack_require__(18);
  95.  
  96. var _toolset2 = _interopRequireDefault(_toolset);
  97.  
  98. var _unloaded = __webpack_require__(19);
  99.  
  100. var _unloaded2 = _interopRequireDefault(_unloaded);
  101.  
  102. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  103.  
  104. /* Important constants */
  105.  
  106. var protocol = exports.protocol = null;
  107.  
  108. /* The raw event ID numbers should NOT be used, instead import the EVENTS object in your file. */
  109. var evtId = 6666666; /* no */
  110.  
  111. var RANK = exports.RANK = {
  112. NONE: 0,
  113. USER: 1,
  114. MODERATOR: 2,
  115. ADMIN: 3
  116. };
  117.  
  118. _global.PublicAPI.RANK = RANK;
  119.  
  120. var EVENTS = exports.EVENTS = {
  121. loaded: ++evtId,
  122. init: ++evtId,
  123. tick: ++evtId,
  124. misc: {
  125. toolsRendered: ++evtId,
  126. toolsInitialized: ++evtId,
  127. logoMakeRoom: ++evtId,
  128. worldInitialized: ++evtId,
  129. windowAdded: ++evtId,
  130. captchaToken: ++evtId
  131. },
  132. renderer: {
  133. addChunk: ++evtId,
  134. rmChunk: ++evtId,
  135. updateChunk: ++evtId
  136. },
  137. camera: {
  138. moved: ++evtId,
  139. zoom: ++evtId /* (zoom value), note that this event should not be used to SET zoom level. */
  140. },
  141. net: {
  142. connecting: ++evtId,
  143. connected: ++evtId,
  144. disconnected: ++evtId,
  145. playerCount: ++evtId,
  146. chat: ++evtId,
  147. devChat: ++evtId,
  148. world: {
  149. leave: ++evtId,
  150. join: ++evtId, /* (worldName string) */
  151. joining: ++evtId, /* (worldName string) */
  152. setId: ++evtId,
  153. playersMoved: ++evtId, /* (Object with all the updated player values) */
  154. playersLeft: ++evtId,
  155. tilesUpdated: ++evtId,
  156. teleported: ++evtId
  157. },
  158. chunk: {
  159. load: ++evtId, /* (Chunk class) */
  160. unload: ++evtId, /* (x, y) */
  161. set: ++evtId, /* (x, y, data), backwards compat */
  162. lock: ++evtId
  163. },
  164. sec: {
  165. rank: ++evtId
  166. }
  167. }
  168. };
  169.  
  170. var PUBLIC_EVENTS = exports.PUBLIC_EVENTS = {
  171. loaded: EVENTS.loaded,
  172. init: EVENTS.init,
  173. tick: EVENTS.tick,
  174. toolsInitialized: EVENTS.misc.toolsInitialized
  175. };
  176.  
  177. _global.PublicAPI.events = PUBLIC_EVENTS;
  178.  
  179. var userOptions = {};
  180. if ((0, _misc.storageEnabled)()) {
  181. try {
  182. userOptions = JSON.parse(localStorage.getItem('owopOptions') || '{}');
  183. } catch (e) {
  184. console.error('Error while parsing user options!', e);
  185. }
  186. }
  187.  
  188. var options = exports.options = (0, _misc.propertyDefaults)(userOptions, {
  189. serverAddress: [{
  190. default: true,
  191. title: 'Official server',
  192. proto: 'old',
  193. url: 'ws:
  194. }, {
  195. default: false,
  196. title: 'Localhost',
  197. proto: 'old',
  198. url: 'ws:
  199. maxRetries: 1
  200. }],
  201. fallbackFps: 30,
  202. maxChatBuffer: 256,
  203. tickSpeed: 30,
  204. minGridZoom: 1, /* Minimum zoom level where the grid shows up */
  205. movementSpeed: 1, /* Pixels per tick */
  206. defaultWorld: 'main',
  207. enableSounds: true,
  208. defaultZoom: 16,
  209. zoomStrength: 1,
  210. zoomLimitMin: 1,
  211. zoomLimitMax: 32,
  212. unloadDistance: 10,
  213. toolSetUrl: _toolset2.default,
  214. unloadedPatternUrl: _unloaded2.default,
  215. backgroundUrl: null,
  216. /* Bug only affects Windows users with an Intel graphics card,
  217. * since we can't easily know the client's GPU,
  218. * activate for all windows users ¯\_(ツ)_/¯
  219. */
  220. chunkBugWorkaround: false
  221. /* Did it get fixed? we'll know soon! */
  222. });
  223.  
  224. if (options.chunkBugWorkaround) {
  225. console.debug('Chunk bug workaround enabled!');
  226. }
  227.  
  228. _global.PublicAPI.options = options;
  229.  
  230. _global.eventSys.on(EVENTS.net.connecting, function (server) {
  231. exports.protocol = protocol = server.proto;
  232. });
  233.  
  234. /***/ }),
  235. /* 2 */
  236. /***/ (function(module, exports, __webpack_require__) {
  237.  
  238. "use strict";
  239.  
  240.  
  241. Object.defineProperty(exports, "__esModule", {
  242. value: true
  243. });
  244. exports.getTime = getTime;
  245. exports.setCookie = setCookie;
  246. exports.getCookie = getCookie;
  247. exports.cookiesEnabled = cookiesEnabled;
  248. exports.storageEnabled = storageEnabled;
  249. exports.propertyDefaults = propertyDefaults;
  250. exports.absMod = absMod;
  251. exports.htmlToElement = htmlToElement;
  252. exports.escapeHTML = escapeHTML;
  253. exports.mkHTML = mkHTML;
  254. exports.loadScript = loadScript;
  255. exports.eventOnce = eventOnce;
  256. exports.setTooltip = setTooltip;
  257. exports.waitFrames = waitFrames;
  258. exports.decompress = decompress;
  259. exports.line = line;
  260.  
  261. var _color = __webpack_require__(4);
  262.  
  263. var _global = __webpack_require__(0);
  264.  
  265. _global.PublicAPI.util = {
  266. getTime: getTime,
  267. cookiesEnabled: cookiesEnabled,
  268. storageEnabled: storageEnabled,
  269. absMod: absMod,
  270. escapeHTML: escapeHTML,
  271. mkHTML: mkHTML,
  272. setTooltip: setTooltip,
  273. waitFrames: waitFrames,
  274. line: line
  275. };
  276.  
  277. var time = Date.now();
  278. function getTime(update) {
  279. return update ? time = Date.now() : time;
  280. }
  281.  
  282. function setCookie(name, value) {
  283. document.cookie = name + '=' + value + '; expires=Fri, 31 Dec 9999 23:59:59 GMT';
  284. }
  285.  
  286. function getCookie(name) {
  287. var cookie = document.cookie.split(';');
  288. for (var i = 0; i < cookie.length; i++) {
  289. var idx = cookie[i].indexOf(name + '=');
  290. if (idx === 0 || idx === 1 && cookie[i][0] === ' ') {
  291. var off = idx + name.length + 1;
  292. return cookie[i].substring(off, cookie[i].length);
  293. }
  294. }
  295. return null;
  296. }
  297.  
  298. function cookiesEnabled() {
  299. return navigator.cookieEnabled;
  300. }
  301.  
  302. function storageEnabled() {
  303. try {
  304. return !!window.localStorage;
  305. } catch (e) {
  306. return false;
  307. }
  308. }
  309.  
  310. function propertyDefaults(obj, defaults) {
  311. if (obj) {
  312. for (var prop in obj) {
  313. if (obj.hasOwnProperty(prop)) {
  314. defaults[prop] = obj[prop];
  315. }
  316. }
  317. }
  318. return defaults;
  319. }
  320.  
  321.  
  322. function absMod(n1, n2) {
  323. return (n1 % n2 + n2) % n2;
  324. }
  325.  
  326. function htmlToElement(html) {
  327. return mkHTML("template", {
  328. innerHTML: html
  329. }).content.firstChild;
  330. }
  331.  
  332. function escapeHTML(text) {
  333. return text.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/\"/g, '&quot;').replace(/\'/g, '&#39;').replace(/\
  334. }
  335.  
  336. /* Makes an HTML element with the values specified in opts */
  337. function mkHTML(tag, opts) {
  338. var elm = document.createElement(tag);
  339. for (var i in opts) {
  340. elm[i] = opts[i];
  341. }
  342. return elm;
  343. }
  344.  
  345. function loadScript(name, callback) {
  346. document.getElementsByTagName('head')[0].appendChild(mkHTML("script", {
  347. type: "text/javascript",
  348. src: name,
  349. onload: callback
  350. }));
  351. }
  352.  
  353. function eventOnce(element, events, func) {
  354. var ev = events.split(' ');
  355. var f = function f(e) {
  356. for (var i = 0; i < ev.length; i++) {
  357. element.removeEventListener(ev[i], f);
  358. }
  359. return func();
  360. };
  361.  
  362. for (var i = 0; i < ev.length; i++) {
  363. element.addEventListener(ev[i], f);
  364. }
  365. }
  366.  
  367. function setTooltip(element, message) {
  368. var elementSpacing = 10;
  369. var intr = 0;
  370. var tip = null;
  371. function tooltip() {
  372. var epos = element.getBoundingClientRect();
  373. var y = epos.top + epos.height / 2;
  374. tip = mkHTML('span', {
  375. innerHTML: message,
  376. className: 'framed tooltip whitetext'
  377. });
  378. document.body.appendChild(tip);
  379. var tpos = tip.getBoundingClientRect();
  380. y -= tpos.height / 2;
  381. var x = epos.left - tpos.width - elementSpacing;
  382. if (x < elementSpacing) {
  383. x = epos.right + elementSpacing;
  384. }
  385. tip.style.transform = 'translate(' + Math.round(x) + 'px,' + Math.round(y) + 'px)';
  386. intr = 0;
  387. }
  388. var mleave = function mleave(e) {
  389. clearTimeout(intr);
  390. intr = 0;
  391. element.removeEventListener('mouseleave', mleave);
  392. element.removeEventListener('click', mleave);
  393. element.removeEventListener('DOMNodeRemoved', mleave);
  394. if (tip !== null) {
  395. tip.remove();
  396. tip = null;
  397. }
  398. };
  399. var menter = function menter(e) {
  400. if (tip === null && intr === 0) {
  401. intr = setTimeout(tooltip, 500);
  402. element.addEventListener('click', mleave);
  403. element.addEventListener('mouseleave', mleave);
  404. element.addEventListener('DOMNodeRemoved', mleave);
  405. }
  406. };
  407. /*var observer = new MutationObserver(e => {
  408. console.log(e, tip, intr);
  409. if (e[0].removedNodes && (tip !== null || intr !== 0)) {
  410. mleave();
  411. }
  412. });
  413. observer.observe(element, { childList: true, subtree: true });*/
  414. element.addEventListener('mouseenter', menter);
  415. }
  416.  
  417. /* Waits n frames */
  418. function waitFrames(n, cb) {
  419. window.requestAnimationFrame(function () {
  420. return n > 0 ? waitFrames(--n, cb) : cb();
  421. });
  422. }
  423.  
  424. function decompress(u8arr) {
  425. var originalLength = u8arr[1] << 8 | u8arr[0];
  426. var u8decompressedarr = new Uint8Array(originalLength);
  427. var numOfRepeats = u8arr[3] << 8 | u8arr[2];
  428. var offset = numOfRepeats * 2 + 4;
  429. var uptr = 0;
  430. var cptr = offset;
  431. for (var i = 0; i < numOfRepeats; i++) {
  432. var currentRepeatLoc = (u8arr[4 + i * 2 + 1] << 8 | u8arr[4 + i * 2]) + offset;
  433. while (cptr < currentRepeatLoc) {
  434. u8decompressedarr[uptr++] = u8arr[cptr++];
  435. }
  436. var repeatedNum = u8arr[cptr + 1] << 8 | u8arr[cptr];
  437. var repeatedColorR = u8arr[cptr + 2];
  438. var repeatedColorG = u8arr[cptr + 3];
  439. var repeatedColorB = u8arr[cptr + 4];
  440. cptr += 5;
  441. while (repeatedNum--) {
  442. u8decompressedarr[uptr] = repeatedColorR;
  443. u8decompressedarr[uptr + 1] = repeatedColorG;
  444. u8decompressedarr[uptr + 2] = repeatedColorB;
  445. uptr += 3;
  446. }
  447. }
  448. while (cptr < u8arr.length) {
  449. u8decompressedarr[uptr++] = u8arr[cptr++];
  450. }
  451. return u8decompressedarr;
  452. }
  453.  
  454. /*function decompressu16(input) {
  455. var originalLength = (((input[1] & 0xFF) << 8 | (input[0] & 0xFF)) + 1) * 2;
  456. var output = new Uint8Array(originalLength);
  457. var numOfRepeats = (input[3] & 0xFF) << 8 | (input[2] & 0xFF);
  458. var offset = numOfRepeats * 2 + 4;
  459. var uptr = 0;
  460. var cptr = offset;
  461. for (var i = 0; i < numOfRepeats; i++) {
  462. var currentRepeatLoc = 2 * ((((input[4 + i * 2 + 1] & 0xFF) << 8) | (input[4 + i * 2] & 0xFF)))
  463. + offset;
  464. while (cptr < currentRepeatLoc) {
  465. output[uptr++] = input[cptr++];
  466. }
  467. var repeatedNum = ((input[cptr + 1] & 0xFF) << 8 | (input[cptr] & 0xFF)) + 1;
  468. var repeatedColorRGB = (input[cptr + 3] & 0xFF) << 8 | (input[cptr + 2] & 0xFF);
  469. cptr += 4;
  470. while (repeatedNum-- != 0) {
  471. output[uptr] = (repeatedColorRGB & 0xFF);
  472. output[uptr + 1] = ((repeatedColorRGB & 0xFF00) >> 8);
  473. uptr += 2;
  474. }
  475. }
  476. while (cptr < input.length) {
  477. output[uptr++] = input[cptr++];
  478. }
  479. return output;
  480. }*/
  481.  
  482. function line(x1, y1, x2, y2, size, plot) {
  483. var dx = Math.abs(x2 - x1),
  484. sx = x1 < x2 ? 1 : -1;
  485. var dy = -Math.abs(y2 - y1),
  486. sy = y1 < y2 ? 1 : -1;
  487. var err = dx + dy,
  488. e2;
  489.  
  490. while (true) {
  491. plot(x1, y1);
  492. if (x1 == x2 && y1 == y2) break;
  493. e2 = 2 * err;
  494. if (e2 >= dy) {
  495. err += dy;x1 += sx;
  496. }
  497. if (e2 <= dx) {
  498. err += dx;y1 += sy;
  499. }
  500. }
  501. }
  502.  
  503. /***/ }),
  504. /* 3 */
  505. /***/ (function(module, exports, __webpack_require__) {
  506.  
  507. "use strict";
  508. /*
  509. * TODO List: https:
  510. * NOTE: Let's stick with the correct way of storing colors,
  511. * first byte should be red value: 0xAABBGGRR, or [r, g, b]
  512. */
  513.  
  514.  
  515. Object.defineProperty(exports, "__esModule", {
  516. value: true
  517. });
  518. exports.playerListWindow = exports.playerListTable = exports.playerList = exports.sounds = exports.misc = exports.elements = exports.mouse = exports.keysDown = exports.statusMsg = exports.showPlayerList = exports.showDevChat = undefined;
  519.  
  520. var _normalizeWheel = __webpack_require__(15);
  521.  
  522. var _anchorme = __webpack_require__(16);
  523.  
  524. var _anchorme2 = _interopRequireDefault(_anchorme);
  525.  
  526. var _conf = __webpack_require__(1);
  527.  
  528. var _Bucket = __webpack_require__(9);
  529.  
  530. var _misc = __webpack_require__(2);
  531.  
  532. var _global = __webpack_require__(0);
  533.  
  534. var _World = __webpack_require__(12);
  535.  
  536. var _canvas_renderer = __webpack_require__(5);
  537.  
  538. var _networking = __webpack_require__(8);
  539.  
  540. var _local_player = __webpack_require__(6);
  541.  
  542. var _all = __webpack_require__(21);
  543.  
  544. var _windowsys = __webpack_require__(11);
  545.  
  546. var _launch = __webpack_require__(25);
  547.  
  548. var _launch2 = _interopRequireDefault(_launch);
  549.  
  550. var _place = __webpack_require__(26);
  551.  
  552. var _place2 = _interopRequireDefault(_place);
  553.  
  554. var _click = __webpack_require__(27);
  555.  
  556. var _click2 = _interopRequireDefault(_click);
  557.  
  558. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  559.  
  560. exports.showDevChat = showDevChat;
  561. exports.showPlayerList = showPlayerList;
  562. exports.statusMsg = statusMsg;
  563. var keysDown = exports.keysDown = {};
  564.  
  565. var mouse = exports.mouse = {
  566. x: 0, /* pageX */
  567. y: 0, /* pageY */
  568. lastX: 0,
  569. lastY: 0,
  570. get worldX() {
  571. return _canvas_renderer.camera.x * 16 + this.x / (_canvas_renderer.camera.zoom / 16);
  572. },
  573. get worldY() {
  574. return _canvas_renderer.camera.y * 16 + this.y / (_canvas_renderer.camera.zoom / 16);
  575. },
  576. mouseDownWorldX: 0,
  577. mouseDownWorldY: 0,
  578. get tileX() {
  579. return Math.floor(this.worldX / 16);
  580. },
  581. get tileY() {
  582. return Math.floor(this.worldY / 16);
  583. },
  584. buttons: 0,
  585. validTile: false,
  586. insideViewport: false,
  587. touches: [],
  588. cancelMouseDown: function cancelMouseDown() {
  589. this.buttons = 0;
  590. }
  591. };
  592.  
  593. var elements = exports.elements = {
  594. viewport: null,
  595. xyDisplay: null,
  596. chatInput: null,
  597. chat: null,
  598. devChat: null
  599. };
  600.  
  601. var misc = exports.misc = {
  602. _world: null,
  603. lastXYDisplay: [-1, -1],
  604. chatRecvModifier: function chatRecvModifier(msg) {
  605. return msg;
  606. },
  607. chatSendModifier: function chatSendModifier(msg) {
  608. return msg;
  609. },
  610. exceptionTimeout: null,
  611. worldPasswords: {},
  612. tick: 0,
  613. urlWorldName: null,
  614. connecting: false,
  615. tickInterval: null,
  616. lastMessage: null,
  617. lastCleanup: 0,
  618. set world(value) {
  619. /* The reason this is done is because the old functions may reference the old world object */
  620. _global.PublicAPI.world = getNewWorldApi();
  621. return this._world = value;
  622. },
  623. get world() {
  624. return this._world;
  625. },
  626. guiShown: false,
  627. cookiesEnabled: (0, _misc.cookiesEnabled)(),
  628. storageEnabled: (0, _misc.storageEnabled)(),
  629. showEUCookieNag: (0, _misc.cookiesEnabled)() && (0, _misc.getCookie)("nagAccepted") !== "true",
  630. usingFirefox: navigator.userAgent.indexOf("Firefox") !== -1
  631. };
  632.  
  633. var sounds = exports.sounds = {
  634. play: function play(sound) {
  635. sound.currentTime = 0;
  636. if (_conf.options.enableSounds) {
  637. sound.play();
  638. }
  639. }
  640. };
  641. sounds.launch = new Audio();
  642. sounds.launch.src = _launch2.default;
  643. sounds.place = new Audio();
  644. sounds.place.src = _place2.default;
  645. sounds.click = new Audio();
  646. sounds.click.src = _click2.default;
  647.  
  648. var playerList = exports.playerList = {};
  649. var playerListTable = exports.playerListTable = document.createElement("table");
  650. var playerListWindow = exports.playerListWindow = new _windowsys.GUIWindow('Players', { closeable: true }, function (wdow) {
  651. var tableHeader = document.createElement("tr");
  652. tableHeader.innerHTML = "<th>Id</th><th>X</th><th>Y</th>";
  653. playerListTable.appendChild(tableHeader);
  654. wdow.container.appendChild(playerListTable);
  655. wdow.container.id = "player-list";
  656. }).move(window.innerWidth - 240, 32);
  657.  
  658. function getNewWorldApi() {
  659. var obj = {};
  660. var defProp = function defProp(prop) {
  661. Object.defineProperty(obj, prop, {
  662. get: function get() {
  663. return misc.world && this['_' + prop] || (this['_' + prop] = misc.world[prop].bind(misc.world));
  664. }
  665. });
  666. };
  667. defProp('getPixel');
  668. defProp('setPixel');
  669. defProp('undo');
  670. defProp('unloadFarChunks');
  671. return obj;
  672. }
  673.  
  674. function receiveMessage(text) {
  675. console.log(text);
  676. text = misc.chatRecvModifier(text);
  677. if (!text) {
  678. return;
  679. }
  680.  
  681. var message = document.createElement("li");
  682. var realText = text;
  683. var isAdmin = false;
  684. if (text.startsWith("[D]")) {
  685. message.className = "discord";
  686. var nick = document.createElement("span");
  687. nick.className = "nick";
  688. var nickname = text.split(": ")[0] + ": ";
  689. nick.innerHTML = (0, _misc.escapeHTML)(nickname);
  690. message.appendChild(nick);
  691. text = text.slice(nickname.length);
  692. } else if (text.startsWith("[Server]") || text.startsWith("Server:") || text.startsWith("Nickname set to") || text.startsWith("User: ")) {
  693. message.className = "server";
  694. } else if (text.startsWith("->")) {
  695. message.className = "tell";
  696. } else if (text.startsWith("(M)")) {
  697. message.className = "moderator";
  698. } else if (isNaN(text.split(": ")[0]) && text.split(": ")[0].charAt(0) != "[") {
  699. message.className = "admin";
  700. isAdmin = true;
  701. } else {
  702. var nick = document.createElement("span");
  703. nick.className = "nick";
  704. var nickname = text.split(": ")[0] + ": ";
  705. nick.innerHTML = (0, _misc.escapeHTML)(nickname);
  706. message.appendChild(nick);
  707. text = text.slice(nickname.length);
  708. }
  709. var idIndex = text.indexOf(': '); /* This shouldn't be like this, change on proto switch */
  710. if (idIndex !== -1) {
  711. var ntext = text.substr(0, idIndex);
  712. realText = ntext.replace(/\d+/g, '') + text.slice(idIndex + 2);
  713. }
  714.  
  715. if (misc.lastMessage && misc.lastMessage.text === realText) {
  716. misc.lastMessage.incCount();
  717. } else {
  718. var span = document.createElement("span");
  719. misc.lastMessage = {
  720. get text() {
  721. return realText;
  722. },
  723. incCount: function incCount() {
  724. var times = span.recvTimes || 1;
  725. span.innerHTML = text + ' [x' + ++times + ']';
  726. span.recvTimes = times;
  727. message.style.animation = 'none'; /* Reset fading anim */
  728. message.offsetHeight; /* Reflow */
  729. message.style.animation = null;
  730. }
  731. };
  732. if (!isAdmin) {
  733. text = (0, _misc.escapeHTML)(text).replace(/\&\#x2F;/g, "/");
  734. }
  735. span.innerHTML = (0, _anchorme2.default)(text, {
  736. attributes: [{
  737. name: "target",
  738. value: "blank"
  739. }]
  740. });
  741. message.appendChild(span);
  742. scrollChatToBottom(function () {
  743. elements.chatMessages.appendChild(message);
  744. var childs = elements.chatMessages.children;
  745. if (childs.length > _conf.options.maxChatBuffer) {
  746. childs[0].remove();
  747. }
  748. }, true);
  749. }
  750. }
  751.  
  752. function receiveDevMessage(text) {
  753. var message = document.createElement("li");
  754. var span = document.createElement("span");
  755. span.innerHTML = text;
  756. message.appendChild(span);
  757. elements.devChatMessages.appendChild(message);
  758. elements.devChatMessages.scrollTop = elements.devChatMessages.scrollHeight;
  759. }
  760.  
  761. function scrollChatToBottom(callback) {
  762. var dontScrollIfNotTop = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  763.  
  764. var shouldScroll = !dontScrollIfNotTop || elements.chatMessages.scrollHeight - elements.chatMessages.scrollTop === elements.chatMessages.clientHeight;
  765. if (callback) callback();
  766. if (shouldScroll) elements.chatMessages.scrollTop = elements.chatMessages.scrollHeight;
  767. }
  768.  
  769. function clearChat() {
  770. elements.chatMessages.innerHTML = "";
  771. elements.devChatMessages.innerHTML = "";
  772. }
  773.  
  774. function tick() {
  775. var tickNum = ++misc.tick;
  776. var speed = Math.max(Math.min(_conf.options.movementSpeed, 64), 0);
  777. var offX = 0;
  778. var offY = 0;
  779. if (keysDown[38]) {
  780.  
  781. offY -= speed;
  782. }
  783. if (keysDown[37]) {
  784.  
  785. offX -= speed;
  786. }
  787. if (keysDown[40]) {
  788.  
  789. offY += speed;
  790. }
  791. if (keysDown[39]) {
  792.  
  793. offX += speed;
  794. }
  795. if (offX !== 0 || offY !== 0) {
  796. (0, _canvas_renderer.moveCameraBy)(offX, offY);
  797. updateMouse(null, 'mousemove', mouse.x, mouse.y);
  798. }
  799.  
  800. _global.eventSys.emit(_conf.EVENTS.tick, tickNum);
  801. if (_local_player.player.tool !== null && misc.world !== null) {
  802. _local_player.player.tool.call('tick', mouse);
  803. }
  804. }
  805.  
  806. function updateMouse(event, eventName, mouseX, mouseY) {
  807. mouse.x = mouseX;
  808. mouse.y = mouseY;
  809. var cancelled = 0;
  810. if (misc.world !== null) {
  811. mouse.validTile = misc.world.validMousePos(mouse.tileX, mouse.tileY);
  812. if (_local_player.player.tool !== null) {
  813. cancelled = _local_player.player.tool.call(eventName, [mouse, event]);
  814. }
  815. if (updateXYDisplay(mouse.tileX, mouse.tileY)) {
  816. (0, _local_player.updateClientFx)();
  817. }
  818. }
  819. return cancelled;
  820. }
  821.  
  822. function openChat() {
  823. elements.chat.className = "active selectable";
  824. elements.devChat.className = "active selectable";
  825. elements.chatMessages.className = "active";
  826. scrollChatToBottom();
  827. }
  828.  
  829. function closeChat() {
  830. elements.chat.className = "";
  831. elements.devChat.className = "";
  832. elements.chatMessages.className = "";
  833. elements.chatInput.blur();
  834. scrollChatToBottom();
  835. }
  836.  
  837. function showDevChat(bool) {
  838. elements.devChat.style.display = bool ? "" : "none";
  839. }
  840.  
  841. function showPlayerList(bool) {
  842. if (bool) {
  843. _windowsys.windowSys.addWindow(playerListWindow);
  844. } else {
  845. _windowsys.windowSys.delWindow(playerListWindow);
  846. }
  847. }
  848.  
  849. function updateXYDisplay(x, y) {
  850. if (misc.lastXYDisplay[0] !== x || misc.lastXYDisplay[1] !== y) {
  851. misc.lastXYDisplay = [x, y];
  852. elements.xyDisplay.innerHTML = "X: " + x + ", Y: " + y;
  853. return true;
  854. }
  855. return false;
  856. }
  857.  
  858. function updatePlayerCount(count) {
  859. elements.playerCountDisplay.innerHTML = count + ' cursor' + (count !== 1 ? 's online' : ' online');
  860. }
  861. /*
  862. function openServerSelector() {
  863. windowsys.addWindow(new GUIWindow(0, 0, 250, 60, "Select a server", {
  864. centered: true
  865. }, wdow => {
  866.  
  867. wdow.addObj(mkHTML("button", {
  868. innerHTML: "Original server",
  869. style: "width: 100%; height: 50%",
  870. onclick: () => {
  871. w.options.serverAddress = "ws:
  872. w.net.connect();
  873. win.wm.delWindow(win);
  874. w.options.oldserver = true;
  875. }
  876. }));
  877. wdow.addObj(mkHTML("button", {
  878. innerHTML: "Beta server",
  879. style: "width: 100%; height: 50%",
  880. onclick: () => {
  881. w.options.serverAddress = "ws:
  882. w.net.connect();
  883. win.wm.delWindow(win);
  884. }
  885. }));
  886. wdow.addObj(mkHTML("button", {
  887. innerHTML: "Localhost",
  888. style: "width: 100%; height: 50%",
  889. onclick: () => {
  890. w.options.serverAddress = "ws:
  891. w.net.connect();
  892. win.wm.delWindow(win);
  893. }
  894. }));
  895. wdow.addObj(mkHTML("button", {
  896. innerHTML: "Custom server",
  897. style: "width: 100%; height: 50%",
  898. onclick: function() {
  899. var i = win.wm.addWindow(
  900. new UtilInput("Enter server address", "Type here...", "text", function(addr) {
  901. w.options.serverAddress = addr;
  902. w.net.connect();
  903. win.close();
  904. }.bind({w: w, win: win}))
  905. );
  906. win.onclose = function() {
  907. i.getWindow().close();
  908. }
  909. }.bind({w: this, win: wdow})
  910. }));
  911. }));
  912. }
  913. */
  914. function logoMakeRoom(bool) {
  915. elements.loadUl.style.transform = bool ? "translateY(-75%) scale(0.5)" : "";
  916. }
  917.  
  918. function showWorldUI(bool) {
  919. misc.guiShown = bool;
  920. elements.xyDisplay.style.transform = bool ? "initial" : "";
  921. elements.playerCountDisplay.style.transform = bool ? "initial" : "";
  922. elements.palette.style.transform = bool ? "translateY(-50%)" : "";
  923. elements.chat.style.transform = bool ? "initial" : "";
  924. elements.chatInput.disabled = !bool;
  925. elements.chatInput.style.display = "initial";
  926. }
  927.  
  928. function showLoadScr(bool, showOptions) {
  929. elements.loadOptions.className = showOptions ? "framed" : "hide";
  930. if (!bool) {
  931. elements.loadScr.style.transform = "translateY(-110%)"; /* +10% for shadow */
  932. (0, _misc.eventOnce)(elements.loadScr, "transitionend webkitTransitionEnd oTransitionEnd msTransitionEnd", function () {
  933. if (_networking.net.isConnected()) {
  934. elements.loadScr.className = "hide";
  935. }
  936. });
  937. } else {
  938. elements.loadScr.className = "";
  939. elements.loadScr.style.transform = "";
  940. }
  941. }
  942.  
  943. function statusMsg(showSpinner, message) {
  944. var statusShown = elements.status.isConnected;
  945. if (message === null) {
  946. elements.status.style.display = "none";
  947. return;
  948. } else {
  949. elements.status.style.display = "";
  950. }
  951. elements.statusMsg.innerHTML = message;
  952. elements.spinner.style.display = showSpinner ? "" : "none";
  953. }
  954.  
  955. function inGameDisconnected() {
  956. showWorldUI(false);
  957. showLoadScr(true, true);
  958. statusMsg(false, "Lost connection with the server.");
  959. misc.world = null;
  960. elements.chat.style.transform = "initial";
  961. elements.chatInput.style.display = "";
  962. }
  963.  
  964. function retryingConnect(serverGetter, worldName) {
  965. if (misc.connecting && !_networking.net.isConnected()) {
  966. /* We're already connected/trying to connect */
  967. return;
  968. }
  969. misc.connecting = true;
  970. var currentServer = serverGetter(false);
  971. var tryConnect = function tryConnect(tryN) {
  972. if (tryN >= (currentServer.maxRetries || 3)) {
  973. currentServer = serverGetter(true);
  974. tryN = 0;
  975. }
  976. _global.eventSys.once(_conf.EVENTS.net.connecting, function () {
  977. console.debug('Trying \'' + currentServer.title + '\' (' + currentServer.url + ')...');
  978. statusMsg(true, 'Connecting to \'' + currentServer.title + '\'...');
  979. showLoadScr(true, false);
  980. });
  981. _networking.net.connect(currentServer, worldName);
  982. var disconnected = function disconnected() {
  983. ++tryN;
  984. statusMsg(true, 'Couldn\'t connect to server, retrying... (' + tryN + ')');
  985. setTimeout(tryConnect, Math.min(tryN * 2000, 10000), tryN);
  986. _global.eventSys.removeListener(_conf.EVENTS.net.connected, connected);
  987. };
  988. var connected = function connected() {
  989. statusMsg(false, "Connected!");
  990. _global.eventSys.removeListener(_conf.EVENTS.net.disconnected, disconnected);
  991. _global.eventSys.once(_conf.EVENTS.net.disconnected, inGameDisconnected);
  992. misc.connecting = false;
  993. };
  994.  
  995. _global.eventSys.once(_conf.EVENTS.net.connected, connected);
  996. _global.eventSys.once(_conf.EVENTS.net.disconnected, disconnected);
  997. };
  998. tryConnect(0);
  999. }
  1000.  
  1001. function saveWorldPasswords() {
  1002. if (misc.storageEnabled) {
  1003. localStorage.worldPasswords = JSON.stringify(misc.worldPasswords);
  1004. }
  1005. }
  1006.  
  1007. function checkFunctionality(callback) {
  1008. /* Multi Browser Support */
  1009. window.requestAnimationFrame = window.requestAnimationFrame || window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame || window.msRequestAnimationFrame || function (f) {
  1010. setTimeout(f, 1000 / _conf.options.fallbackFps);
  1011. };
  1012.  
  1013. Number.isInteger = Number.isInteger || function (n) {
  1014. return Math.floor(n) === n && Math.abs(n) !== Infinity;
  1015. };
  1016. Math.trunc = Math.trunc || function (n) {
  1017. return n | 0;
  1018. };
  1019.  
  1020. var toBlob = HTMLCanvasElement.prototype.toBlob = HTMLCanvasElement.prototype.toBlob || HTMLCanvasElement.prototype.msToBlob;
  1021.  
  1022. if (!toBlob) {
  1023. /* Load toBlob polyfill */
  1024. (0, _misc.loadScript)(__webpack_require__(28), callback);
  1025. } else {
  1026. callback();
  1027. }
  1028. }
  1029.  
  1030. function init() {
  1031. var viewport = elements.viewport;
  1032. var chatinput = elements.chatInput;
  1033.  
  1034. if (misc.storageEnabled && localStorage.worldPasswords) {
  1035. try {
  1036. misc.worldPasswords = JSON.parse(localStorage.worldPasswords);
  1037. } catch (e) {}
  1038. }
  1039.  
  1040. misc.lastCleanup = 0;
  1041.  
  1042. viewport.oncontextmenu = function () {
  1043. return false;
  1044. };
  1045.  
  1046. viewport.addEventListener("mouseenter", function () {
  1047. mouse.insideViewport = true;
  1048. (0, _local_player.updateClientFx)();
  1049. });
  1050. viewport.addEventListener("mouseleave", function () {
  1051. mouse.insideViewport = false;
  1052. (0, _local_player.updateClientFx)();
  1053. });
  1054.  
  1055. var chatHistory = [];
  1056. var historyIndex = 0;
  1057. chatinput.addEventListener("keydown", function (event) {
  1058. event.stopPropagation();
  1059. if (historyIndex === 0) {
  1060. chatHistory[0] = chatinput.value;
  1061. }
  1062. var keyCode = event.which || event.keyCode;
  1063. switch (keyCode) {
  1064. case 27:
  1065. closeChat();
  1066. break;
  1067. case 13:
  1068. if (!event.shiftKey) {
  1069. event.preventDefault();
  1070. var text = chatinput.value;
  1071. historyIndex = 0;
  1072. chatHistory.unshift(text);
  1073. if (misc.storageEnabled) {
  1074. if (text.startsWith("/adminlogin ")) {
  1075. localStorage.adminlogin = text.slice(12);
  1076. } else if (text.startsWith("/modlogin ")) {
  1077. localStorage.modlogin = text.slice(10);
  1078. } else if (text.startsWith("/nick")) {
  1079. var nick = text.slice(6);
  1080. if (nick.length) {
  1081. localStorage.nick = nick;
  1082. } else {
  1083. delete localStorage.nick;
  1084. }
  1085. } else if (text.startsWith("/pass ") && misc.world) {
  1086. var pass = text.slice(6);
  1087. misc.worldPasswords[_networking.net.protocol.worldName] = pass;
  1088. saveWorldPasswords();
  1089. }
  1090. }
  1091. if (!event.ctrlKey) {
  1092. text = misc.chatSendModifier(text);
  1093. }
  1094. _networking.net.protocol.sendMessage(text);
  1095. chatinput.value = '';
  1096. chatinput.style.height = "16px";
  1097. event.stopPropagation();
  1098. }
  1099. break;
  1100. case 38:
  1101.  
  1102. if (event.shiftKey && historyIndex < chatHistory.length - 1) {
  1103. historyIndex++;
  1104. chatinput.value = chatHistory[historyIndex];
  1105. chatinput.style.height = 0;
  1106. chatinput.style.height = Math.min(chatinput.scrollHeight - 8, 16 * 4) + "px";
  1107. }
  1108. break;
  1109. case 40:
  1110.  
  1111. if (event.shiftKey && historyIndex > 0) {
  1112. historyIndex--;
  1113. chatinput.value = chatHistory[historyIndex];
  1114. chatinput.style.height = 0;
  1115. chatinput.style.height = Math.min(chatinput.scrollHeight - 8, 16 * 4) + "px";
  1116. }
  1117. break;
  1118. }
  1119. });
  1120. chatinput.addEventListener("keyup", function (event) {
  1121. event.stopPropagation();
  1122. var keyCode = event.which || event.keyCode;
  1123. if (keyCode == 13 && !event.shiftKey) {
  1124. closeChat();
  1125. }
  1126. });
  1127. chatinput.addEventListener("input", function (event) {
  1128. chatinput.style.height = 0;
  1129. chatinput.style.height = Math.min(chatinput.scrollHeight - 8, 16 * 4) + "px";
  1130. });
  1131. chatinput.addEventListener("focus", function (event) {
  1132. if (!mouse.buttons) {
  1133. openChat();
  1134. } else {
  1135. chatinput.blur();
  1136. }
  1137. });
  1138.  
  1139. window.addEventListener("keydown", function (event) {
  1140. var keyCode = event.which || event.keyCode;
  1141. if (document.activeElement.tagName !== "INPUT" && misc.world !== null) {
  1142. keysDown[keyCode] = true;
  1143. var tool = _local_player.player.tool;
  1144. if (tool !== null && misc.world !== null && tool.isEventDefined('keydown')) {
  1145. if (tool.call('keydown', [keysDown, event])) {
  1146. return false;
  1147. }
  1148. }
  1149. switch (keyCode) {
  1150. case 80:
  1151. /* P */
  1152. _local_player.player.tool = "pipette";
  1153. break;
  1154.  
  1155. case 79:
  1156. /* O */
  1157. _local_player.player.tool = "cursor";
  1158. break;
  1159.  
  1160. case 77: /* M */
  1161. case 16:
  1162. /* Shift */
  1163. _local_player.player.tool = "move";
  1164. break;
  1165.  
  1166. case 90:
  1167. /* Ctrl + Z */
  1168. if (!event.ctrlKey || !misc.world) {
  1169. break;
  1170. }
  1171. misc.world.undo(event.shiftKey);
  1172. event.preventDefault();
  1173. break;
  1174.  
  1175. case 70:
  1176. /* F */
  1177. var parseClr = function parseClr(clr) {
  1178. var tmp = clr.split(',');
  1179. var nrgb = null;
  1180. if (tmp.length == 3) {
  1181. nrgb = tmp;
  1182. for (var i = 0; i < tmp.length; i++) {
  1183. tmp[i] = +tmp[i];
  1184. if (!(tmp[i] >= 0 && tmp[i] < 256)) {
  1185. return null;
  1186. }
  1187. }
  1188. } else if (clr[0] == '#' && clr.length == 7) {
  1189. var colr = parseInt(clr.replace('#', '0x'));
  1190. /* The parsed HTML color doesn't have red as the first byte, so invert it. */
  1191. nrgb = [colr >> 16 & 0xFF, colr >> 8 & 0xFF, colr & 0xFF];
  1192. }
  1193. return nrgb;
  1194. };
  1195. var input = prompt("Custom color\nType three values separated by a comma: r,g,b\n(...or the hex string: #RRGGBB)\nYou can add multiple colors at a time separating them with a space.");
  1196. if (!input) {
  1197. break;
  1198. }
  1199. input = input.split(' ');
  1200. for (var j = 0; j < input.length; j++) {
  1201. var rgb = parseClr(input[j]);
  1202. if (rgb) {
  1203. _local_player.player.selectedColor = rgb;
  1204. }
  1205. }
  1206.  
  1207. break;
  1208.  
  1209. case 71:
  1210. /* G */
  1211. _canvas_renderer.renderer.showGrid(!_canvas_renderer.renderer.gridShown);
  1212. break;
  1213.  
  1214. case 112:
  1215. /* F1 */
  1216. showWorldUI(!misc.guiShown);
  1217. event.preventDefault();
  1218. break;
  1219.  
  1220. case 107:
  1221. case 187:
  1222. ++_canvas_renderer.camera.zoom;
  1223. break;
  1224.  
  1225. case 109:
  1226. case 189:
  1227. --_canvas_renderer.camera.zoom;
  1228. break;
  1229.  
  1230. default:
  1231. return true;
  1232. break;
  1233. }
  1234. return false;
  1235. }
  1236. });
  1237. window.addEventListener("keyup", function (event) {
  1238. var keyCode = event.which || event.keyCode;
  1239. delete keysDown[keyCode];
  1240. if (document.activeElement.tagName !== "INPUT") {
  1241. var tool = _local_player.player.tool;
  1242. if (tool !== null && misc.world !== null && tool.isEventDefined('keyup')) {
  1243. if (tool.call('keyup', [keysDown, event])) {
  1244. return false;
  1245. }
  1246. }
  1247. if (keyCode == 13) {
  1248. elements.chatInput.focus();
  1249. } else if (keyCode == 16) {
  1250. _local_player.player.tool = "cursor";
  1251. }
  1252. }
  1253. });
  1254. viewport.addEventListener("mousedown", function (event) {
  1255. closeChat();
  1256. mouse.lastX = mouse.x;
  1257. mouse.lastY = mouse.y;
  1258. mouse.x = event.pageX;
  1259. mouse.y = event.pageY;
  1260. mouse.mouseDownWorldX = mouse.worldX;
  1261. mouse.mouseDownWorldY = mouse.worldY;
  1262. if ('buttons' in event) {
  1263. mouse.buttons = event.buttons;
  1264. } else {
  1265. var realBtn = event.button;
  1266. if (realBtn === 2) {
  1267. realBtn = 1;
  1268. } else if (realBtn === 1) {
  1269. realBtn = 2;
  1270. }
  1271. mouse.buttons |= 1 << realBtn;
  1272. }
  1273.  
  1274. var tool = _local_player.player.tool;
  1275. if (tool !== null && misc.world !== null) {
  1276. _local_player.player.tool.call('mousedown', [mouse, event]);
  1277. }
  1278. });
  1279.  
  1280. window.addEventListener("mouseup", function (event) {
  1281. /* Old versions of firefox have the buttons property as the
  1282. * buttons released, instead of the currently pressed buttons.
  1283. **/
  1284. if ('buttons' in event && !misc.usingFirefox) {
  1285. mouse.buttons = event.buttons;
  1286. } else {
  1287. var realBtn = event.button;
  1288. if (realBtn === 2) {
  1289. realBtn = 1;
  1290. } else if (realBtn === 1) {
  1291. realBtn = 2;
  1292. }
  1293. mouse.buttons &= ~(1 << realBtn);
  1294. }
  1295. var tool = _local_player.player.tool;
  1296. if (tool !== null && misc.world !== null) {
  1297. _local_player.player.tool.call('mouseup', [mouse, event]);
  1298. }
  1299. });
  1300.  
  1301. window.addEventListener("mousemove", function (event) {
  1302. var cancelledButtons = updateMouse(event, 'mousemove', event.pageX, event.pageY);
  1303. var remainingButtons = mouse.buttons & ~cancelledButtons;
  1304. if (remainingButtons & 4) {
  1305. /* If middle click was not used for anything */
  1306. (0, _canvas_renderer.moveCameraBy)((mouse.mouseDownWorldX - mouse.worldX) / 16, (mouse.mouseDownWorldY - mouse.worldY) / 16);
  1307. }
  1308. });
  1309.  
  1310. var mousewheel = function mousewheel(event) {
  1311. var nevt = (0, _normalizeWheel.normalizeWheel)(event);
  1312. if (_local_player.player.tool !== null && misc.world !== null && _local_player.player.tool.isEventDefined('scroll')) {
  1313. if (_local_player.player.tool.call('scroll', [mouse, nevt, event])) {
  1314. return;
  1315. }
  1316. }
  1317. if (event.ctrlKey) {
  1318. _canvas_renderer.camera.zoom += Math.max(-1, Math.min(1, -nevt.pixelY));
  1319.  
  1320. } else {
  1321. var delta = Math.max(-1, Math.min(1, nevt.spinY));
  1322. var pIndex = _local_player.player.paletteIndex;
  1323. if (delta > 0) {
  1324. pIndex++;
  1325. } else if (delta < 0) {
  1326. pIndex--;
  1327. }
  1328. _local_player.player.paletteIndex = pIndex;
  1329. }
  1330. };
  1331.  
  1332. var wheelEventName = 'onwheel' in document ? 'wheel' : 'onmousewheel' in document ? 'mousewheel' : 'DOMMouseScroll';
  1333.  
  1334. viewport.addEventListener(wheelEventName, mousewheel, { passive: true });
  1335. viewport.addEventListener(wheelEventName, function (e) {
  1336. e.preventDefault();
  1337. return false;
  1338. }, { passive: false });
  1339.  
  1340.  
  1341. var touchEventNoUpdate = function touchEventNoUpdate(evtName) {
  1342. return function (event) {
  1343. var tool = _local_player.player.tool;
  1344. mouse.buttons = 0;
  1345. if (tool !== null && misc.world !== null) {
  1346. _local_player.player.tool.call(evtName, [mouse, event]);
  1347. }
  1348. };
  1349. };
  1350. viewport.addEventListener("touchstart", function (event) {
  1351. var moved = event.changedTouches[0];
  1352. mouse.buttons = 1;
  1353. if (moved) {
  1354. updateMouse(event, 'touchstart', moved.pageX, moved.pageY);
  1355. mouse.mouseDownWorldX = mouse.worldX;
  1356. mouse.mouseDownWorldY = mouse.worldY;
  1357. }
  1358. }, { passive: true });
  1359. viewport.addEventListener("touchmove", function (event) {
  1360. var moved = event.changedTouches[0];
  1361. if (moved) {
  1362. updateMouse(event, 'touchmove', moved.pageX, moved.pageY);
  1363. }
  1364. }, { passive: true });
  1365. viewport.addEventListener("touchend", touchEventNoUpdate('touchend'), { passive: true });
  1366. viewport.addEventListener("touchcancel", touchEventNoUpdate('touchcancel'), { passive: true });
  1367.  
  1368.  
  1369. console.log("%c" + " _ _ _ _ _ _____ ___ _____ _ _ \n" + "| | | |___ ___| |_| | | | _| | _ |_|_ _ ___| |___ \n" + "| | | | . | _| | . | | | | _| | __| |_'_| -_| |_ -|\n" + "|_____|___|_| |_|___| |_____|_| |__| |_|_,_|___|_|___|", "font-size: 15px; font-weight: bold;");
  1370. console.log("%cWelcome to the developer console!", "font-size: 20px; font-weight: bold; color: #F0F;");
  1371.  
  1372.  
  1373. (0, _all.resolveProtocols)();
  1374.  
  1375. /* Calls other initialization functions */
  1376. _global.eventSys.emit(_conf.EVENTS.init);
  1377.  
  1378. updateXYDisplay(0, 0);
  1379.  
  1380. var worldName = decodeURIComponent(window.location.pathname);
  1381. if (worldName[0] === '/') {
  1382. worldName = worldName.slice(1);
  1383. }
  1384.  
  1385. misc.urlWorldName = worldName;
  1386.  
  1387. var serverGetter = function (serverList) {
  1388. var defaults = [];
  1389. var availableServers = [];
  1390. for (var i = 0; i < serverList.length; i++) {
  1391. if (serverList[i].default) {
  1392. defaults.push(serverList[i]);
  1393. } else {
  1394. availableServers.push(serverList[i]);
  1395. }
  1396. }
  1397. var index = 0;
  1398. return function (next) {
  1399. if (next) {
  1400. defaults.pop();
  1401. ++index;
  1402. }
  1403. if (defaults.length) {
  1404. var sv = defaults[0];
  1405. availableServers.push(sv);
  1406. return sv;
  1407. }
  1408. return availableServers[index % availableServers.length];
  1409. };
  1410. }(_conf.options.serverAddress);
  1411.  
  1412. retryingConnect(serverGetter, misc.urlWorldName);
  1413.  
  1414. elements.reconnectBtn.onclick = function () {
  1415. return retryingConnect(serverGetter, misc.urlWorldName);
  1416. };
  1417.  
  1418. misc.tickInterval = setInterval(tick, 1000 / _conf.options.tickSpeed);
  1419. }
  1420.  
  1421. _global.eventSys.once(_conf.EVENTS.loaded, function () {
  1422. return statusMsg(true, "Initializing...");
  1423. });
  1424. _global.eventSys.once(_conf.EVENTS.misc.logoMakeRoom, function () {
  1425. statusMsg(false, null);
  1426. logoMakeRoom();
  1427. });
  1428.  
  1429. _global.eventSys.once(_conf.EVENTS.loaded, init);
  1430. _global.eventSys.on(_conf.EVENTS.net.playerCount, updatePlayerCount);
  1431.  
  1432. _global.eventSys.on(_conf.EVENTS.net.chat, receiveMessage);
  1433. _global.eventSys.on(_conf.EVENTS.net.devChat, receiveDevMessage);
  1434.  
  1435. _global.eventSys.on(_conf.EVENTS.net.world.setId, function (id) {
  1436. if (!misc.storageEnabled) {
  1437. return;
  1438. }
  1439.  
  1440. function autoNick() {
  1441. if (localStorage.nick) {
  1442. _networking.net.protocol.sendMessage("/nick " + localStorage.nick);
  1443. }
  1444. }
  1445.  
  1446.  
  1447. var desiredRank = localStorage.adminlogin ? _conf.RANK.ADMIN : localStorage.modlogin ? _conf.RANK.MODERATOR : _networking.net.protocol.worldName in misc.worldPasswords ? _conf.RANK.USER : _conf.RANK.NONE;
  1448. if (desiredRank > _conf.RANK.NONE) {
  1449. var onWrong = function onWrong() {
  1450. console.log("WRONG");
  1451. _global.eventSys.removeListener(_conf.EVENTS.net.sec.rank, onCorrect);
  1452. if (desiredRank == _conf.RANK.ADMIN) {
  1453. delete localStorage.adminlogin;
  1454. } else if (desiredRank == _conf.RANK.MODERATOR) {
  1455. delete localStorage.modlogin;
  1456. } else if (desiredRank == _conf.RANK.USER) {
  1457. delete misc.worldPasswords[_networking.net.protocol.worldName];
  1458. saveWorldPasswords();
  1459. }
  1460. retryingConnect(function () {
  1461. return _networking.net.currentServer;
  1462. }, _networking.net.protocol.worldName);
  1463. };
  1464. var onCorrect = function onCorrect(newrank) {
  1465. if (newrank == desiredRank) {
  1466. setTimeout(function () {
  1467. /* Ugly fix for wrong password on worlds without one */
  1468. _global.eventSys.removeListener(_conf.EVENTS.net.disconnected, onWrong);
  1469. }, 1000);
  1470. _global.eventSys.removeListener(_conf.EVENTS.net.sec.rank, onCorrect);
  1471. autoNick();
  1472. }
  1473. };
  1474. _global.eventSys.once(_conf.EVENTS.net.disconnected, onWrong);
  1475. _global.eventSys.on(_conf.EVENTS.net.sec.rank, onCorrect);
  1476. var msg;
  1477. if (desiredRank == _conf.RANK.ADMIN) {
  1478. msg = "/adminlogin " + localStorage.adminlogin;
  1479. } else if (desiredRank == _conf.RANK.MODERATOR) {
  1480. msg = "/modlogin " + localStorage.modlogin;
  1481. } else if (desiredRank == _conf.RANK.USER) {
  1482. msg = "/pass " + misc.worldPasswords[_networking.net.protocol.worldName];
  1483. }
  1484. _networking.net.protocol.sendMessage(msg);
  1485. } else {
  1486. autoNick();
  1487. }
  1488. });
  1489.  
  1490. _global.eventSys.on(_conf.EVENTS.misc.windowAdded, function (window) {
  1491. if (misc.world === null) {
  1492. statusMsg(false, null);
  1493. logoMakeRoom(true);
  1494. }
  1495. });
  1496.  
  1497. _global.eventSys.on(_conf.EVENTS.net.world.joining, function (name) {
  1498. logoMakeRoom(false);
  1499. console.log('Joining world: ' + name);
  1500. });
  1501.  
  1502. _global.eventSys.on(_conf.EVENTS.net.world.join, function (world) {
  1503. showLoadScr(false, false);
  1504. showWorldUI(true);
  1505. sounds.play(sounds.launch);
  1506. misc.world = new _World.World(world);
  1507. _global.eventSys.emit(_conf.EVENTS.misc.worldInitialized);
  1508. });
  1509.  
  1510. _global.eventSys.on(_conf.EVENTS.net.connected, function () {
  1511. clearChat();
  1512. });
  1513.  
  1514. _global.eventSys.on(_conf.EVENTS.camera.moved, function (camera) {
  1515. var time = (0, _misc.getTime)();
  1516. if (misc.world !== null && time - misc.lastCleanup > 1000) {
  1517. misc.lastCleanup = time;
  1518. _canvas_renderer.renderer.unloadFarClusters();
  1519. }
  1520. if (updateXYDisplay(mouse.tileX, mouse.tileY)) {
  1521. (0, _local_player.updateClientFx)();
  1522. }
  1523. });
  1524.  
  1525. _global.eventSys.on(_conf.EVENTS.camera.zoom, function (camera) {
  1526. if (updateXYDisplay(mouse.tileX, mouse.tileY)) {
  1527. (0, _local_player.updateClientFx)();
  1528. }
  1529. });
  1530.  
  1531. window.addEventListener("error", function (e) {
  1532. showDevChat(true);
  1533. var errmsg = e && e.error ? e.error.message || e.error.stack : e.message || "Unknown error occurred";
  1534. errmsg = (0, _misc.escapeHTML)(errmsg);
  1535. errmsg = errmsg.split('\n');
  1536. for (var i = 0; i < errmsg.length; i++) {
  1537. /* Should be some kind of dissapearing notification instead */
  1538. receiveDevMessage(errmsg[i]);
  1539. }
  1540. if (_local_player.player.rank !== _conf.RANK.ADMIN) {
  1541. /* TODO */
  1542. if (misc.exceptionTimeout) {
  1543. clearTimeout(misc.exceptionTimeout);
  1544. }
  1545. misc.exceptionTimeout = setTimeout(function () {
  1546. return showDevChat(false);
  1547. }, 5000);
  1548. }
  1549. });
  1550.  
  1551. window.addEventListener("load", function () {
  1552. elements.loadScr = document.getElementById("load-scr");
  1553. elements.loadUl = document.getElementById("load-ul");
  1554. elements.loadOptions = document.getElementById("load-options");
  1555. elements.reconnectBtn = document.getElementById("reconnect-btn");
  1556. elements.spinner = document.getElementById("spinner");
  1557. elements.statusMsg = document.getElementById("status-msg");
  1558. elements.status = document.getElementById("status");
  1559. elements.logo = document.getElementById("logo");
  1560.  
  1561. elements.xyDisplay = document.getElementById("xy-display");
  1562. elements.devChat = document.getElementById("dev-chat");
  1563. elements.chat = document.getElementById("chat");
  1564. elements.devChatMessages = document.getElementById("dev-chat-messages");
  1565. elements.chatMessages = document.getElementById("chat-messages");
  1566. elements.playerCountDisplay = document.getElementById("playercount-display");
  1567.  
  1568. elements.palette = document.getElementById("palette");
  1569. elements.paletteColors = document.getElementById("palette-colors");
  1570. elements.paletteCreate = document.getElementById("palette-create");
  1571. elements.paletteInput = document.getElementById("palette-input");
  1572.  
  1573. elements.animCanvas = document.getElementById("animations");
  1574.  
  1575. elements.viewport = document.getElementById("viewport");
  1576. elements.windows = document.getElementById("windows");
  1577.  
  1578. elements.chatInput = document.getElementById("chat-input");
  1579.  
  1580. document.getElementById("help-button").addEventListener("click", function () {
  1581. document.getElementById("help").className = "";
  1582. });
  1583. document.getElementById("help-close").addEventListener("click", function () {
  1584. document.getElementById("help").className = "hidden";
  1585. });
  1586.  
  1587. checkFunctionality(function () {
  1588. return _global.eventSys.emit(_conf.EVENTS.loaded);
  1589. });
  1590. });
  1591.  
  1592. /* Public API definitions */
  1593. _global.PublicAPI.emit = _global.eventSys.emit.bind(_global.eventSys);
  1594. _global.PublicAPI.on = _global.eventSys.on.bind(_global.eventSys);
  1595. _global.PublicAPI.once = _global.eventSys.once.bind(_global.eventSys);
  1596. _global.PublicAPI.removeListener = _global.eventSys.removeListener.bind(_global.eventSys);
  1597. _global.PublicAPI.elements = elements;
  1598. _global.PublicAPI.mouse = mouse;
  1599. _global.PublicAPI.world = getNewWorldApi();
  1600. _global.PublicAPI.chat = {
  1601. send: function send(msg) {
  1602. return _networking.net.protocol && _networking.net.protocol.sendMessage(msg);
  1603. },
  1604. clear: clearChat,
  1605. local: receiveMessage,
  1606. get recvModifier() {
  1607. return misc.chatRecvModifier;
  1608. },
  1609. set recvModifier(fn) {
  1610. misc.chatRecvModifier = fn;
  1611. },
  1612. get sendModifier() {
  1613. return misc.chatSendModifier;
  1614. },
  1615. set sendModifier(fn) {
  1616. misc.chatSendModifier = fn;
  1617. }
  1618. };
  1619. _global.PublicAPI.sounds = sounds;
  1620.  
  1621. /***/ }),
  1622. /* 4 */
  1623. /***/ (function(module, exports, __webpack_require__) {
  1624.  
  1625. "use strict";
  1626.  
  1627.  
  1628. Object.defineProperty(exports, "__esModule", {
  1629. value: true
  1630. });
  1631. var colorUtils = exports.colorUtils = {
  1632. to888: function to888(R, G, B) {
  1633. return [R * 527 + 23 >> 6, G * 259 + 33 >> 6, B * 527 + 23 >> 6];
  1634. },
  1635. to565: function to565(R, G, B) {
  1636. return [R * 249 + 1014 >> 11, G * 253 + 505 >> 10, B * 249 + 1014 >> 11];
  1637. },
  1638. u16_565: function u16_565(R, G, B) {
  1639. return B << 11 | G << 5 | R;
  1640. },
  1641. u24_888: function u24_888(R, G, B) {
  1642. return B << 16 | G << 8 | R;
  1643. },
  1644. u32_888: function u32_888(R, G, B) {
  1645. return colorUtils.u24_888(R, G, B) | 0xFF000000;
  1646. },
  1647. u16_565_to_888: function u16_565_to_888(color) {
  1648. var R = (color & 31) * 527 + 23 >> 6;
  1649. var G = (color >> 5 & 31) * 527 + 23 >> 6;
  1650. var B = (color >> 11 & 31) * 527 + 23 >> 6;
  1651. return B << 16 | G << 8 | R;
  1652. },
  1653. arrFrom565: function arrFrom565(color) {
  1654. return [color & 31, color >> 5 & 63, color >> 11 & 31];
  1655. },
  1656. /* Takes an integer, and gives an html compatible color */
  1657. toHTML: function toHTML(color) {
  1658. color = (color >> 16 & 0xFF | color & 0xFF00 | color << 16 & 0xFF0000).toString(16);
  1659. return '#' + ('000000' + color).substring(color.length);
  1660. }
  1661. };
  1662.  
  1663. /***/ }),
  1664. /* 5 */
  1665. /***/ (function(module, exports, __webpack_require__) {
  1666.  
  1667. "use strict";
  1668.  
  1669.  
  1670. Object.defineProperty(exports, "__esModule", {
  1671. value: true
  1672. });
  1673. exports.renderer = exports.camera = exports.isVisible = exports.moveCameraTo = exports.moveCameraBy = exports.centerCameraTo = undefined;
  1674.  
  1675. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  1676.  
  1677. exports.drawText = drawText;
  1678. exports.unloadFarClusters = unloadFarClusters;
  1679.  
  1680. var _conf = __webpack_require__(1);
  1681.  
  1682. var _global = __webpack_require__(0);
  1683.  
  1684. var _main = __webpack_require__(3);
  1685.  
  1686. var _local_player = __webpack_require__(6);
  1687.  
  1688. var _Fx = __webpack_require__(7);
  1689.  
  1690. var _misc = __webpack_require__(2);
  1691.  
  1692. var _color = __webpack_require__(4);
  1693.  
  1694. var _Lerp = __webpack_require__(14);
  1695.  
  1696. var _tools = __webpack_require__(10);
  1697.  
  1698. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  1699.  
  1700. exports.centerCameraTo = centerCameraTo;
  1701. exports.moveCameraBy = moveCameraBy;
  1702. exports.moveCameraTo = moveCameraTo;
  1703. exports.isVisible = isVisible;
  1704.  
  1705. /* oh boy, i'm going to get shit for making this private, aren't i? */
  1706.  
  1707. var cameraValues = {
  1708. x: 0,
  1709. y: 0,
  1710. zoom: -1 /*,
  1711. lerpZoom: new Lerp(options.defaultZoom, options.defaultZoom, 200)*/
  1712. };
  1713.  
  1714. var camera = exports.camera = {
  1715. get x() {
  1716. return cameraValues.x;
  1717. },
  1718. get y() {
  1719. return cameraValues.y;
  1720. },
  1721. get zoom() {
  1722. return cameraValues.zoom;
  1723. },
  1724. /*get lerpZoom() { return cameraValues.lerpZoom.val; },*/
  1725. set zoom(z) {
  1726. z = Math.min(_conf.options.zoomLimitMax, Math.max(_conf.options.zoomLimitMin, z));
  1727. if (z !== cameraValues.zoom) {
  1728. var center = getCenterPixel();
  1729. cameraValues.zoom = z;
  1730. centerCameraTo(center[0], center[1]);
  1731. _global.eventSys.emit(_conf.EVENTS.camera.zoom, z);
  1732. }
  1733. },
  1734. isVisible: isVisible
  1735. };
  1736.  
  1737. var rendererValues = {
  1738. updateRequired: 3,
  1739. animContext: null,
  1740. gridShown: true,
  1741. gridPattern: null, /* Rendered each time the zoom changes */
  1742. unloadedPattern: null,
  1743. worldBackground: null,
  1744. minGridZoom: _conf.options.minGridZoom,
  1745. updatedClusters: [], /* Clusters to render in the next frame */
  1746. clusters: {},
  1747. visibleClusters: [],
  1748. currentFontSize: -1
  1749. };
  1750.  
  1751. /*PublicAPI.rval = rendererValues;*/
  1752.  
  1753. var renderer = exports.renderer = {
  1754. rendertype: {
  1755. ALL: 3,
  1756. FX: 1,
  1757. WORLD: 2
  1758. },
  1759. patterns: {
  1760. get unloaded() {
  1761. return rendererValues.unloadedPattern;
  1762. }
  1763. },
  1764. render: requestRender,
  1765. showGrid: setGridVisibility,
  1766. get gridShown() {
  1767. return rendererValues.gridShown;
  1768. },
  1769. updateCamera: onCameraMove,
  1770. unloadFarClusters: unloadFarClusters
  1771. };
  1772.  
  1773. _global.PublicAPI.camera = camera;
  1774. _global.PublicAPI.renderer = renderer;
  1775.  
  1776. var BufView = function () {
  1777. function BufView(u32data, x, y, w, h, realw) {
  1778. _classCallCheck(this, BufView);
  1779.  
  1780. this.data = u32data;
  1781. if (_conf.options.chunkBugWorkaround) {
  1782. this.changes = [];
  1783. }
  1784. this.offx = x;
  1785. this.offy = y;
  1786. this.realwidth = realw;
  1787. this.width = w;
  1788. this.height = h;
  1789. }
  1790.  
  1791. _createClass(BufView, [{
  1792. key: 'get',
  1793. value: function get(x, y) {
  1794. return this.data[this.offx + x + (this.offy + y) * this.realwidth];
  1795. }
  1796. }, {
  1797. key: 'set',
  1798. value: function set(x, y, data) {
  1799. this.data[this.offx + x + (this.offy + y) * this.realwidth] = data;
  1800. if (_conf.options.chunkBugWorkaround) {
  1801. this.changes.push([0, x, y, data]);
  1802. }
  1803. }
  1804. }, {
  1805. key: 'fill',
  1806. value: function fill(data) {
  1807. for (var i = 0; i < this.height; i++) {
  1808. for (var j = 0; j < this.width; j++) {
  1809. this.data[this.offx + j + (this.offy + i) * this.realwidth] = data;
  1810. }
  1811. }
  1812. if (_conf.options.chunkBugWorkaround) {
  1813. this.changes.push([1, 0, 0, data]);
  1814. }
  1815. }
  1816. }, {
  1817. key: 'fillFromBuf',
  1818. value: function fillFromBuf(u32buf) {
  1819. for (var i = 0; i < this.height; i++) {
  1820. for (var j = 0; j < this.width; j++) {
  1821. this.data[this.offx + j + (this.offy + i) * this.realwidth] = u32buf[j + i * this.width];
  1822. if (_conf.options.chunkBugWorkaround) {
  1823. /* Terrible */
  1824. this.changes.push([0, j, i, u32buf[j + i * this.width]]);
  1825. }
  1826. }
  1827. }
  1828. }
  1829. }]);
  1830.  
  1831. return BufView;
  1832. }();
  1833.  
  1834. var ChunkCluster = function () {
  1835. function ChunkCluster(x, y) {
  1836. _classCallCheck(this, ChunkCluster);
  1837.  
  1838. this.removed = false;
  1839. this.toUpdate = false;
  1840. this.shown = false; /* is in document? */
  1841. this.x = x;
  1842. this.y = y;
  1843. this.canvas = document.createElement("canvas");
  1844. this.canvas.width = _conf.protocol.chunkSize * _conf.protocol.clusterChunkAmount;
  1845. this.canvas.height = _conf.protocol.chunkSize * _conf.protocol.clusterChunkAmount;
  1846. this.ctx = this.canvas.getContext("2d");
  1847. this.data = this.ctx.createImageData(this.canvas.width, this.canvas.height);
  1848. this.u32data = new Uint32Array(this.data.data.buffer);
  1849. this.chunks = [];
  1850. if (_conf.options.chunkBugWorkaround) {
  1851. this.currentColor = 0;
  1852. }
  1853. }
  1854.  
  1855. _createClass(ChunkCluster, [{
  1856. key: 'render',
  1857. value: function render() {
  1858. this.toUpdate = false;
  1859. for (var i = this.chunks.length; i--;) {
  1860. var c = this.chunks[i];
  1861. if (c.needsRedraw) {
  1862. c.needsRedraw = false;
  1863. if (_conf.options.chunkBugWorkaround) {
  1864. var arr = c.view.changes;
  1865. var s = _conf.protocol.chunkSize;
  1866. for (var j = 0; j < arr.length; j++) {
  1867. var current = arr[j];
  1868. if (this.currentColor !== current[3]) {
  1869. this.currentColor = current[3];
  1870. this.ctx.fillStyle = _color.colorUtils.toHTML(current[3]);
  1871. }
  1872. switch (current[0]) {
  1873. case 0:
  1874. this.ctx.fillRect(c.view.offx + current[1], c.view.offy + current[2], 1, 1);
  1875. break;
  1876. case 1:
  1877. this.ctx.fillRect(c.view.offx, c.view.offy, s, s);
  1878. break;
  1879. }
  1880. }
  1881. c.view.changes = [];
  1882. } else {
  1883. this.ctx.putImageData(this.data, 0, 0, c.view.offx, c.view.offy, c.view.width, c.view.height);
  1884. }
  1885. }
  1886. }
  1887. }
  1888. }, {
  1889. key: 'remove',
  1890. value: function remove() {
  1891. this.removed = true;
  1892. if (this.shown) {
  1893. var visiblecl = rendererValues.visibleClusters;
  1894. visiblecl.splice(visiblecl.indexOf(this), 1);
  1895. this.shown = false;
  1896. }
  1897. this.canvas.width = 0;
  1898. this.u32data = this.data = null;
  1899. delete rendererValues.clusters[this.x + ',' + this.y];
  1900. for (var i = 0; i < this.chunks.length; i++) {
  1901. this.chunks[i].view = null;
  1902. this.chunks[i].remove();
  1903. }
  1904. this.chunks = [];
  1905. }
  1906. }, {
  1907. key: 'addChunk',
  1908. value: function addChunk(chunk) {
  1909. /* WARNING: Should absMod if not power of two */
  1910. var x = chunk.x & _conf.protocol.clusterChunkAmount - 1;
  1911. var y = chunk.y & _conf.protocol.clusterChunkAmount - 1;
  1912. var s = _conf.protocol.chunkSize;
  1913. var view = new BufView(this.u32data, x * s, y * s, s, s, _conf.protocol.clusterChunkAmount * s);
  1914. if (chunk.tmpChunkBuf) {
  1915. view.fillFromBuf(chunk.tmpChunkBuf);
  1916. chunk.tmpChunkBuf = null;
  1917. }
  1918. chunk.view = view;
  1919. this.chunks.push(chunk);
  1920. chunk.needsRedraw = true;
  1921. }
  1922. }, {
  1923. key: 'delChunk',
  1924. value: function delChunk(chunk) {
  1925. chunk.view = null;
  1926. /* There is no real need to clearRect the chunk area */
  1927. var i = this.chunks.indexOf(chunk);
  1928. if (i !== -1) {
  1929. this.chunks.splice(i, 1);
  1930. }
  1931. if (!this.chunks.length) {
  1932. this.remove();
  1933. }
  1934. }
  1935. }]);
  1936.  
  1937. return ChunkCluster;
  1938. }();
  1939.  
  1940. /* Draws white text with a black border */
  1941.  
  1942.  
  1943. function drawText(ctx, str, x, y, centered) {
  1944. ctx.strokeStyle = "#000000", ctx.fillStyle = "#FFFFFF", ctx.lineWidth = 2.5, ctx.globalAlpha = 0.5;
  1945. if (centered) {
  1946. x -= ctx.measureText(str).width >> 1;
  1947. }
  1948. ctx.strokeText(str, x, y);
  1949. ctx.globalAlpha = 1;
  1950. ctx.fillText(str, x, y);
  1951. }
  1952.  
  1953. function isVisible(x, y, w, h) {
  1954. var cx = camera.x;
  1955. var cy = camera.y;
  1956. var czoom = camera.zoom;
  1957. var cw = window.innerWidth;
  1958. var ch = window.innerHeight;
  1959. return x + w > cx && y + h > cy && x <= cx + cw / czoom && y <= cy + ch / czoom;
  1960. }
  1961.  
  1962. function unloadFarClusters() {
  1963. /* Slow? */
  1964. var camx = camera.x;
  1965. var camy = camera.y;
  1966. var zoom = camera.zoom;
  1967. var camw = window.innerWidth / zoom | 0;
  1968. var camh = window.innerHeight / zoom | 0;
  1969. var ctrx = camx + camw / 2;
  1970. var ctry = camy + camh / 2;
  1971. var s = _conf.protocol.clusterChunkAmount * _conf.protocol.chunkSize;
  1972. for (var c in rendererValues.clusters) {
  1973. c = rendererValues.clusters[c];
  1974. if (!isVisible(c.x * s, c.y * s, s, s)) {
  1975. var dx = Math.abs(ctrx / s - c.x) | 0;
  1976. var dy = Math.abs(ctry / s - c.y) | 0;
  1977. var dist = dx + dy; /* no sqrt please */
  1978.  
  1979. if (dist > _conf.options.unloadDistance) {
  1980. c.remove();
  1981. }
  1982. }
  1983. }
  1984. }
  1985.  
  1986. function render(type) {
  1987. var time = (0, _misc.getTime)(true);
  1988. var camx = camera.x;
  1989. var camy = camera.y;
  1990. var zoom = camera.zoom;
  1991. var needsRender = 0; /* If an animation didn't finish, render again */
  1992.  
  1993. if (type & renderer.rendertype.WORLD) {
  1994. var uClusters = rendererValues.updatedClusters;
  1995. for (var i = 0; i < uClusters.length; i++) {
  1996. var c = uClusters[i];
  1997. c.render();
  1998. }
  1999. rendererValues.updatedClusters = [];
  2000. }
  2001.  
  2002. if (type & renderer.rendertype.FX && _main.misc.world !== null) {
  2003. var ctx = rendererValues.animContext;
  2004. var visible = rendererValues.visibleClusters;
  2005. var clusterCanvasSize = _conf.protocol.chunkSize * _conf.protocol.clusterChunkAmount;
  2006. var cwidth = window.innerWidth;
  2007. var cheight = window.innerHeight;
  2008. var background = rendererValues.worldBackground;
  2009. var allChunksLoaded = _main.misc.world.allChunksLoaded();
  2010.  
  2011. if (!allChunksLoaded) {
  2012. ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height);
  2013. }
  2014.  
  2015. ctx.lineWidth = 2.5 / 16 * zoom;
  2016.  
  2017. ctx.scale(zoom, zoom);
  2018.  
  2019. for (var i = 0; i < visible.length; i++) {
  2020. var cluster = visible[i];
  2021. var gx = -(camx - cluster.x * clusterCanvasSize);
  2022. var gy = -(camy - cluster.y * clusterCanvasSize);
  2023. var clipx = gx < 0 ? -gx : 0;
  2024. var clipy = gy < 0 ? -gy : 0;
  2025. var x = gx < 0 ? 0 : gx;
  2026. var y = gy < 0 ? 0 : gy;
  2027. var clipw = clusterCanvasSize - clipx;
  2028. var cliph = clusterCanvasSize - clipy;
  2029. clipw = clipw + x < cwidth / zoom ? clipw : cwidth / zoom - x;
  2030. cliph = cliph + y < cheight / zoom ? cliph : cheight / zoom - y;
  2031. clipw = clipw + 1 | 0; /* Math.ceil */
  2032. cliph = cliph + 1 | 0;
  2033. if (clipw > 0 && cliph > 0) {
  2034. ctx.drawImage(cluster.canvas, clipx, clipy, clipw, cliph, x, y, clipw, cliph);
  2035. }
  2036. }
  2037.  
  2038. ctx.scale(1 / zoom, 1 / zoom); /* probably faster than ctx.save(), ctx.restore() */
  2039.  
  2040. if (background != null) {
  2041. var newscale = zoom / _conf.options.defaultZoom;
  2042. var oldscale = _conf.options.defaultZoom / zoom;
  2043. var gx = -(camx * zoom) % (background.width * newscale);
  2044. var gy = -(camy * zoom) % (background.height * newscale);
  2045. ctx.translate(gx, gy);
  2046.  
  2047. ctx.fillStyle = background;
  2048. ctx.globalCompositeOperation = "destination-over";
  2049.  
  2050. ctx.scale(newscale, newscale);
  2051. ctx.fillRect(-gx / newscale, -gy / newscale, ctx.canvas.width * oldscale, ctx.canvas.height * oldscale);
  2052. ctx.scale(oldscale, oldscale);
  2053.  
  2054. ctx.translate(-gx, -gy);
  2055. }
  2056.  
  2057. var gx = -(camx * zoom) % (16 * zoom);
  2058. var gy = -(camy * zoom) % (16 * zoom);
  2059. ctx.translate(gx, gy);
  2060.  
  2061. if (rendererValues.gridShown && rendererValues.gridPattern) {
  2062. ctx.fillStyle = rendererValues.gridPattern;
  2063. if (!allChunksLoaded) {
  2064. ctx.globalCompositeOperation = "source-atop";
  2065. }
  2066. ctx.fillRect(-gx, -gy, ctx.canvas.width, ctx.canvas.height);
  2067. }
  2068.  
  2069. if (rendererValues.unloadedPattern != null && (!allChunksLoaded || background != null)) {
  2070. ctx.fillStyle = rendererValues.unloadedPattern;
  2071. ctx.globalCompositeOperation = "destination-over";
  2072. ctx.fillRect(-gx, -gy, ctx.canvas.width, ctx.canvas.height);
  2073. }
  2074.  
  2075. ctx.translate(-gx, -gy);
  2076.  
  2077. ctx.globalCompositeOperation = "source-over";
  2078.  
  2079. for (var i = 0; i < _Fx.activeFx.length; i++) {
  2080. switch (_Fx.activeFx[i].render(ctx, time)) {
  2081. case 0:
  2082. /* Anim not finished */
  2083. needsRender |= renderer.rendertype.FX;
  2084. break;
  2085. case 2:
  2086. /* Obj deleted from array, prevent flickering */
  2087. --i;
  2088. break;
  2089. }
  2090. }
  2091. ctx.globalAlpha = 1;
  2092. var players = _main.misc.world.players;
  2093. var fontsize = 10 / 16 * zoom | 0;
  2094. if (rendererValues.currentFontSize != fontsize) {
  2095. ctx.font = fontsize + "px sans-serif";
  2096. rendererValues.currentFontSize = fontsize;
  2097. }
  2098. for (var p in players) {
  2099. var player = players[p];
  2100. if (!renderPlayer(player, fontsize)) {
  2101. needsRender |= renderer.rendertype.FX;
  2102. }
  2103. }
  2104. }
  2105.  
  2106. requestRender(needsRender);
  2107. }
  2108.  
  2109. function renderPlayer(targetPlayer, fontsize) {
  2110. var camx = camera.x * 16;
  2111. var camy = camera.y * 16;
  2112. var zoom = camera.zoom;
  2113. var ctx = rendererValues.animContext;
  2114. var cnvs = ctx.canvas;
  2115. var tool = targetPlayer.tool;
  2116. if (!tool) {
  2117. /* Render the default tool if the selected one isn't defined */
  2118. tool = _tools.tools['cursor'];
  2119. }
  2120. var toolwidth = tool.cursor.width / 16 * zoom;
  2121. var toolheight = tool.cursor.height / 16 * zoom;
  2122.  
  2123. var x = targetPlayer.x;
  2124. var y = targetPlayer.y;
  2125. var cx = (x - camx - tool.offset[0]) * (zoom / 16) | 0;
  2126. var cy = (y - camy - tool.offset[1]) * (zoom / 16) | 0;
  2127.  
  2128. if (cx < -toolwidth || cy < -toolheight || cx > cnvs.width || cy > cnvs.height) {
  2129. return true;
  2130. }
  2131.  
  2132. if (fontsize > 3) {
  2133. var idstr = targetPlayer.id;
  2134. var textw = ctx.measureText(idstr).width + zoom / 2;
  2135.  
  2136. ctx.globalAlpha = 1;
  2137. ctx.fillStyle = targetPlayer.clr;
  2138. ctx.fillRect(cx, cy + toolheight, textw, zoom);
  2139. ctx.globalAlpha = 0.2;
  2140. ctx.lineWidth = 3;
  2141. ctx.strokeStyle = "#000000";
  2142. ctx.strokeRect(cx, cy + toolheight, textw, zoom);
  2143. ctx.globalAlpha = 1;
  2144. drawText(ctx, idstr, cx + zoom / 4, cy + fontsize + toolheight + zoom / 8);
  2145. }
  2146.  
  2147. ctx.drawImage(tool.cursor, cx, cy, toolwidth, toolheight);
  2148.  
  2149. return x === targetPlayer.endX && y === targetPlayer.endY;
  2150. }
  2151.  
  2152. function requestRender(type) {
  2153. rendererValues.updateRequired |= type;
  2154. }
  2155.  
  2156. function setGridVisibility(enabled) {
  2157. rendererValues.gridShown = enabled;
  2158. requestRender(renderer.rendertype.FX);
  2159. }
  2160.  
  2161. function renderGrid(zoom) {
  2162. var tmpcanvas = document.createElement("canvas");
  2163. var ctx = tmpcanvas.getContext("2d");
  2164. var size = tmpcanvas.width = tmpcanvas.height = Math.round(16 * zoom);
  2165. ctx.setLineDash([1]);
  2166. ctx.globalAlpha = 0.2;
  2167. if (zoom >= 4) {
  2168. var fadeMult = Math.min(1, zoom - 4);
  2169. if (fadeMult < 1) {
  2170. ctx.globalAlpha = 0.2 * fadeMult;
  2171. }
  2172. ctx.beginPath();
  2173. for (var i = 16; --i;) {
  2174. ctx.moveTo(i * zoom + .5, 0);
  2175. ctx.lineTo(i * zoom + .5, size);
  2176. ctx.moveTo(0, i * zoom + .5);
  2177. ctx.lineTo(size, i * zoom + .5);
  2178. }
  2179. ctx.stroke();
  2180. ctx.globalAlpha = Math.max(0.2, 1 * fadeMult);
  2181. }
  2182. ctx.beginPath();
  2183. ctx.moveTo(0, 0);
  2184. ctx.lineTo(0, size);
  2185. ctx.lineTo(size, size);
  2186. ctx.stroke();
  2187. return ctx.createPattern(tmpcanvas, "repeat");
  2188. }
  2189.  
  2190. function setGridZoom(zoom) {
  2191. if (zoom >= rendererValues.minGridZoom) {
  2192. rendererValues.gridPattern = renderGrid(zoom);
  2193. } else {
  2194. rendererValues.gridPattern = null;
  2195. }
  2196. }
  2197.  
  2198. function updateVisible() {
  2199. var clusters = rendererValues.clusters;
  2200. var visiblecl = rendererValues.visibleClusters;
  2201. for (var c in clusters) {
  2202. c = clusters[c];
  2203. var size = _conf.protocol.chunkSize * _conf.protocol.clusterChunkAmount;
  2204. var visible = isVisible(c.x * size, c.y * size, size, size);
  2205. if (!visible && c.shown) {
  2206. c.shown = false;
  2207. visiblecl.splice(visiblecl.indexOf(c), 1);
  2208. } else if (visible && !c.shown) {
  2209. c.shown = true;
  2210. visiblecl.push(c);
  2211. requestRender(renderer.rendertype.WORLD);
  2212. }
  2213. }
  2214. };
  2215.  
  2216. function onResize() {
  2217. _main.elements.animCanvas.width = window.innerWidth;
  2218. _main.elements.animCanvas.height = window.innerHeight;
  2219. var ctx = rendererValues.animContext;
  2220. ctx.imageSmoothingEnabled = false;
  2221. ctx.webkitImageSmoothingEnabled = false;
  2222. ctx.mozImageSmoothingEnabled = false;
  2223. ctx.msImageSmoothingEnabled = false;
  2224. ctx.oImageSmoothingEnabled = false;
  2225. rendererValues.currentFontSize = -1;
  2226. onCameraMove();
  2227. }
  2228.  
  2229. function alignCamera() {
  2230. var zoom = cameraValues.zoom;
  2231. var alignedX = Math.round(cameraValues.x * zoom) / zoom;
  2232. var alignedY = Math.round(cameraValues.y * zoom) / zoom;
  2233. cameraValues.x = alignedX;
  2234. cameraValues.y = alignedY;
  2235. }
  2236.  
  2237. function requestMissingChunks() {
  2238. /* TODO: move this to World */
  2239. var x = camera.x / _conf.protocol.chunkSize - 2 | 0;
  2240. var mx = camera.x / _conf.protocol.chunkSize + window.innerWidth / camera.zoom / _conf.protocol.chunkSize | 0;
  2241. var cy = camera.y / _conf.protocol.chunkSize - 2 | 0;
  2242. var my = camera.y / _conf.protocol.chunkSize + window.innerHeight / camera.zoom / _conf.protocol.chunkSize | 0;
  2243. while (++x <= mx) {
  2244. var y = cy;
  2245. while (++y <= my) {
  2246. _main.misc.world.loadChunk(x, y);
  2247. }
  2248. }
  2249. }
  2250.  
  2251. function onCameraMove() {
  2252. _global.eventSys.emit(_conf.EVENTS.camera.moved, camera);
  2253. alignCamera();
  2254. updateVisible();
  2255. if (_main.misc.world !== null) {
  2256. requestMissingChunks();
  2257. }
  2258. requestRender(renderer.rendertype.FX);
  2259. }
  2260.  
  2261. function getCenterPixel() {
  2262. var x = Math.round(cameraValues.x + window.innerWidth / camera.zoom / 2);
  2263. var y = Math.round(cameraValues.y + window.innerHeight / camera.zoom / 2);
  2264. return [x, y];
  2265. }
  2266.  
  2267. function centerCameraTo(x, y) {
  2268. cameraValues.x = -(window.innerWidth / camera.zoom / 2) + x;
  2269. cameraValues.y = -(window.innerHeight / camera.zoom / 2) + y;
  2270. onCameraMove();
  2271. }
  2272.  
  2273. function moveCameraBy(x, y) {
  2274. cameraValues.x += x;
  2275. cameraValues.y += y;
  2276. onCameraMove();
  2277. }
  2278.  
  2279. function moveCameraTo(x, y) {
  2280. cameraValues.x = x;
  2281. cameraValues.y = y;
  2282. onCameraMove();
  2283. }
  2284.  
  2285. _global.eventSys.on(_conf.EVENTS.net.world.teleported, function (x, y) {
  2286. centerCameraTo(x, y);
  2287. });
  2288.  
  2289. _global.eventSys.on(_conf.EVENTS.camera.zoom, function (z) {
  2290. setGridZoom(z);
  2291. /*cameraValues.lerpZoom.val = z;*/
  2292. requestRender(renderer.rendertype.FX);
  2293. });
  2294.  
  2295. _global.eventSys.on(_conf.EVENTS.renderer.addChunk, function (chunk) {
  2296. var clusterX = Math.floor(chunk.x / _conf.protocol.clusterChunkAmount);
  2297. var clusterY = Math.floor(chunk.y / _conf.protocol.clusterChunkAmount);
  2298. var key = clusterX + ',' + clusterY;
  2299. var clusters = rendererValues.clusters;
  2300. var cluster = clusters[key];
  2301. if (!cluster) {
  2302. cluster = clusters[key] = new ChunkCluster(clusterX, clusterY);
  2303. updateVisible();
  2304. }
  2305. cluster.addChunk(chunk);
  2306. if (!cluster.toUpdate) {
  2307. cluster.toUpdate = true;
  2308. rendererValues.updatedClusters.push(cluster);
  2309. }
  2310. var size = _conf.protocol.chunkSize;
  2311. if (cluster.toUpdate || isVisible(chunk.x * size, chunk.y * size, size, size)) {
  2312. requestRender(renderer.rendertype.WORLD | renderer.rendertype.FX);
  2313. }
  2314. });
  2315.  
  2316. _global.eventSys.on(_conf.EVENTS.renderer.rmChunk, function (chunk) {
  2317. var clusterX = Math.floor(chunk.x / _conf.protocol.clusterChunkAmount);
  2318. var clusterY = Math.floor(chunk.y / _conf.protocol.clusterChunkAmount);
  2319. var key = clusterX + ',' + clusterY;
  2320. var clusters = rendererValues.clusters;
  2321. var cluster = clusters[key];
  2322. if (cluster) {
  2323. cluster.delChunk(chunk);
  2324. if (!cluster.removed && !cluster.toUpdate) {
  2325. cluster.toUpdate = true;
  2326. rendererValues.updatedClusters.push(cluster);
  2327. }
  2328. }
  2329. });
  2330.  
  2331. _global.eventSys.on(_conf.EVENTS.renderer.updateChunk, function (chunk) {
  2332. var clusterX = Math.floor(chunk.x / _conf.protocol.clusterChunkAmount);
  2333. var clusterY = Math.floor(chunk.y / _conf.protocol.clusterChunkAmount);
  2334. var key = clusterX + ',' + clusterY;
  2335. var cluster = rendererValues.clusters[key];
  2336. if (cluster && !cluster.toUpdate) {
  2337. cluster.toUpdate = true;
  2338. rendererValues.updatedClusters.push(cluster);
  2339. }
  2340. var size = _conf.protocol.chunkSize;
  2341. if (isVisible(chunk.x * size, chunk.y * size, size, size)) {
  2342. requestRender(renderer.rendertype.WORLD | renderer.rendertype.FX);
  2343. }
  2344. });
  2345.  
  2346. _global.eventSys.on(_conf.EVENTS.misc.worldInitialized, function () {
  2347. requestMissingChunks();
  2348. });
  2349.  
  2350. _global.eventSys.once(_conf.EVENTS.init, function () {
  2351. rendererValues.animContext = _main.elements.animCanvas.getContext("2d", { alpha: false });
  2352. window.addEventListener("resize", onResize);
  2353. onResize();
  2354. camera.zoom = _conf.options.defaultZoom;
  2355. centerCameraTo(0, 0);
  2356.  
  2357. var mkPatternFromUrl = function mkPatternFromUrl(url, cb) {
  2358. var patImg = new Image();
  2359. patImg.onload = function () {
  2360. var pat = rendererValues.animContext.createPattern(patImg, "repeat");
  2361. pat.width = patImg.width;
  2362. pat.height = patImg.height;
  2363. cb(pat);
  2364. };
  2365. patImg.src = url;
  2366. };
  2367.  
  2368. /* Create the pattern images */
  2369. mkPatternFromUrl(_conf.options.unloadedPatternUrl, function (pat) {
  2370. rendererValues.unloadedPattern = pat;
  2371. });
  2372.  
  2373. if (_conf.options.backgroundUrl != null) {
  2374. mkPatternFromUrl(_conf.options.backgroundUrl, function (pat) {
  2375. rendererValues.worldBackground = pat;
  2376. });
  2377. }
  2378.  
  2379. function frameLoop() {
  2380. var type = void 0;
  2381. if ((type = rendererValues.updateRequired) !== 0) {
  2382. rendererValues.updateRequired = 0;
  2383. render(type);
  2384. }
  2385. window.requestAnimationFrame(frameLoop);
  2386. }
  2387. _global.eventSys.once(_conf.EVENTS.misc.toolsInitialized, frameLoop);
  2388. });
  2389.  
  2390. /***/ }),
  2391. /* 6 */
  2392. /***/ (function(module, exports, __webpack_require__) {
  2393.  
  2394. "use strict";
  2395.  
  2396.  
  2397. Object.defineProperty(exports, "__esModule", {
  2398. value: true
  2399. });
  2400. exports.player = exports.networkRankVerification = exports.undoHistory = exports.updateClientFx = undefined;
  2401. exports.shouldUpdate = shouldUpdate;
  2402. exports.getDefaultTool = getDefaultTool;
  2403.  
  2404. var _global = __webpack_require__(0);
  2405.  
  2406. var _conf = __webpack_require__(1);
  2407.  
  2408. var _misc = __webpack_require__(2);
  2409.  
  2410. var _main = __webpack_require__(3);
  2411.  
  2412. var _color = __webpack_require__(4);
  2413.  
  2414. var _canvas_renderer = __webpack_require__(5);
  2415.  
  2416. var _tool_renderer = __webpack_require__(13);
  2417.  
  2418. var _tools = __webpack_require__(10);
  2419.  
  2420. var _Fx = __webpack_require__(7);
  2421.  
  2422. var _networking = __webpack_require__(8);
  2423.  
  2424. var _Bucket = __webpack_require__(9);
  2425.  
  2426. exports.updateClientFx = updateClientFx;
  2427.  
  2428.  
  2429. var toolSelected = null;
  2430.  
  2431.  
  2432. /*const palette = [
  2433. [0x1A, 0x1C, 0x2C], [0x57, 0x29, 0x56], [0xB1, 0x41, 0x56], [0xEE, 0x7B, 0x58],
  2434. [0xFF, 0xD0, 0x79], [0xA0, 0xF0, 0x72], [0x38, 0xB8, 0x6E], [0x27, 0x6E, 0x7B],
  2435. [0x29, 0x36, 0x6F], [0x40, 0x5B, 0xD0], [0x4F, 0xA4, 0xF7], [0x86, 0xEC, 0xF8],
  2436. [0xF4, 0xF4, 0xF4], [0x93, 0xB6, 0xC1], [0x55, 0x71, 0x85], [0x32, 0x40, 0x56]
  2437. ];*/
  2438.  
  2439. var palette = [[0xE4, 0xA6, 0x72], [0xB8, 0x6F, 0x50], [0x74, 0x3F, 0x39], [0x3F, 0x28, 0x32], [0x9E, 0x28, 0x35], [0xE5, 0x3B, 0x44], [0xFB, 0x92, 0x2B], [0xFF, 0xE7, 0x62], [0x63, 0xC6, 0x4D], [0x32, 0x73, 0x45], [0x19, 0x3D, 0x3F], [0x4F, 0x67, 0x81], [0xAF, 0xBF, 0xD2], [0xFF, 0xFF, 0xFF], [0x2C, 0xE8, 0xF4], [0x04, 0x84, 0xD1]];
  2440. var paletteIndex = 0;
  2441.  
  2442. var undoHistory = exports.undoHistory = [];
  2443.  
  2444. var clientFx = new _Fx.Fx(_Fx.PLAYERFX.NONE, {
  2445. isLocalPlayer: true,
  2446. player: {
  2447. get tileX() {
  2448. return _main.mouse.tileX;
  2449. },
  2450. get tileY() {
  2451. return _main.mouse.tileY;
  2452. },
  2453. get x() {
  2454. return _main.mouse.worldX;
  2455. },
  2456. get y() {
  2457. return _main.mouse.worldY;
  2458. },
  2459. get htmlRgb() {
  2460. return player.htmlRgb;
  2461. },
  2462. get tool() {
  2463. return player.tool;
  2464. }
  2465. }
  2466. });
  2467.  
  2468. clientFx.setVisibleFunc(function () {
  2469. return _main.mouse.insideViewport && _main.mouse.validTile;
  2470. });
  2471.  
  2472.  
  2473. var networkRankVerification = exports.networkRankVerification = [_conf.RANK.NONE];
  2474. var rank = _conf.RANK.NONE;
  2475. var somethingChanged = false;
  2476.  
  2477. var cachedHtmlRgb = [null, ""];
  2478.  
  2479. var player = exports.player = {
  2480. get paletteIndex() {
  2481. return paletteIndex;
  2482. },
  2483. set paletteIndex(i) {
  2484. paletteIndex = (0, _misc.absMod)(i, palette.length);
  2485. updatePalette();
  2486. },
  2487. get htmlRgb() {
  2488. var selClr = player.selectedColor;
  2489. if (cachedHtmlRgb[0] === selClr) {
  2490. return cachedHtmlRgb[1];
  2491. } else {
  2492. var str = _color.colorUtils.toHTML(_color.colorUtils.u24_888(selClr[0], selClr[1], selClr[2]));
  2493. cachedHtmlRgb[0] = selClr;
  2494. cachedHtmlRgb[1] = str;
  2495. return str;
  2496. }
  2497. },
  2498. get selectedColor() {
  2499. return palette[paletteIndex];
  2500. },
  2501. set selectedColor(c) {
  2502. addPaletteColor(c);
  2503. },
  2504. get palette() {
  2505. return palette;
  2506. },
  2507. get rank() {
  2508. return rank;
  2509. },
  2510. get tool() {
  2511. return toolSelected;
  2512. },
  2513. set tool(name) {
  2514. selectTool(name);
  2515. },
  2516. /* TODO: Clear confusion between netid and tool id */
  2517. get toolId() {
  2518. return _networking.net.currentServer.proto.tools.id[toolSelected.id];
  2519. },
  2520. get tools() {
  2521. return _tools.tools;
  2522. }
  2523. };
  2524.  
  2525. _global.PublicAPI.player = player;
  2526.  
  2527. function shouldUpdate() {
  2528. /* sets colorChanged to false when called */
  2529. return somethingChanged ? !(somethingChanged = false) : somethingChanged;
  2530. }
  2531.  
  2532. function changedColor() {
  2533. updateClientFx();
  2534. updatePaletteIndex();
  2535. somethingChanged = true;
  2536. }
  2537.  
  2538. function updatePalette() {
  2539. var paletteColors = _main.elements.paletteColors;
  2540. paletteColors.innerHTML = "";
  2541. var colorClick = function colorClick(index) {
  2542. return function () {
  2543. paletteIndex = index;
  2544. changedColor();
  2545. };
  2546. };
  2547. var colorDelete = function colorDelete(index) {
  2548. return function () {
  2549. if (palette.length > 1) {
  2550. palette.splice(index, 1);
  2551. if (paletteIndex > index || paletteIndex === palette.length) {
  2552. --paletteIndex;
  2553. }
  2554. updatePalette();
  2555. changedColor();
  2556. }
  2557. };
  2558. };
  2559.  
  2560. for (var i = 0; i < palette.length; i++) {
  2561. var element = document.createElement("div");
  2562. var clr = palette[i];
  2563. element.style.backgroundColor = "rgb(" + clr[0] + "," + clr[1] + "," + clr[2] + ")";
  2564. (0, _misc.setTooltip)(element, _color.colorUtils.toHTML(_color.colorUtils.u24_888(clr[0], clr[1], clr[2])));
  2565. element.onmouseup = function (e) {
  2566. switch (e.button) {
  2567. case 0:
  2568. this.sel();
  2569. break;
  2570. case 2:
  2571. this.del();
  2572. break;
  2573. }
  2574. return false;
  2575. }.bind({
  2576. sel: colorClick(i),
  2577. del: colorDelete(i)
  2578. });
  2579. element.oncontextmenu = function () {
  2580. return false;
  2581. };
  2582. paletteColors.appendChild(element);
  2583. }
  2584. changedColor();
  2585. }
  2586.  
  2587. function updatePaletteIndex() {
  2588. _main.elements.paletteColors.style.transform = "translateY(" + -paletteIndex * 40 + "px)";
  2589. }
  2590.  
  2591. function addPaletteColor(color) {
  2592. for (var i = 0; i < palette.length; i++) {
  2593. if (palette[i][0] === color[0] && palette[i][1] === color[1] && palette[i][2] === color[2]) {
  2594. paletteIndex = i;
  2595. changedColor();
  2596. return;
  2597. }
  2598. }
  2599. paletteIndex = palette.length;
  2600. palette.push(color);
  2601. updatePalette();
  2602. }
  2603.  
  2604. function getDefaultTool() {
  2605. for (var toolName in _tools.tools) {
  2606. if (_tools.tools[toolName].rankRequired <= player.rank) {
  2607. return toolName;
  2608. }
  2609. }
  2610. return null;
  2611. }
  2612.  
  2613. function selectTool(name) {
  2614. var tool = _tools.tools[name];
  2615. if (!tool || tool === toolSelected || tool.rankRequired > player.rank) {
  2616. return false;
  2617. }
  2618. if (toolSelected) {
  2619. toolSelected.call('deselect');
  2620. }
  2621. toolSelected = tool;
  2622. _main.mouse.cancelMouseDown();
  2623. tool.call('select');
  2624. (0, _tools.updateToolWindow)(name);
  2625. _main.mouse.validClick = false;
  2626. clientFx.setRenderer(tool.fxRenderer);
  2627. somethingChanged = true;
  2628. updateClientFx();
  2629. return true;
  2630. }
  2631.  
  2632. function updateClientFx() {
  2633. _canvas_renderer.renderer.render(_canvas_renderer.renderer.rendertype.FX);
  2634. }
  2635.  
  2636. _global.eventSys.once(_conf.EVENTS.misc.toolsInitialized, function () {
  2637. player.tool = getDefaultTool();
  2638. });
  2639.  
  2640. _global.eventSys.on(_conf.EVENTS.net.sec.rank, function (newRank) {
  2641. if (networkRankVerification[0] < newRank) {
  2642. return;
  2643. }
  2644. rank = newRank;
  2645. console.log('Got rank:', newRank);
  2646. /* This is why we can't have nice things */
  2647. if (_networking.net.isConnected()) {
  2648. _networking.net.protocol.ws.send(new Uint8Array([newRank]).buffer);
  2649. }
  2650. switch (newRank) {
  2651. case _conf.RANK.USER:
  2652. case _conf.RANK.NONE:
  2653. (0, _main.showDevChat)(false);
  2654. (0, _main.showPlayerList)(false);
  2655. break;
  2656.  
  2657. case _conf.RANK.MODERATOR:
  2658. case _conf.RANK.ADMIN:
  2659. (0, _main.showDevChat)(true);
  2660. (0, _main.showPlayerList)(true);
  2661. break;
  2662. }
  2663. (0, _tools.updateToolbar)();
  2664. });
  2665.  
  2666. _global.eventSys.once(_conf.EVENTS.init, function () {
  2667. _main.elements.paletteInput.onclick = function () {
  2668. var c = player.selectedColor;
  2669. this.value = _color.colorUtils.toHTML(_color.colorUtils.u24_888(c[0], c[1], c[2]));;
  2670. };
  2671. _main.elements.paletteInput.onchange = function () {
  2672. var value = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(this.value);
  2673. addPaletteColor([parseInt(value[1], 16), parseInt(value[2], 16), parseInt(value[3], 16)]);
  2674. };
  2675. _main.elements.paletteCreate.onclick = function () {
  2676. return _main.elements.paletteInput.click();
  2677. };
  2678. (0, _misc.setTooltip)(_main.elements.paletteCreate, "Add color");
  2679. updatePalette();
  2680. });
  2681.  
  2682. /***/ }),
  2683. /* 7 */
  2684. /***/ (function(module, exports, __webpack_require__) {
  2685.  
  2686. "use strict";
  2687.  
  2688.  
  2689. Object.defineProperty(exports, "__esModule", {
  2690. value: true
  2691. });
  2692. exports.Fx = exports.activeFx = exports.WORLDFX = exports.PLAYERFX = undefined;
  2693.  
  2694. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  2695.  
  2696. var _color = __webpack_require__(4);
  2697.  
  2698. var _conf = __webpack_require__(1);
  2699.  
  2700. var _misc = __webpack_require__(2);
  2701.  
  2702. var _global = __webpack_require__(0);
  2703.  
  2704. var _canvas_renderer = __webpack_require__(5);
  2705.  
  2706. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  2707.  
  2708. var PLAYERFX = exports.PLAYERFX = {
  2709. NONE: null,
  2710. RECT_SELECT_ALIGNED: function RECT_SELECT_ALIGNED(pixelSize, htmlColor) {
  2711. return function (fx, ctx, time) {
  2712. var x = fx.extra.player.x;
  2713. var y = fx.extra.player.y;
  2714. var fxx = (Math.floor(x / (16 * pixelSize)) * pixelSize - _canvas_renderer.camera.x) * _canvas_renderer.camera.zoom;
  2715. var fxy = (Math.floor(y / (16 * pixelSize)) * pixelSize - _canvas_renderer.camera.y) * _canvas_renderer.camera.zoom;
  2716. ctx.globalAlpha = 0.8;
  2717. ctx.strokeStyle = htmlColor || fx.extra.player.htmlRgb;
  2718. ctx.strokeRect(fxx, fxy, _canvas_renderer.camera.zoom * pixelSize, _canvas_renderer.camera.zoom * pixelSize);
  2719. return 1; /* Rendering finished (won't change on next frame) */
  2720. };
  2721. }
  2722. };
  2723.  
  2724. var WORLDFX = exports.WORLDFX = {
  2725. NONE: null,
  2726. RECT_FADE_ALIGNED: function RECT_FADE_ALIGNED(size, x, y) {
  2727. var startTime = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : (0, _misc.getTime)();
  2728. return function (fx, ctx, time) {
  2729. var alpha = 1 - (time - startTime) / 1000;
  2730. if (alpha <= 0) {
  2731. fx.delete();
  2732. return 2; /* 2 = An FX object was deleted */
  2733. }
  2734. var fxx = (x * size - _canvas_renderer.camera.x) * _canvas_renderer.camera.zoom;
  2735. var fxy = (y * size - _canvas_renderer.camera.y) * _canvas_renderer.camera.zoom;
  2736. ctx.globalAlpha = alpha;
  2737. ctx.strokeStyle = fx.extra.htmlRgb || "#000000";
  2738. ctx.strokeRect(fxx, fxy, _canvas_renderer.camera.zoom * size, _canvas_renderer.camera.zoom * size);
  2739. return 0; /* 0 = Animation not finished */
  2740. };
  2741. }
  2742. };
  2743.  
  2744. var activeFx = exports.activeFx = [];
  2745.  
  2746. /*PublicAPI.activeFx = activeFx;*/
  2747.  
  2748. var Fx = exports.Fx = function () {
  2749. function Fx(renderFunc, extra) {
  2750. _classCallCheck(this, Fx);
  2751.  
  2752. this.visible = true;
  2753. this.renderFunc = renderFunc;
  2754. this.extra = extra || {};
  2755. activeFx.push(this);
  2756. }
  2757.  
  2758. _createClass(Fx, [{
  2759. key: 'render',
  2760. value: function render(ctx, time) {
  2761. if (this.renderFunc && this.visible) {
  2762. return this.renderFunc(this, ctx, time);
  2763. }
  2764. return 1;
  2765. }
  2766. }, {
  2767. key: 'setVisibleFunc',
  2768. value: function setVisibleFunc(func) {
  2769. Object.defineProperty(this, 'visible', {
  2770. get: func
  2771. });
  2772. }
  2773. }, {
  2774. key: 'setVisible',
  2775. value: function setVisible(bool) {
  2776. this.visible = bool;
  2777. }
  2778. }, {
  2779. key: 'setRenderer',
  2780. value: function setRenderer(func) {
  2781. this.renderFunc = func;
  2782. }
  2783. }, {
  2784. key: 'update',
  2785. value: function update(extra) {
  2786. this.extra = extra;
  2787. }
  2788. }, {
  2789. key: 'delete',
  2790. value: function _delete() {
  2791. var i = activeFx.indexOf(this);
  2792. if (i !== -1) {
  2793. activeFx.splice(i, 1);
  2794. }
  2795. }
  2796. }]);
  2797.  
  2798. return Fx;
  2799. }();
  2800.  
  2801. _global.PublicAPI.fx = {
  2802. world: WORLDFX,
  2803. player: PLAYERFX,
  2804. class: Fx
  2805. };
  2806.  
  2807. _global.eventSys.on(_conf.EVENTS.net.world.tilesUpdated, function (tiles) {
  2808. var time = (0, _misc.getTime)(true);
  2809. var made = false;
  2810. for (var i = 0; i < tiles.length; i++) {
  2811. var t = tiles[i];
  2812. if (_canvas_renderer.camera.isVisible(t.x, t.y, 1, 1)) {
  2813. new Fx(WORLDFX.RECT_FADE_ALIGNED(1, t.x, t.y), { htmlRgb: _color.colorUtils.toHTML(t.rgb ^ 0xFFFFFF) });
  2814. made = true;
  2815. }
  2816. }
  2817. if (made) {
  2818. _canvas_renderer.renderer.render(_canvas_renderer.renderer.rendertype.FX);
  2819. }
  2820. });
  2821.  
  2822. _global.eventSys.on(_conf.EVENTS.net.chunk.set, function (chunkX, chunkY, data) {
  2823. var wX = chunkX * _conf.protocol.chunkSize;
  2824. var wY = chunkY * _conf.protocol.chunkSize;
  2825. if (_canvas_renderer.camera.isVisible(wX, wY, _conf.protocol.chunkSize, _conf.protocol.chunkSize)) {
  2826. new Fx(WORLDFX.RECT_FADE_ALIGNED(16, chunkX, chunkY));
  2827. _canvas_renderer.renderer.render(_canvas_renderer.renderer.rendertype.FX);
  2828. }
  2829. });
  2830.  
  2831. _global.eventSys.on(_conf.EVENTS.net.chunk.lock, function (chunkX, chunkY, state, local) {
  2832. var wX = chunkX * _conf.protocol.chunkSize;
  2833. var wY = chunkY * _conf.protocol.chunkSize;
  2834. if (!local && _canvas_renderer.camera.isVisible(wX, wY, _conf.protocol.chunkSize, _conf.protocol.chunkSize)) {
  2835. new Fx(WORLDFX.RECT_FADE_ALIGNED(16, chunkX, chunkY), {
  2836. htmlRgb: state ? "#00FF00" : "#FF0000"
  2837. });
  2838. _canvas_renderer.renderer.render(_canvas_renderer.renderer.rendertype.FX);
  2839. }
  2840. });
  2841.  
  2842. /***/ }),
  2843. /* 8 */
  2844. /***/ (function(module, exports, __webpack_require__) {
  2845.  
  2846. "use strict";
  2847.  
  2848.  
  2849. Object.defineProperty(exports, "__esModule", {
  2850. value: true
  2851. });
  2852. exports.net = undefined;
  2853.  
  2854. var _conf = __webpack_require__(1);
  2855.  
  2856. var _global = __webpack_require__(0);
  2857.  
  2858. var net = exports.net = {
  2859. currentServer: null,
  2860. protocol: null,
  2861. isConnected: isConnected,
  2862. connect: connect
  2863. };
  2864.  
  2865. _global.PublicAPI.net = net;
  2866.  
  2867. function isConnected() {
  2868. return net.protocol !== null && net.protocol.isConnected();
  2869. }
  2870.  
  2871. function connect(server, worldName) {
  2872. _global.eventSys.emit(_conf.EVENTS.net.connecting, server);
  2873. net.connection = new WebSocket(server.url);
  2874. net.connection.binaryType = "arraybuffer";
  2875. net.currentServer = server;
  2876. net.protocol = new server.proto.class(net.connection, worldName);
  2877. }
  2878.  
  2879. /***/ }),
  2880. /* 9 */
  2881. /***/ (function(module, exports, __webpack_require__) {
  2882.  
  2883. "use strict";
  2884.  
  2885.  
  2886. Object.defineProperty(exports, "__esModule", {
  2887. value: true
  2888. });
  2889.  
  2890. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  2891.  
  2892. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  2893.  
  2894. var Bucket = exports.Bucket = function () {
  2895. function Bucket(rate, time) {
  2896. _classCallCheck(this, Bucket);
  2897.  
  2898. this.lastCheck = Date.now();
  2899. this.allowance = rate;
  2900. this.rate = rate;
  2901. this.time = time;
  2902. this.infinite = false;
  2903. }
  2904.  
  2905. _createClass(Bucket, [{
  2906. key: 'canSpend',
  2907. value: function canSpend(count) {
  2908. if (this.infinite) {
  2909. return true;
  2910. }
  2911.  
  2912. this.allowance += (Date.now() - this.lastCheck) / 1000 * (this.rate / this.time);
  2913. this.lastCheck = Date.now();
  2914. if (this.allowance > this.rate) {
  2915. this.allowance = this.rate;
  2916. }
  2917. if (this.allowance < count) {
  2918. return false;
  2919. }
  2920. this.allowance -= count;
  2921. return true;
  2922. }
  2923. }]);
  2924.  
  2925. return Bucket;
  2926. }();
  2927.  
  2928. /***/ }),
  2929. /* 10 */
  2930. /***/ (function(module, exports, __webpack_require__) {
  2931.  
  2932. "use strict";
  2933.  
  2934.  
  2935. Object.defineProperty(exports, "__esModule", {
  2936. value: true
  2937. });
  2938. exports.toolsWindow = exports.tools = undefined;
  2939.  
  2940. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  2941.  
  2942. exports.updateToolWindow = updateToolWindow;
  2943. exports.updateToolbar = updateToolbar;
  2944. exports.showToolsWindow = showToolsWindow;
  2945. exports.addTool = addTool;
  2946.  
  2947. var _global = __webpack_require__(0);
  2948.  
  2949. var _conf = __webpack_require__(1);
  2950.  
  2951. var _misc = __webpack_require__(2);
  2952.  
  2953. var _tool_renderer = __webpack_require__(13);
  2954.  
  2955. var _networking = __webpack_require__(8);
  2956.  
  2957. var _local_player = __webpack_require__(6);
  2958.  
  2959. var _canvas_renderer = __webpack_require__(5);
  2960.  
  2961. var _windowsys = __webpack_require__(11);
  2962.  
  2963. var _main = __webpack_require__(3);
  2964.  
  2965. var _Fx = __webpack_require__(7);
  2966.  
  2967. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  2968.  
  2969. var tools = exports.tools = {};
  2970. var toolsWindow = exports.toolsWindow = null;
  2971. var windowShown = false;
  2972.  
  2973. function updateToolWindow(name) {
  2974. if (!toolsWindow) {
  2975. return;
  2976. }
  2977. var tool = tools[name];
  2978. var children = toolsWindow.container.children;
  2979. for (var i = 0; i < children.length; i++) {
  2980. var button = children[i];
  2981. var isSelected = button.id.split('-')[1] === name;
  2982. button.className = isSelected ? 'selected' : '';
  2983. button.children[0].style.backgroundImage = "url(" + (isSelected ? _tool_renderer.cursors.slotset : _tool_renderer.cursors.set.src) + ")";
  2984. }
  2985. _main.elements.viewport.style.cursor = "url(" + tool.cursorblob + ") " + tool.offset[0] + " " + tool.offset[1] + ", pointer";
  2986. }
  2987.  
  2988. function updateToolbar() {
  2989. var win = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : toolsWindow;
  2990.  
  2991. if (!win) {
  2992. return;
  2993. }
  2994.  
  2995. var container = win.container;
  2996. var toolButtonClick = function toolButtonClick(name) {
  2997. return function (event) {
  2998. _local_player.player.tool = name;
  2999. _main.sounds.play(_main.sounds.click);
  3000. };
  3001. };
  3002.  
  3003. container.innerHTML = "";
  3004.  
  3005.  
  3006. for (var name in tools) {
  3007. var tool = tools[name];
  3008. if (_local_player.player.rank >= tool.rankRequired) {
  3009. var element = document.createElement("button");
  3010. var mask = document.createElement("div");
  3011. (0, _misc.setTooltip)(element, tool.name + " tool");
  3012. element.id = "tool-" + name;
  3013. element.addEventListener("click", toolButtonClick(name));
  3014. if (tool === _local_player.player.tool) {
  3015. mask.style.backgroundImage = "url(" + _tool_renderer.cursors.slotset + ")";
  3016. element.className = "selected";
  3017. } else {
  3018. mask.style.backgroundImage = "url(" + _tool_renderer.cursors.set.src + ")";
  3019. }
  3020. mask.style.backgroundPosition = tool.setposition;
  3021. element.appendChild(mask);
  3022. container.appendChild(element);
  3023. }
  3024. }
  3025. }
  3026.  
  3027. function showToolsWindow(bool) {
  3028. if (windowShown !== bool) {
  3029. if (bool && toolsWindow) {
  3030. _windowsys.windowSys.addWindow(toolsWindow);
  3031. } else if (toolsWindow) {
  3032. _windowsys.windowSys.delWindow(toolsWindow);
  3033. }
  3034. windowShown = bool;
  3035. }
  3036. }
  3037.  
  3038. function addTool(tool) {
  3039. tool.id = tool.name.toLowerCase();
  3040. tools[tool.id] = tool;
  3041. updateToolbar();
  3042. }
  3043.  
  3044. var Tool = function () {
  3045. function Tool(name, cursor, fxRenderer, rankNeeded, onInit) {
  3046. _classCallCheck(this, Tool);
  3047.  
  3048. this.name = name;
  3049. this.id = null;
  3050. this.fxRenderer = fxRenderer;
  3051. this.cursorblob = cursor.img.shadowblob;
  3052. this.cursor = cursor.img.shadowed;
  3053. this.setposition = -cursor.imgpos[0] * 36 + "px " + -cursor.imgpos[1] * 36 + "px";
  3054. this.offset = cursor.hotspot;
  3055. this.rankRequired = rankNeeded;
  3056. this.extra = {}; /* Extra storage for tools */
  3057. this.events = {
  3058. mouseup: null,
  3059. mousedown: null,
  3060. mousemove: null,
  3061. touchstart: null,
  3062. touchmove: null,
  3063. touchend: null,
  3064. touchcancel: null,
  3065. select: null,
  3066. deselect: null,
  3067. keydown: null,
  3068. keyup: null,
  3069. scroll: null,
  3070. tick: null
  3071. };
  3072. onInit(this);
  3073. }
  3074.  
  3075. /* Doesn't update if tool already selected */
  3076.  
  3077.  
  3078. _createClass(Tool, [{
  3079. key: 'setFxRenderer',
  3080. value: function setFxRenderer(func) {
  3081. this.fxRenderer = func;
  3082. }
  3083. }, {
  3084. key: 'isEventDefined',
  3085. value: function isEventDefined(type) {
  3086. return type in this.events;
  3087. }
  3088. }, {
  3089. key: 'setEvent',
  3090. value: function setEvent(type, func) {
  3091. var events = type.split(' ');
  3092. for (var i = 0; i < events.length; i++) {
  3093. this.events[events[i]] = func || null;
  3094. }
  3095. }
  3096. }, {
  3097. key: 'call',
  3098. value: function call(type, data) {
  3099. var func = this.events[type];
  3100. if (func) {
  3101. return func.apply(this, data);
  3102. } else if (type.indexOf("touch") === 0) {
  3103. return this.defaultTouchHandler(type.slice(5), data);
  3104. }
  3105. return false;
  3106. }
  3107. }, {
  3108. key: 'defaultTouchHandler',
  3109. value: function defaultTouchHandler(type, data) {
  3110. var mouse = data[0];
  3111. var event = data[1]; /* hmm... */
  3112. var handlers = {
  3113. start: this.events.mousedown,
  3114. move: this.events.mousemove,
  3115. end: this.events.mouseup,
  3116. cancel: this.events.mouseup
  3117. };
  3118. var handler = handlers[type];
  3119. if (handler) {
  3120. var touches = event.changedTouches;
  3121. for (var i = 0; i < touches.length; i++) {
  3122. mouse.x = touches[i].pageX;
  3123. mouse.y = touches[i].pageY;
  3124. handler.apply(this, data);
  3125. }
  3126. }
  3127. }
  3128. }]);
  3129.  
  3130. return Tool;
  3131. }();
  3132.  
  3133. _global.PublicAPI.tool = {
  3134. class: Tool,
  3135. addToolObject: addTool,
  3136. updateToolbar: updateToolbar,
  3137. allTools: tools
  3138. };
  3139.  
  3140. _global.eventSys.once(_conf.EVENTS.misc.toolsRendered, function () {
  3141.  
  3142. addTool(new Tool('Cursor', _tool_renderer.cursors.cursor, _Fx.PLAYERFX.RECT_SELECT_ALIGNED(1), _conf.RANK.USER, function (tool) {
  3143. var lastX, lastY;
  3144. tool.setEvent('mousedown mousemove', function (mouse, event) {
  3145. var usedButtons = 3; /* Left and right mouse buttons are always used... */
  3146. /* White color if right clicking */
  3147. var color = mouse.buttons === 2 ? [255, 255, 255] : _local_player.player.selectedColor;
  3148. switch (mouse.buttons) {
  3149. case 1:
  3150. case 2:
  3151. if (!lastX || !lastY) {
  3152. lastX = mouse.tileX;
  3153. lastY = mouse.tileY;
  3154. }
  3155. (0, _misc.line)(lastX, lastY, mouse.tileX, mouse.tileY, 1, function (x, y) {
  3156. var pixel = _main.misc.world.getPixel(x, y);
  3157. if (pixel !== null && !(color[0] === pixel[0] && color[1] === pixel[1] && color[2] === pixel[2])) {
  3158. _main.misc.world.setPixel(x, y, color);
  3159. }
  3160. });
  3161. lastX = mouse.tileX;
  3162. lastY = mouse.tileY;
  3163. break;
  3164. case 4:
  3165. if (event.ctrlKey) {
  3166. usedButtons |= 4;
  3167. var color = _main.misc.world.getPixel(mouse.tileX, mouse.tileY);
  3168. if (color) {
  3169. _local_player.player.selectedColor = color;
  3170. }
  3171. }
  3172. break;
  3173. }
  3174. return usedButtons;
  3175. });
  3176. tool.setEvent('mouseup', function (mouse) {
  3177. lastX = null;
  3178. lastY = null;
  3179. });
  3180. }));
  3181.  
  3182.  
  3183. addTool(new Tool('Move', _tool_renderer.cursors.move, _Fx.PLAYERFX.NONE, _conf.RANK.NONE, function (tool) {
  3184. function move(x, y, startX, startY) {
  3185. (0, _canvas_renderer.moveCameraBy)((startX - x) / 16, (startY - y) / 16);
  3186. }
  3187. tool.setEvent('mousemove', function (mouse, event) {
  3188. if (mouse.buttons !== 0) {
  3189. move(mouse.worldX, mouse.worldY, mouse.mouseDownWorldX, mouse.mouseDownWorldY);
  3190. return mouse.buttons;
  3191. }
  3192. });
  3193. tool.setEvent('scroll', function (mouse, event, rawEvent) {
  3194. if (!rawEvent.ctrlKey) {
  3195. var dx = Math.max(-500, Math.min(event.spinX * 16, 500));
  3196. var dy = Math.max(-500, Math.min(event.spinY * 16, 500));
  3197. var pxAmount = _canvas_renderer.camera.zoom;
  3198. (0, _canvas_renderer.moveCameraBy)(dx / pxAmount, dy / pxAmount);
  3199. return true;
  3200. }
  3201. });
  3202. }));
  3203.  
  3204.  
  3205. addTool(new Tool('Pipette', _tool_renderer.cursors.pipette, _Fx.PLAYERFX.NONE, _conf.RANK.NONE, function (tool) {
  3206. tool.setEvent('mousedown mousemove', function (mouse, event) {
  3207. if (mouse.buttons !== 0 && !(mouse.buttons & 4)) {
  3208. var color = _main.misc.world.getPixel(mouse.tileX, mouse.tileY);
  3209. if (color) {
  3210. _local_player.player.selectedColor = color;
  3211. }
  3212. return mouse.buttons;
  3213. }
  3214. });
  3215. }));
  3216.  
  3217.  
  3218. addTool(new Tool('Eraser', _tool_renderer.cursors.erase, _Fx.PLAYERFX.RECT_SELECT_ALIGNED(16), _conf.RANK.ADMIN, function (tool) {
  3219. function fillChunk(chunkX, chunkY, c) {
  3220. var color = c[2] << 16 | c[1] << 8 | c[0];
  3221. var chunk = _main.misc.world.getChunkAt(chunkX, chunkY);
  3222. if (chunk) {
  3223. var empty = true;
  3224. firstLoop: for (var y = 0; y < _conf.protocol.chunkSize; y++) {
  3225. for (var x = 0; x < _conf.protocol.chunkSize; x++) {
  3226. if ((chunk.get(x, y) & 0xFFFFFF) != color) {
  3227. empty = false;
  3228. break firstLoop;
  3229. }
  3230. }
  3231. }
  3232. if (!empty) {
  3233. chunk.set(color);
  3234. _networking.net.protocol.setChunk(chunkX, chunkY, new Array(256).fill(color));
  3235. }
  3236. }
  3237. }
  3238.  
  3239. tool.setEvent('mousedown mousemove', function (mouse, event) {
  3240. if (mouse.buttons & 1) {
  3241. fillChunk(Math.floor(mouse.tileX / _conf.protocol.chunkSize), Math.floor(mouse.tileY / _conf.protocol.chunkSize), _local_player.player.selectedColor);
  3242. return 1;
  3243. } else if (mouse.buttons & 2) {
  3244. fillChunk(Math.floor(mouse.tileX / _conf.protocol.chunkSize), Math.floor(mouse.tileY / _conf.protocol.chunkSize), [255, 255, 255]);
  3245. return 1;
  3246. }
  3247. });
  3248. }));
  3249.  
  3250.  
  3251. addTool(new Tool('Zoom', _tool_renderer.cursors.zoom, _Fx.PLAYERFX.NONE, _conf.RANK.NONE, function (tool) {
  3252. function zoom(mouse, type) {
  3253. var lzoom = _canvas_renderer.camera.zoom;
  3254. var nzoom = _canvas_renderer.camera.zoom;
  3255. var offX = 0;
  3256. var offY = 0;
  3257. var w = window.innerWidth;
  3258. var h = window.innerHeight;
  3259. if (type === 1) {
  3260.  
  3261. nzoom *= 1 + _conf.options.zoomStrength;
  3262. offX = (mouse.x - w / 2) / nzoom;
  3263. offY = (mouse.y - h / 2) / nzoom;
  3264. } else if (type === 2) {
  3265.  
  3266. nzoom /= 1 + _conf.options.zoomStrength;
  3267. offX = (mouse.x - w / 2) * (3 / lzoom - 2 / nzoom);
  3268. offY = (mouse.y - h / 2) * (3 / lzoom - 2 / nzoom);
  3269. } else if (type === 3) {
  3270.  
  3271. nzoom = _conf.options.defaultZoom;
  3272. }
  3273. nzoom = Math.round(nzoom);
  3274. _canvas_renderer.camera.zoom = nzoom;
  3275. if (_canvas_renderer.camera.zoom !== lzoom) {
  3276. (0, _canvas_renderer.moveCameraBy)(offX, offY);
  3277. }
  3278. }
  3279.  
  3280. tool.setEvent("mousedown", function (mouse, event) {
  3281. zoom(mouse, mouse.buttons);
  3282. });
  3283. tool.setEvent("touchstart", function (mouse, event) {
  3284. tool.extra.maxTouches = Math.max(tool.extra.maxTouches || 0, event.touches.length);
  3285. });
  3286. tool.setEvent("touchend", function (mouse, event) {
  3287. if (event.touches.length === 0) {
  3288. if (tool.extra.maxTouches > 1) {
  3289. zoom(mouse, tool.extra.maxTouches);
  3290. }
  3291. tool.extra.maxTouches = 0;
  3292. }
  3293. });
  3294. }));
  3295.  
  3296.  
  3297. addTool(new Tool('Export', _tool_renderer.cursors.select, _Fx.PLAYERFX.NONE, _conf.RANK.NONE, function (tool) {
  3298. tool.setFxRenderer(function (fx, ctx, time) {
  3299. if (!fx.extra.isLocalPlayer) return 1;
  3300. var x = fx.extra.player.x;
  3301. var y = fx.extra.player.y;
  3302. var fxx = (Math.floor(x / 16) - _canvas_renderer.camera.x) * _canvas_renderer.camera.zoom;
  3303. var fxy = (Math.floor(y / 16) - _canvas_renderer.camera.y) * _canvas_renderer.camera.zoom;
  3304. var oldlinew = ctx.lineWidth;
  3305. ctx.lineWidth = 1;
  3306. if (tool.extra.end) {
  3307. var s = tool.extra.start;
  3308. var e = tool.extra.end;
  3309. var x = (s[0] - _canvas_renderer.camera.x) * _canvas_renderer.camera.zoom + 0.5;
  3310. var y = (s[1] - _canvas_renderer.camera.y) * _canvas_renderer.camera.zoom + 0.5;
  3311. var w = e[0] - s[0];
  3312. var h = e[1] - s[1];
  3313. ctx.beginPath();
  3314. ctx.rect(x, y, w * _canvas_renderer.camera.zoom, h * _canvas_renderer.camera.zoom);
  3315. ctx.globalAlpha = 1;
  3316. ctx.strokeStyle = "#FFFFFF";
  3317. ctx.stroke();
  3318. ctx.setLineDash([3, 4]);
  3319. ctx.strokeStyle = "#000000";
  3320. ctx.stroke();
  3321. ctx.globalAlpha = 0.25 + Math.sin(time / 500) / 4;
  3322. ctx.fillStyle = _canvas_renderer.renderer.patterns.unloaded;
  3323. ctx.fill();
  3324. ctx.setLineDash([]);
  3325. var oldfont = ctx.font;
  3326. ctx.font = "16px sans-serif";
  3327. var txt = (!tool.extra.clicking ? "Right click to screenshot " : "") + '(' + Math.abs(w) + 'x' + Math.abs(h) + ')';
  3328. var txtx = window.innerWidth >> 1;
  3329. var txty = window.innerHeight >> 1;
  3330. txtx = Math.max(x, Math.min(txtx, x + w * _canvas_renderer.camera.zoom));
  3331. txty = Math.max(y, Math.min(txty, y + h * _canvas_renderer.camera.zoom));
  3332.  
  3333. (0, _canvas_renderer.drawText)(ctx, txt, txtx, txty, true);
  3334. ctx.font = oldfont;
  3335. ctx.lineWidth = oldlinew;
  3336. return 0;
  3337. } else {
  3338. ctx.beginPath();
  3339. ctx.moveTo(0, fxy + 0.5);
  3340. ctx.lineTo(window.innerWidth, fxy + 0.5);
  3341. ctx.moveTo(fxx + 0.5, 0);
  3342. ctx.lineTo(fxx + 0.5, window.innerHeight);
  3343.  
  3344.  
  3345. ctx.globalAlpha = 1;
  3346. ctx.strokeStyle = "#FFFFFF";
  3347. ctx.stroke();
  3348. ctx.setLineDash([3]);
  3349. ctx.strokeStyle = "#000000";
  3350. ctx.stroke();
  3351.  
  3352. ctx.setLineDash([]);
  3353. ctx.lineWidth = oldlinew;
  3354. return 1;
  3355. }
  3356. });
  3357.  
  3358. function dlarea(x, y, w, h, onblob) {
  3359. var c = document.createElement('canvas');
  3360. c.width = w;
  3361. c.height = h;
  3362. var ctx = c.getContext('2d');
  3363. var d = ctx.createImageData(w, h);
  3364. for (var i = y; i < y + h; i++) {
  3365. for (var j = x; j < x + w; j++) {
  3366. var pix = _main.misc.world.getPixel(j, i);
  3367. if (!pix) continue;
  3368. d.data[4 * ((i - y) * w + (j - x))] = pix[0];
  3369. d.data[4 * ((i - y) * w + (j - x)) + 1] = pix[1];
  3370. d.data[4 * ((i - y) * w + (j - x)) + 2] = pix[2];
  3371. d.data[4 * ((i - y) * w + (j - x)) + 3] = 255;
  3372. }
  3373. }
  3374. ctx.putImageData(d, 0, 0);
  3375. c.toBlob(onblob);
  3376. }
  3377.  
  3378. tool.extra.start = null;
  3379. tool.extra.end = null;
  3380. tool.extra.clicking = false;
  3381.  
  3382. tool.setEvent('mousedown', function (mouse, event) {
  3383. var s = tool.extra.start;
  3384. var e = tool.extra.end;
  3385. var isInside = function isInside() {
  3386. return mouse.tileX >= s[0] && mouse.tileX < e[0] && mouse.tileY >= s[1] && mouse.tileY < e[1];
  3387. };
  3388. if (mouse.buttons === 1 && !tool.extra.end) {
  3389. tool.extra.start = [mouse.tileX, mouse.tileY];
  3390. tool.extra.clicking = true;
  3391. tool.setEvent('mousemove', function (mouse, event) {
  3392. if (tool.extra.start && mouse.buttons === 1) {
  3393. tool.extra.end = [mouse.tileX, mouse.tileY];
  3394. return 1;
  3395. }
  3396. });
  3397. var finish = function finish() {
  3398. tool.setEvent('mousemove mouseup deselect', null);
  3399. tool.extra.clicking = false;
  3400. var s = tool.extra.start;
  3401. var e = tool.extra.end;
  3402. if (e) {
  3403. if (s[0] === e[0] || s[1] === e[1]) {
  3404. tool.extra.start = null;
  3405. tool.extra.end = null;
  3406. }
  3407. if (s[0] > e[0]) {
  3408. var tmp = e[0];
  3409. e[0] = s[0];
  3410. s[0] = tmp;
  3411. }
  3412. if (s[1] > e[1]) {
  3413. var tmp = e[1];
  3414. e[1] = s[1];
  3415. s[1] = tmp;
  3416. }
  3417. }
  3418. _canvas_renderer.renderer.render(_canvas_renderer.renderer.rendertype.FX);
  3419. };
  3420. tool.setEvent('deselect', finish);
  3421. tool.setEvent('mouseup', function (mouse, event) {
  3422. if (!(mouse.buttons & 1)) {
  3423. finish();
  3424. }
  3425. });
  3426. } else if (mouse.buttons === 1 && tool.extra.end) {
  3427. if (isInside()) {
  3428. var offx = mouse.tileX;
  3429. var offy = mouse.tileY;
  3430. tool.setEvent('mousemove', function (mouse, event) {
  3431. var dx = mouse.tileX - offx;
  3432. var dy = mouse.tileY - offy;
  3433. tool.extra.start = [s[0] + dx, s[1] + dy];
  3434. tool.extra.end = [e[0] + dx, e[1] + dy];
  3435. });
  3436. var end = function end() {
  3437. tool.setEvent('mouseup deselect mousemove', null);
  3438. };
  3439. tool.setEvent('deselect', end);
  3440. tool.setEvent('mouseup', function (mouse, event) {
  3441. if (!(mouse.buttons & 1)) {
  3442. end();
  3443. }
  3444. });
  3445. } else {
  3446. tool.extra.start = null;
  3447. tool.extra.end = null;
  3448. }
  3449. } else if (mouse.buttons === 2 && tool.extra.end && isInside()) {
  3450. tool.extra.start = null;
  3451. tool.extra.end = null;
  3452. var cvs = dlarea(s[0], s[1], e[0] - s[0], e[1] - s[1], function (b) {
  3453. var url = URL.createObjectURL(b);
  3454. var img = new Image();
  3455. img.onload = function () {
  3456. _windowsys.windowSys.addWindow(new _windowsys.GUIWindow("Resulting image", {
  3457. centerOnce: true,
  3458. closeable: true
  3459. }, function (win) {
  3460. var props = ['width', 'height'];
  3461. if (img.width > img.height) {
  3462. props.reverse();
  3463. }
  3464. var r = img[props[0]] / img[props[1]];
  3465. var shownSize = img[props[1]] >= 128 ? 256 : 128;
  3466. img[props[0]] = r * shownSize;
  3467. img[props[1]] = shownSize;
  3468. win.container.classList.add('centeredChilds');
  3469. var image = win.addObj(img);
  3470. (0, _misc.setTooltip)(img, "Right click to copy/save!");
  3471. /*var okButton = win.addObj(mkHTML("button", {
  3472. innerHTML: "OK",
  3473. style: "display: block; width: 80px; height: 30px; margin: auto;",
  3474. onclick: function() {
  3475. img.remove();
  3476. URL.revokeObjectURL(url);
  3477. win.getWindow().close();
  3478. }
  3479. }));*/
  3480. }));
  3481. };
  3482. img.src = url;
  3483. });
  3484. }
  3485. });
  3486. }));
  3487.  
  3488.  
  3489. addTool(new Tool('Fill', _tool_renderer.cursors.fill, _Fx.PLAYERFX.NONE, _conf.RANK.USER, function (tool) {
  3490. tool.extra.tickAmount = 6;
  3491. var queue = [];
  3492. var fillingColor = null;
  3493. var defaultFx = _Fx.PLAYERFX.RECT_SELECT_ALIGNED(1);
  3494. tool.setFxRenderer(function (fx, ctx, time) {
  3495. ctx.globalAlpha = 0.8;
  3496. ctx.strokeStyle = fx.extra.player.htmlRgb;
  3497. var z = _canvas_renderer.camera.zoom;
  3498. if (!fillingColor || !fx.extra.isLocalPlayer) {
  3499. defaultFx(fx, ctx, time);
  3500. } else {
  3501. ctx.beginPath();
  3502. for (var i = 0; i < queue.length; i++) {
  3503. ctx.rect((queue[i][0] - _canvas_renderer.camera.x) * z, (queue[i][1] - _canvas_renderer.camera.y) * z, z, z);
  3504. }
  3505. ctx.stroke();
  3506. }
  3507. });
  3508. function tick() {
  3509. var eq = function eq(a, b) {
  3510. return a && b && a[0] === b[0] && a[1] === b[1] && a[2] === b[2];
  3511. };
  3512. var check = function check(x, y) {
  3513. if (eq(_main.misc.world.getPixel(x, y), fillingColor)) {
  3514. queue.unshift([x, y]);
  3515. return true;
  3516. }
  3517. return false;
  3518. };
  3519.  
  3520. if (!queue.length || !fillingColor) {
  3521. return;
  3522. }
  3523.  
  3524. var selClr = _local_player.player.selectedColor;
  3525. var painted = 0;
  3526. var tickAmount = tool.extra.tickAmount;
  3527. for (var painted = 0; painted < tickAmount && queue.length; painted++) {
  3528. var current = queue.pop();
  3529. var x = current[0];
  3530. var y = current[1];
  3531. var thisClr = _main.misc.world.getPixel(x, y);
  3532. if (eq(thisClr, fillingColor) && !eq(thisClr, selClr)) {
  3533. if (!_main.misc.world.setPixel(x, y, selClr)) {
  3534. queue.push(current);
  3535. break;
  3536. }
  3537.  
  3538.  
  3539. var top = check(x, y - 1);
  3540. var bottom = check(x, y + 1);
  3541. var left = check(x - 1, y);
  3542. var right = check(x + 1, y);
  3543.  
  3544.  
  3545. if (top && left) {
  3546. check(x - 1, y - 1);
  3547. }
  3548. if (top && right) {
  3549. check(x + 1, y - 1);
  3550. }
  3551. if (bottom && left) {
  3552. check(x - 1, y + 1);
  3553. }
  3554. if (bottom && right) {
  3555. check(x + 1, y + 1);
  3556. }
  3557.  
  3558.  
  3559. /*check(x , y - 1);
  3560. check(x - 1, y );
  3561. check(x + 1, y );
  3562. check(x , y + 1);*/
  3563. }
  3564. }
  3565. }
  3566. tool.setEvent('mousedown', function (mouse) {
  3567. if (!(mouse.buttons & 4)) {
  3568. fillingColor = _main.misc.world.getPixel(mouse.tileX, mouse.tileY);
  3569. if (fillingColor) {
  3570. queue.push([mouse.tileX, mouse.tileY]);
  3571. tool.setEvent('tick', tick);
  3572. }
  3573. }
  3574. });
  3575. tool.setEvent('mouseup deselect', function (mouse) {
  3576. if (!mouse || !(mouse.buttons & 1)) {
  3577. fillingColor = null;
  3578. queue = [];
  3579. tool.setEvent('tick', null);
  3580. }
  3581. });
  3582. }));
  3583.  
  3584. addTool(new Tool('Line', _tool_renderer.cursors.wand, _Fx.PLAYERFX.NONE, _conf.RANK.USER, function (tool) {
  3585. var start = null;
  3586. var end = null;
  3587. var queue = [];
  3588. function line(x1, y1, x2, y2, plot) {
  3589. var dx = Math.abs(x2 - x1),
  3590. sx = x1 < x2 ? 1 : -1;
  3591. var dy = -Math.abs(y2 - y1),
  3592. sy = y1 < y2 ? 1 : -1;
  3593. var err = dx + dy,
  3594. e2;
  3595.  
  3596. while (true) {
  3597. plot(x1, y1);
  3598. if (x1 == x2 && y1 == y2) break;
  3599. e2 = 2 * err;
  3600. if (e2 >= dy) {
  3601. err += dy;x1 += sx;
  3602. }
  3603. if (e2 <= dx) {
  3604. err += dx;y1 += sy;
  3605. }
  3606. }
  3607. }
  3608. var defaultFx = _Fx.PLAYERFX.RECT_SELECT_ALIGNED(1);
  3609. tool.setFxRenderer(function (fx, ctx, time) {
  3610. ctx.globalAlpha = 0.8;
  3611. ctx.strokeStyle = fx.extra.player.htmlRgb;
  3612. var z = _canvas_renderer.camera.zoom;
  3613. if (!start || !end || !fx.extra.isLocalPlayer) {
  3614. defaultFx(fx, ctx, time);
  3615. } else {
  3616. ctx.beginPath();
  3617. line(start[0], start[1], end[0], end[1], function (x, y) {
  3618. ctx.rect((x - _canvas_renderer.camera.x) * _canvas_renderer.camera.zoom, (y - _canvas_renderer.camera.y) * _canvas_renderer.camera.zoom, _canvas_renderer.camera.zoom, _canvas_renderer.camera.zoom);
  3619. });
  3620. ctx.stroke();
  3621. }
  3622. });
  3623. function tick() {
  3624. for (var painted = 0; painted < 3 && queue.length; painted++) {
  3625. var current = queue.pop();
  3626. var c = _main.misc.world.getPixel(current[0], current[1]);
  3627. var pc = _local_player.player.selectedColor;
  3628. if ((c[0] != pc[0] || c[1] != pc[1] || c[2] != pc[2]) && !_main.misc.world.setPixel(current[0], current[1], _local_player.player.selectedColor)) {
  3629. queue.push(current);
  3630. break;
  3631. }
  3632. }
  3633. if (!queue.length) {
  3634. start = null;
  3635. end = null;
  3636. tool.setEvent('tick', null);
  3637. return;
  3638. }
  3639. }
  3640. tool.setEvent('mousedown', function (mouse) {
  3641. if (!(mouse.buttons & 4)) {
  3642. queue = [];
  3643. tool.setEvent('tick', null);
  3644. start = [mouse.tileX, mouse.tileY];
  3645. end = [mouse.tileX, mouse.tileY];
  3646. }
  3647. });
  3648. tool.setEvent('mousemove', function (mouse) {
  3649. if (!queue.length) {
  3650. end = [mouse.tileX, mouse.tileY];
  3651. }
  3652. });
  3653. tool.setEvent('mouseup', function (mouse) {
  3654. if (!(mouse.buttons & 3) && !queue.length) {
  3655. end = [mouse.tileX, mouse.tileY];
  3656. if (!start) {
  3657. end = null;
  3658. return;
  3659. }
  3660. if (_local_player.player.rank == _conf.RANK.ADMIN) {
  3661. line(start[0], start[1], end[0], end[1], function (x, y) {
  3662. _main.misc.world.setPixel(x, y, _local_player.player.selectedColor);
  3663. });
  3664. start = null;
  3665. end = null;
  3666. } else {
  3667. line(start[0], start[1], end[0], end[1], function (x, y) {
  3668. queue.push([x, y]);
  3669. });
  3670. tool.setEvent('tick', tick);
  3671. }
  3672. }
  3673. });
  3674. tool.setEvent('deselect', function (mouse) {
  3675. queue = [];
  3676. start = null;
  3677. end = null;
  3678. tool.setEvent('tick', null);
  3679. });
  3680. }));
  3681.  
  3682. addTool(new Tool('Protect', _tool_renderer.cursors.shield, _Fx.PLAYERFX.RECT_SELECT_ALIGNED(16, "#000000"), _conf.RANK.MODERATOR, function (tool) {
  3683. tool.setFxRenderer(function (fx, ctx, time) {
  3684. var x = fx.extra.player.x;
  3685. var y = fx.extra.player.y;
  3686. var fxx = (Math.floor(x / 256) * 16 - _canvas_renderer.camera.x) * _canvas_renderer.camera.zoom;
  3687. var fxy = (Math.floor(y / 256) * 16 - _canvas_renderer.camera.y) * _canvas_renderer.camera.zoom;
  3688. ctx.globalAlpha = 0.5;
  3689. var chunkX = Math.floor(fx.extra.player.tileX / _conf.protocol.chunkSize);
  3690. var chunkY = Math.floor(fx.extra.player.tileY / _conf.protocol.chunkSize);
  3691. var chunk = _main.misc.world.getChunkAt(chunkX, chunkY);
  3692. if (chunk) {
  3693. ctx.fillStyle = chunk.locked ? "#00FF00" : "#FF0000";
  3694. ctx.fillRect(fxx, fxy, _canvas_renderer.camera.zoom * 16, _canvas_renderer.camera.zoom * 16);
  3695. }
  3696. return 1; /* Rendering finished (won't change on next frame) */
  3697. });
  3698. tool.setEvent('mousedown mousemove', function (mouse) {
  3699. var chunkX = Math.floor(mouse.tileX / _conf.protocol.chunkSize);
  3700. var chunkY = Math.floor(mouse.tileY / _conf.protocol.chunkSize);
  3701. var chunk = _main.misc.world.getChunkAt(chunkX, chunkY);
  3702. switch (mouse.buttons) {
  3703. case 1:
  3704. if (!chunk.locked) {
  3705. _networking.net.protocol.protectChunk(chunkX, chunkY, 1);
  3706. }
  3707. break;
  3708.  
  3709. case 2:
  3710. if (chunk.locked) {
  3711. _networking.net.protocol.protectChunk(chunkX, chunkY, 0);
  3712. }
  3713. break;
  3714. }
  3715. });
  3716. }));
  3717.  
  3718. addTool(new Tool('Paste', _tool_renderer.cursors.paste, _Fx.PLAYERFX.NONE, _conf.RANK.ADMIN, function (tool) {
  3719. tool.setFxRenderer(function (fx, ctx, time) {
  3720. var z = _canvas_renderer.camera.zoom;
  3721. var x = fx.extra.player.x;
  3722. var y = fx.extra.player.y;
  3723. var fxx = Math.floor(x / 16) - _canvas_renderer.camera.x;
  3724. var fxy = Math.floor(y / 16) - _canvas_renderer.camera.y;
  3725. if (tool.extra.canvas && fx.extra.isLocalPlayer) {
  3726. ctx.globalAlpha = 0.5 + Math.sin(time / 500) / 4;
  3727. ctx.strokeStyle = "#000000";
  3728. ctx.scale(z, z);
  3729. ctx.drawImage(tool.extra.canvas, fxx, fxy);
  3730. ctx.scale(1 / z, 1 / z);
  3731. ctx.globalAlpha = 0.8;
  3732. ctx.strokeRect(fxx * z, fxy * z, tool.extra.canvas.width * z, tool.extra.canvas.height * z);
  3733. return 0;
  3734. }
  3735. });
  3736. var paint = function paint(tileX, tileY) {
  3737. var tmpBuffer = new Uint32Array(_conf.protocol.chunkSize * _conf.protocol.chunkSize);
  3738. var ctx = tool.extra.canvas.getContext("2d");
  3739. var dat = ctx.getImageData(0, 0, tool.extra.canvas.width, tool.extra.canvas.height);
  3740. var u32dat = new Uint32Array(dat.data.buffer);
  3741. var totalChunksW = Math.ceil(((0, _misc.absMod)(tileX, _conf.protocol.chunkSize) + dat.width) / _conf.protocol.chunkSize);
  3742. var totalChunksH = Math.ceil(((0, _misc.absMod)(tileY, _conf.protocol.chunkSize) + dat.height) / _conf.protocol.chunkSize);
  3743. var getModifiedPixel = function getModifiedPixel(x, y) {
  3744. var imgY = y - tileY;
  3745. var imgX = x - tileX;
  3746. if (imgY < 0 || imgX < 0 || imgY >= dat.height || imgX >= dat.width) {
  3747. var currentPixel = _main.misc.world.getPixel(x, y);
  3748. return currentPixel ? currentPixel[2] << 16 | currentPixel[1] << 8 | currentPixel[0] : null;
  3749. }
  3750. var img = u32dat[imgY * dat.width + imgX];
  3751. var oldPixel = _main.misc.world.getPixel(x, y);
  3752. var alpha = img >> 24 & 0xFF;
  3753. if (!oldPixel) {
  3754. return null;
  3755. }
  3756. var r = (1 - alpha / 255) * oldPixel[0] + alpha / 255 * (img & 0xFF);
  3757. var g = (1 - alpha / 255) * oldPixel[1] + alpha / 255 * (img >> 8 & 0xFF);
  3758. var b = (1 - alpha / 255) * oldPixel[2] + alpha / 255 * (img >> 16 & 0xFF);
  3759. var rgb = b << 16 | g << 8 | r;
  3760. return r == oldPixel[0] && g == oldPixel[1] && b == oldPixel[2] ? rgb : 0xFF000000 | rgb;
  3761. };
  3762. var getModifiedChunk = function getModifiedChunk(chunkX, chunkY) {
  3763. var modified = 0;
  3764. var offX = chunkX * _conf.protocol.chunkSize;
  3765. var offY = chunkY * _conf.protocol.chunkSize;
  3766. for (var y = 0; y < _conf.protocol.chunkSize; y++) {
  3767. for (var x = 0; x < _conf.protocol.chunkSize; x++) {
  3768. var color = getModifiedPixel(x + offX, y + offY);
  3769. if (color !== null) {
  3770. if (color & 0xFF000000) {
  3771. ++modified;
  3772. }
  3773. tmpBuffer[y * _conf.protocol.chunkSize + x] = color & 0xFFFFFF;
  3774. } else {
  3775. /* Chunk not loaded... */
  3776. throw new Error('Couldn\'t paste -- chunk (' + chunkX + ', ' + chunkY + ') is unloaded');
  3777. }
  3778. }
  3779. }
  3780. return modified ? tmpBuffer : null;
  3781. };
  3782. if (!_networking.net.protocol.setChunk) {
  3783. throw new Error("Protocol doesn't support pasting");
  3784. }
  3785. for (var y = Math.floor(tileY / _conf.protocol.chunkSize), t = totalChunksH; --t >= 0; y++) {
  3786. for (var x = Math.floor(tileX / _conf.protocol.chunkSize), tw = totalChunksW; --tw >= 0; x++) {
  3787. var newChunk = getModifiedChunk(x, y);
  3788. if (newChunk) {
  3789. _networking.net.protocol.setChunk(x, y, newChunk);
  3790. }
  3791. }
  3792. }
  3793. };
  3794.  
  3795. tool.setEvent('mousedown', function (mouse) {
  3796. if (!(mouse.buttons & 4)) {
  3797. if (tool.extra.canvas) {
  3798. paint(mouse.tileX, mouse.tileY);
  3799. }
  3800. }
  3801. });
  3802.  
  3803. var input = document.createElement("input");
  3804. input.type = "file";
  3805. input.accept = "image/*";
  3806. tool.setEvent('select', function () {
  3807. input.onchange = function (event) {
  3808. if (input.files && input.files[0]) {
  3809. var reader = new FileReader();
  3810. reader.onload = function (e) {
  3811. var image = new Image();
  3812. image.onload = function () {
  3813. tool.extra.canvas = document.createElement("canvas");
  3814. tool.extra.canvas.width = image.width;
  3815. tool.extra.canvas.height = image.height;
  3816. var ctx = tool.extra.canvas.getContext("2d");
  3817. ctx.drawImage(image, 0, 0);
  3818. console.log('Loaded image');
  3819. };
  3820. image.src = e.target.result;
  3821. };
  3822. reader.readAsDataURL(input.files[0]);
  3823. }
  3824. };
  3825. input.click();
  3826. });
  3827. }));
  3828.  
  3829. _global.eventSys.emit(_conf.EVENTS.misc.toolsInitialized);
  3830. });
  3831.  
  3832. _global.eventSys.once(_conf.EVENTS.init, function () {
  3833. exports.toolsWindow = toolsWindow = new _windowsys.GUIWindow('Tools', {}, function (wdow) {
  3834. wdow.container.id = "toole-container";
  3835. wdow.container.style.cssText = "max-width: 40px";
  3836. }).move(5, 32);
  3837. });
  3838.  
  3839. _global.eventSys.once(_conf.EVENTS.misc.toolsInitialized, function () {
  3840. updateToolbar();
  3841. if (windowShown) {
  3842. _windowsys.windowSys.addWindow(toolsWindow);
  3843. }
  3844. });
  3845.  
  3846. _global.eventSys.on(_conf.EVENTS.net.disconnected, function () {
  3847. showToolsWindow(false);
  3848. });
  3849.  
  3850. _global.eventSys.on(_conf.EVENTS.misc.worldInitialized, function () {
  3851. showToolsWindow(true);
  3852. });
  3853.  
  3854. /***/ }),
  3855. /* 11 */
  3856. /***/ (function(module, exports, __webpack_require__) {
  3857.  
  3858. "use strict";
  3859.  
  3860.  
  3861. Object.defineProperty(exports, "__esModule", {
  3862. value: true
  3863. });
  3864. exports.windowSys = undefined;
  3865. exports.UtilInput = UtilInput;
  3866. exports.UtilDialog = UtilDialog;
  3867. exports.OWOPDropDown = OWOPDropDown;
  3868. exports.GUIWindow = GUIWindow;
  3869. exports.addWindow = addWindow;
  3870. exports.delWindow = delWindow;
  3871. exports.centerWindow = centerWindow;
  3872.  
  3873. var _main = __webpack_require__(3);
  3874.  
  3875. var _conf = __webpack_require__(1);
  3876.  
  3877. var _global = __webpack_require__(0);
  3878.  
  3879. var _misc = __webpack_require__(2);
  3880.  
  3881. var windowSys = exports.windowSys = {
  3882. windows: {},
  3883. class: {
  3884. input: UtilInput,
  3885. dialog: UtilDialog,
  3886. dropDown: OWOPDropDown,
  3887. window: GUIWindow
  3888. },
  3889. addWindow: addWindow,
  3890. delWindow: delWindow,
  3891. centerWindow: centerWindow
  3892. };
  3893.  
  3894. _global.PublicAPI.windowSys = windowSys;
  3895.  
  3896. function UtilInput(title, message, inputType, cb) {
  3897. this.win = new GUIWindow(title, {
  3898. centerOnce: true,
  3899. closeable: true
  3900. }, function (win) {
  3901. this.inputField = win.addObj((0, _misc.mkHTML)("input", {
  3902. style: "width: 100%; height: 50%;",
  3903. type: inputType,
  3904. placeholder: message,
  3905. onkeyup: function (e) {
  3906. if ((e.which || e.keyCode) == 13) {
  3907. this.okButton.click();
  3908. }
  3909. }.bind(this)
  3910. }));
  3911. this.okButton = win.addObj((0, _misc.mkHTML)("button", {
  3912. innerHTML: "OK",
  3913. style: "width: 100%; height: 50%;",
  3914. onclick: function () {
  3915. cb(this.inputField.value);
  3916. this.getWindow().close();
  3917. }.bind(this)
  3918. }));
  3919. }.bind(this)).resize(200, 60);
  3920. }
  3921.  
  3922. UtilInput.prototype.getWindow = function () {
  3923. return this.win;
  3924. };
  3925.  
  3926. function UtilDialog(title, message, canClose, cb) {
  3927. this.win = new GUIWindow(title, {
  3928. centered: true,
  3929. closeable: canClose
  3930. }, function (win) {
  3931. this.messageBox = win.addObj((0, _misc.mkHTML)("span", {
  3932. className: "whitetext",
  3933. style: "display: block; padding-bottom: 4px;",
  3934. innerHTML: message
  3935. }));
  3936. this.okButton = win.addObj((0, _misc.mkHTML)("button", {
  3937. innerHTML: "OK",
  3938. style: "display: block; width: 80px; height: 30px; margin: auto;",
  3939. onclick: function () {
  3940. cb();
  3941. this.getWindow().close();
  3942. }.bind(this)
  3943. }));
  3944. }.bind(this));
  3945. }
  3946.  
  3947. UtilDialog.prototype.getWindow = function () {
  3948. return this.win;
  3949. };
  3950.  
  3951. /* Highly specific purpose, should only be created once */
  3952. function OWOPDropDown() {
  3953. this.win = new GUIWindow(null, {
  3954. immobile: true
  3955. }, function (win) {
  3956. win.frame.className = "owopdropdown";
  3957. win.container.style.cssText = "border: none;\
  3958. background-color: initial;\
  3959. pointer-events: none;\
  3960. margin: 0;";
  3961. var hlpdiv = win.addObj((0, _misc.mkHTML)("div", {
  3962. className: "winframe",
  3963. style: "padding: 0;\
  3964. width: 68px; height: 64px;"
  3965. }));
  3966. var hidebtn = win.addObj((0, _misc.mkHTML)("button", {
  3967. innerHTML: 'hi'
  3968. /*className: "winframe",
  3969. style: "padding: 0;\
  3970. background-color: #ffd162;\
  3971. left: -6px; top: 70px;\
  3972. width: 38px; height: 36px;"*/
  3973. }));
  3974. /*var rddtbtn = win.addObj(mkHTML("button", {
  3975. className: "winframe",
  3976. style: "padding: 0;\
  3977. right: -6px; top: 70px;\
  3978. width: 38px; height: 36px;"
  3979. }));*/
  3980. var hlpcontainer = (0, _misc.mkHTML)("div", {
  3981. className: "wincontainer",
  3982. style: "margin-top: -5px;"
  3983. });
  3984. hlpdiv.appendChild(hlpcontainer);
  3985. hlpcontainer.appendChild((0, _misc.mkHTML)("button", {
  3986. style: "background-image: url(img/gui.png);\
  3987. background-position: -64px 4px;\
  3988. background-origin: border-box;\
  3989. background-repeat: no-repeat;\
  3990. width: 100%; height: 100%;",
  3991. onclick: function () {
  3992. console.log("help");
  3993. }.bind(this)
  3994. }));
  3995. }).resize(68, 64);
  3996. }
  3997.  
  3998. OWOPDropDown.prototype.getWindow = function () {
  3999. return this.win;
  4000. };
  4001.  
  4002. /* wm = WindowManager object
  4003. * initfunc = function where all the windows objects should be added,
  4004. * first function argument is the guiwindow object itself
  4005. */
  4006. function GUIWindow(title, options, initfunc) {
  4007. var _this = this;
  4008.  
  4009. options = options || {};
  4010. this.wm = WorldOfPixels.windowsys;
  4011. this.opt = options;
  4012. this.title = title;
  4013. this.frame = document.createElement("div");
  4014. this.container = document.createElement("div");
  4015. this.container.className = 'wincontainer';
  4016.  
  4017. if (title) {
  4018. this.titlespan = document.createElement("span");
  4019. this.titlespan.innerHTML = title;
  4020.  
  4021. this.frame.appendChild(this.titlespan);
  4022. }
  4023.  
  4024. this.frame.appendChild(this.container);
  4025.  
  4026. if (options.centered) {
  4027. options.immobile = true;
  4028. this.frame.className = "centered";
  4029. }
  4030.  
  4031. Object.defineProperty(this, "realw", {
  4032. get: function () {
  4033. return this.frame.offsetWidth;
  4034. }.bind(this)
  4035. });
  4036. Object.defineProperty(this, "realh", {
  4037. get: function () {
  4038. return this.frame.offsetHeight;
  4039. }.bind(this)
  4040. });
  4041.  
  4042. this.elements = [];
  4043.  
  4044. this.creationtime = Date.now();
  4045. this.currentaction = null; /* Func to call every mousemove evt */
  4046.  
  4047. if (initfunc) {
  4048. initfunc(this);
  4049. }
  4050.  
  4051. this.mdownfunc = function (e) {
  4052. var offx = e.clientX - this.x;
  4053. var offy = e.clientY - this.y;
  4054. if (e.target === this.frame && !this.opt.immobile) {
  4055. this.currentaction = function (x, y) {
  4056. x = x <= 0 ? 0 : x > window.innerWidth ? window.innerWidth : x;
  4057. y = y <= 0 ? 0 : y > window.innerHeight ? window.innerHeight : y;
  4058. this.move(x - offx, y - offy);
  4059. };
  4060. }
  4061. }.bind(this);
  4062.  
  4063. if (options.centerOnce) {
  4064. /* Ugly solution to wait for offset(Height, Width) values to be available */
  4065. this.move(window.innerWidth, window.innerHeight); /* Hide the window */
  4066. (0, _misc.waitFrames)(2, function () {
  4067. return centerWindow(_this);
  4068. });
  4069. }
  4070.  
  4071. this.frame.addEventListener("mousedown", this.mdownfunc);
  4072.  
  4073. this.mupfunc = function (e) {
  4074. this.currentaction = null;
  4075. }.bind(this);
  4076.  
  4077. window.addEventListener("mouseup", this.mupfunc);
  4078.  
  4079. this.mmovefunc = function (e) {
  4080. if (this.currentaction) {
  4081. this.currentaction(e.clientX, e.clientY);
  4082. }
  4083. }.bind(this);
  4084.  
  4085. window.addEventListener("mousemove", this.mmovefunc);
  4086.  
  4087. if (options.closeable) {
  4088. this.frame.appendChild((0, _misc.mkHTML)("button", {
  4089. onclick: function () {
  4090. this.close();
  4091. }.bind(this),
  4092. className: 'windowCloseButton'
  4093. }));
  4094. }
  4095. }
  4096.  
  4097. GUIWindow.prototype.getWindow = function () {
  4098. return this;
  4099. };
  4100.  
  4101. GUIWindow.prototype.addObj = function (object) {
  4102. this.elements.push(object);
  4103. this.container.appendChild(object);
  4104. return object;
  4105. };
  4106.  
  4107. GUIWindow.prototype.delObj = function (object) {
  4108. var i = this.elements.indexOf(object);
  4109. if (i != -1) {
  4110. this.elements.splice(i, 1);
  4111. this.container.removeChild(object);
  4112. }
  4113. };
  4114.  
  4115. GUIWindow.prototype.move = function (x, y) {
  4116. if (!this.opt.immobile) {
  4117. this.frame.style.transform = "translate(" + x + "px," + y + "px)";
  4118. this.x = x;
  4119. this.y = y;
  4120. }
  4121. return this;
  4122. };
  4123.  
  4124. GUIWindow.prototype.resize = function (w, h) {
  4125. this.w = w;
  4126. this.h = h;
  4127. this.container.style.width = w + "px";
  4128. this.container.style.height = h + "px";
  4129. return this;
  4130. };
  4131.  
  4132. GUIWindow.prototype.close = function () {
  4133. delWindow(this);
  4134. window.removeEventListener("mousemove", this.mmovefunc);
  4135. window.removeEventListener("mouseup", this.mupfunc);
  4136. this.frame.removeEventListener("mousedown", this.mdownfunc);
  4137. if (this.onclose) {
  4138. this.onclose();
  4139. }
  4140. };
  4141.  
  4142. /* Window X/Y is specified on window.x, window.y */
  4143. function addWindow(window) {
  4144. var realWindow = window.getWindow();
  4145. if (!windowSys.windows[realWindow.title]) {
  4146. _main.elements.windows.appendChild(realWindow.frame);
  4147. windowSys.windows[realWindow.title] = realWindow;
  4148. }
  4149. _global.eventSys.emit(_conf.EVENTS.misc.windowAdded, window);
  4150. return window;
  4151. }
  4152.  
  4153. function delWindow(window) {
  4154. var realWindow = window.getWindow();
  4155. if (windowSys.windows[realWindow.title]) {
  4156. _main.elements.windows.removeChild(realWindow.frame);
  4157. delete windowSys.windows[realWindow.title];
  4158. }
  4159. return window;
  4160. }
  4161.  
  4162. function centerWindow(win) {
  4163. win = win.getWindow();
  4164. win.move(window.innerWidth / 2 - win.realw / 2 | 0, window.innerHeight / 2 - win.realh / 2 | 0);
  4165. }
  4166.  
  4167. /***/ }),
  4168. /* 12 */
  4169. /***/ (function(module, exports, __webpack_require__) {
  4170.  
  4171. "use strict";
  4172.  
  4173.  
  4174. Object.defineProperty(exports, "__esModule", {
  4175. value: true
  4176. });
  4177. exports.World = exports.Chunk = undefined;
  4178.  
  4179. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  4180.  
  4181. var _conf = __webpack_require__(1);
  4182.  
  4183. var _global = __webpack_require__(0);
  4184.  
  4185. var _color = __webpack_require__(4);
  4186.  
  4187. var _networking = __webpack_require__(8);
  4188.  
  4189. var _canvas_renderer = __webpack_require__(5);
  4190.  
  4191. var _main = __webpack_require__(3);
  4192.  
  4193. var _local_player = __webpack_require__(6);
  4194.  
  4195. var _Player = __webpack_require__(20);
  4196.  
  4197. var _Fx = __webpack_require__(7);
  4198.  
  4199. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  4200.  
  4201. var lastPlace = 0;
  4202.  
  4203. var Chunk = exports.Chunk = function () {
  4204. function Chunk(x, y, netdata, locked) {
  4205. _classCallCheck(this, Chunk);
  4206.  
  4207. /* netdata = Uint32Array */
  4208. this.needsRedraw = false;
  4209. this.x = x;
  4210. this.y = y;
  4211. this.tmpChunkBuf = netdata;
  4212. this.view = null;
  4213. this.locked = locked;
  4214. this.lockedNeighbors = 0; /* Up, Right, Down, Left */
  4215. }
  4216.  
  4217. _createClass(Chunk, [{
  4218. key: 'update',
  4219. value: function update(x, y, color) {
  4220. /* WARNING: Should absMod if not power of two */
  4221. x &= _conf.protocol.chunkSize - 1;
  4222. y &= _conf.protocol.chunkSize - 1;
  4223. this.view.set(x, y, 0xFF000000 | color);
  4224. this.needsRedraw = true;
  4225. }
  4226. }, {
  4227. key: 'get',
  4228. value: function get(x, y) {
  4229. x &= _conf.protocol.chunkSize - 1;
  4230. y &= _conf.protocol.chunkSize - 1;
  4231. return this.view.get(x, y);
  4232. }
  4233. }, {
  4234. key: 'set',
  4235. value: function set(data) {
  4236. if (Number.isInteger(data)) {
  4237. this.view.fill(0xFF000000 | data);
  4238. } else {
  4239. this.view.fillFromBuf(data);
  4240. }
  4241. this.needsRedraw = true;
  4242. }
  4243. }, {
  4244. key: 'remove',
  4245. value: function remove() {
  4246. /* Can be called when manually unloading too */
  4247. _global.eventSys.emit(_conf.EVENTS.net.chunk.unload, this);
  4248. }
  4249. }]);
  4250.  
  4251. return Chunk;
  4252. }();
  4253.  
  4254. Chunk.dir = {
  4255. UP: 8,
  4256. RIGHT: 4,
  4257. DOWN: 2,
  4258. LEFT: 1
  4259. };
  4260.  
  4261. var World = exports.World = function () {
  4262. function World(worldName) {
  4263. var _this = this;
  4264.  
  4265. _classCallCheck(this, World);
  4266.  
  4267. this.name = worldName;
  4268. this.chunks = {};
  4269. this.protectedChunks = {};
  4270. this.players = {};
  4271. this.undoHistory = [];
  4272. this.pathUpdaterTimeout = -1;
  4273. this.pathFx = new _Fx.Fx(function (fx, ctx, time) {
  4274. var retval = 1;
  4275. if (fx.extra.path) {
  4276. ctx.strokeStyle = "#525252";
  4277. var l = ctx.lineWidth;
  4278. ctx.lineWidth = 3 / _canvas_renderer.camera.zoom;
  4279. ctx.setTransform(_canvas_renderer.camera.zoom, 0, 0, _canvas_renderer.camera.zoom, -_canvas_renderer.camera.x * _canvas_renderer.camera.zoom, -_canvas_renderer.camera.y * _canvas_renderer.camera.zoom);
  4280. if (time - fx.extra.placeTime < 1500) {
  4281. ctx.globalAlpha = (1 - (time - fx.extra.placeTime) / 1500) * 0.5;
  4282. ctx.fillStyle = _canvas_renderer.renderer.patterns.unloaded;
  4283. ctx.fill(fx.extra.path);
  4284. retval = 0;
  4285. }
  4286. ctx.globalAlpha = 0.75;
  4287. ctx.stroke(fx.extra.path);
  4288. ctx.setTransform(1, 0, 0, 1, 0, 0);
  4289. ctx.lineWidth = l;
  4290. }
  4291. return retval;
  4292. });
  4293.  
  4294. var loadCFunc = function loadCFunc(chunk) {
  4295. return _this.chunkLoaded(chunk);
  4296. };
  4297. var unloadCFunc = function unloadCFunc(chunk) {
  4298. return _this.chunkUnloaded(chunk);
  4299. };
  4300. var setCFunc = function setCFunc(x, y, data) {
  4301. return _this.chunkPasted(x, y, data);
  4302. };
  4303. var lockCFunc = function lockCFunc(x, y, newState) {
  4304. return _this.chunkLocked(x, y, newState);
  4305. };
  4306. var disconnectedFunc = function disconnectedFunc() {
  4307. return _global.eventSys.emit(_conf.EVENTS.net.world.leave);
  4308. };
  4309. var updateTileFunc = function updateTileFunc(t) {
  4310. return _this.tilesUpdated(t);
  4311. };
  4312. var updatePlayerFunc = function updatePlayerFunc(p) {
  4313. return _this.playersMoved(p);
  4314. };
  4315. var destroyPlayerFunc = function destroyPlayerFunc(p) {
  4316. return _this.playersLeft(p);
  4317. };
  4318. var leaveWFunc = function leaveWFunc() {
  4319. _this.pathFx.delete();
  4320. _this.unloadAllChunks();
  4321. _this.playersLeft(Object.keys(_this.players));
  4322. _global.eventSys.removeListener(_conf.EVENTS.net.chunk.load, loadCFunc);
  4323. _global.eventSys.removeListener(_conf.EVENTS.net.chunk.unload, unloadCFunc);
  4324. _global.eventSys.removeListener(_conf.EVENTS.net.chunk.set, setCFunc);
  4325. _global.eventSys.removeListener(_conf.EVENTS.net.chunk.lock, lockCFunc);
  4326. _global.eventSys.removeListener(_conf.EVENTS.net.disconnected, disconnectedFunc);
  4327. _global.eventSys.removeListener(_conf.EVENTS.net.world.tilesUpdated, updateTileFunc);
  4328. _global.eventSys.removeListener(_conf.EVENTS.net.world.playersMoved, updatePlayerFunc);
  4329. _global.eventSys.removeListener(_conf.EVENTS.net.world.playersLeft, destroyPlayerFunc);
  4330. };
  4331. _global.eventSys.on(_conf.EVENTS.net.chunk.load, loadCFunc);
  4332. _global.eventSys.on(_conf.EVENTS.net.chunk.unload, unloadCFunc);
  4333. _global.eventSys.on(_conf.EVENTS.net.chunk.set, setCFunc);
  4334. _global.eventSys.on(_conf.EVENTS.net.chunk.lock, lockCFunc);
  4335. _global.eventSys.on(_conf.EVENTS.net.world.tilesUpdated, updateTileFunc);
  4336. _global.eventSys.on(_conf.EVENTS.net.world.playersMoved, updatePlayerFunc);
  4337. _global.eventSys.on(_conf.EVENTS.net.world.playersLeft, destroyPlayerFunc);
  4338. _global.eventSys.once(_conf.EVENTS.net.world.leave, leaveWFunc);
  4339. _global.eventSys.once(_conf.EVENTS.net.disconnected, disconnectedFunc);
  4340. }
  4341.  
  4342. _createClass(World, [{
  4343. key: 'makeLockedChunksPath',
  4344. value: function makeLockedChunksPath() {
  4345. var d = Chunk.dir;
  4346. var mainPath = new Path2D();
  4347.  
  4348. var vpoints = {};
  4349. var hpoints = {};
  4350.  
  4351. var addPoint = function addPoint(fx, fy, tx, ty, points) {
  4352. var fkey = fx + ',' + fy;
  4353. var tkey = tx + ',' + ty;
  4354. if (tkey in points && fkey in points) {
  4355. points[points[fkey]] = points[tkey];
  4356. points[points[tkey]] = points[fkey];
  4357. delete points[tkey];
  4358. delete points[fkey];
  4359. } else if (tkey in points) {
  4360. var newTo = points[tkey];
  4361. points[newTo] = fkey;
  4362. delete points[tkey];
  4363. points[fkey] = newTo;
  4364. } else if (fkey in points) {
  4365. var newFrom = points[fkey];
  4366. points[newFrom] = tkey;
  4367. delete points[fkey];
  4368. points[tkey] = newFrom;
  4369. } else {
  4370. points[fkey] = tkey;
  4371. points[tkey] = fkey;
  4372. }
  4373. };
  4374.  
  4375. for (var k in this.protectedChunks) {
  4376. var chunk = this.protectedChunks[k];
  4377. var ln = chunk.lockedNeighbors;
  4378. if (ln === (d.LEFT | d.DOWN | d.UP | d.RIGHT)) {
  4379. continue;
  4380. }
  4381.  
  4382. if (!(ln & d.UP)) {
  4383. addPoint(chunk.x + 1, chunk.y, chunk.x, chunk.y, hpoints);
  4384. }
  4385. if (!(ln & d.DOWN)) {
  4386. addPoint(chunk.x, chunk.y + 1, chunk.x + 1, chunk.y + 1, hpoints);
  4387. }
  4388.  
  4389. if (!(ln & d.LEFT)) {
  4390. addPoint(chunk.x, chunk.y + 1, chunk.x, chunk.y, vpoints);
  4391. }
  4392. if (!(ln & d.RIGHT)) {
  4393. addPoint(chunk.x + 1, chunk.y + 1, chunk.x + 1, chunk.y, vpoints);
  4394. }
  4395. }
  4396.  
  4397. var polys = 0;
  4398. var pointobjs = [vpoints, hpoints];
  4399. for (var p in vpoints) {
  4400. var a = p.split(',');
  4401. mainPath.moveTo(a[0] * 16, a[1] * 16);
  4402.  
  4403. delete vpoints[vpoints[p]];
  4404. delete vpoints[p];
  4405. p = hpoints[p];
  4406. for (var i = 0; p && (a = p.split(',')); i++) {
  4407. var prev = pointobjs[i + 1 & 1];
  4408. var next = pointobjs[i & 1];
  4409. mainPath.lineTo(a[0] * 16, a[1] * 16);
  4410.  
  4411. delete prev[prev[p]];
  4412. delete prev[p];
  4413. p = next[p];
  4414. }
  4415. mainPath.closePath();
  4416. ++polys;
  4417. }
  4418.  
  4419. return polys === 0 ? null : mainPath;
  4420. }
  4421. }, {
  4422. key: 'findNeighborLockedChunks',
  4423. value: function findNeighborLockedChunks(chunk, newState) {
  4424. var _this2 = this;
  4425.  
  4426. var d = Chunk.dir;
  4427. var checkSide = function checkSide(x, y, to, from) {
  4428. var sidec = _this2.getChunkAt(chunk.x + x, chunk.y + y);
  4429. if (sidec && sidec.locked) {
  4430. if (newState) {
  4431. chunk.lockedNeighbors |= to;
  4432. sidec.lockedNeighbors |= from;
  4433. } else {
  4434. chunk.lockedNeighbors &= ~to;
  4435. sidec.lockedNeighbors &= ~from;
  4436. }
  4437. }
  4438. };
  4439.  
  4440. checkSide(0, -1, d.UP, d.DOWN);
  4441. checkSide(1, 0, d.RIGHT, d.LEFT);
  4442. checkSide(-1, 0, d.LEFT, d.RIGHT);
  4443. checkSide(0, 1, d.DOWN, d.UP);
  4444.  
  4445. clearTimeout(this.pathUpdaterTimeout);
  4446. this.pathUpdaterTimeout = setTimeout(function () {
  4447. _this2.pathFx.update({ path: _this2.makeLockedChunksPath() });
  4448. _canvas_renderer.renderer.render(_canvas_renderer.renderer.rendertype.FX);
  4449. }, 100);
  4450. }
  4451. }, {
  4452. key: 'loadChunk',
  4453. value: function loadChunk(x, y) {
  4454. var key = x + ',' + y;
  4455. if (!this.chunks[key] && _networking.net.isConnected()) {
  4456. _networking.net.protocol.requestChunk(x, y);
  4457. }
  4458. }
  4459. }, {
  4460. key: 'allChunksLoaded',
  4461. value: function allChunksLoaded() {
  4462. return _networking.net.protocol.allChunksLoaded();
  4463. }
  4464. }, {
  4465. key: 'tilesUpdated',
  4466. value: function tilesUpdated(tiles) {
  4467. var chunksUpdated = {};
  4468. var chunkSize = _conf.protocol.chunkSize;
  4469. for (var i = 0; i < tiles.length; i++) {
  4470. var t = tiles[i];
  4471. var key = Math.floor(t.x / chunkSize) + ',' + Math.floor(t.y / chunkSize);
  4472. var chunk = this.chunks[key];
  4473. if (chunk) {
  4474. chunksUpdated[key] = chunk;
  4475. chunk.update(t.x, t.y, t.rgb);
  4476. }
  4477. }
  4478. for (var c in chunksUpdated) {
  4479. _global.eventSys.emit(_conf.EVENTS.renderer.updateChunk, chunksUpdated[c]);
  4480. }
  4481. }
  4482. }, {
  4483. key: 'playersMoved',
  4484. value: function playersMoved(players) {
  4485. var rendered = false;
  4486. for (var id in players) {
  4487. var player = this.players[id];
  4488. var u = players[id];
  4489. if (player) {
  4490. player.update(u.x, u.y, u.rgb, u.tool);
  4491. } else {
  4492. player = this.players[id] = new _Player.Player(u.x, u.y, u.rgb, u.tool, id);
  4493. }
  4494. if (!rendered && ((0, _canvas_renderer.isVisible)(player.endX / 16, player.endY / 16, 4, 4) || (0, _canvas_renderer.isVisible)(player.x / 16, player.y / 16, 4, 4))) {
  4495. rendered = true;
  4496. _canvas_renderer.renderer.render(_canvas_renderer.renderer.rendertype.FX);
  4497. }
  4498. }
  4499. }
  4500. }, {
  4501. key: 'playersLeft',
  4502. value: function playersLeft(ids) {
  4503. var rendered = false;
  4504. for (var i = 0; i < ids.length; i++) {
  4505. var id = ids[i];
  4506. var player = this.players[id];
  4507. if (player) {
  4508. player.disconnect();
  4509. if (!rendered && (0, _canvas_renderer.isVisible)(player.x / 16, player.y / 16, 4, 4)) {
  4510. rendered = true;
  4511. _canvas_renderer.renderer.render(_canvas_renderer.renderer.rendertype.FX);
  4512. }
  4513. }
  4514. delete this.players[id];
  4515. }
  4516. }
  4517. }, {
  4518. key: 'setPixel',
  4519. value: function setPixel(x, y, color, noUndo) {
  4520. var time = Date.now();
  4521. var chunkSize = _conf.protocol.chunkSize;
  4522. var chunk = this.chunks[Math.floor(x / chunkSize) + ',' + Math.floor(y / chunkSize)];
  4523. if (chunk && (!chunk.locked || _local_player.player.rank >= _conf.RANK.MODERATOR)) {
  4524. var oldPixel = this.getPixel(x, y, chunk);
  4525. if (!oldPixel || oldPixel[0] === color[0] && oldPixel[1] === color[1] && oldPixel[2] === color[2] || !_networking.net.protocol.updatePixel(x, y, color)) {
  4526. return false;
  4527. }
  4528. if (!noUndo) {
  4529. oldPixel.push(x, y, time);
  4530. this.undoHistory.push(oldPixel);
  4531. }
  4532. chunk.update(x, y, _color.colorUtils.u24_888(color[0], color[1], color[2]));
  4533. _global.eventSys.emit(_conf.EVENTS.renderer.updateChunk, chunk);
  4534. if (time - lastPlace > 30) {
  4535. _main.sounds.play(_main.sounds.place);
  4536. lastPlace = time;
  4537. }
  4538. return true;
  4539. } else if (chunk && chunk.locked) {
  4540. this.pathFx.extra.placeTime = time;
  4541. _canvas_renderer.renderer.render(_canvas_renderer.renderer.rendertype.FX);
  4542. }
  4543. return false;
  4544. }
  4545. }, {
  4546. key: 'undo',
  4547. value: function undo(bulkUndo) {
  4548. var eq = function eq(a, b) {
  4549. return a[0] == b[0] && a[1] == b[1] && a[2] == b[2];
  4550. };
  4551. if (this.undoHistory.length === 0) {
  4552. return false;
  4553. }
  4554. var changeTime = null;
  4555. for (var i = this.undoHistory.length; --i >= 0;) {
  4556. var undo = this.undoHistory[i];
  4557. if (!changeTime) {
  4558. changeTime = undo[5];
  4559. }
  4560. var px = this.getPixel(undo[3], undo[4]);
  4561. if (px) {
  4562. var shouldContinue = !bulkUndo || changeTime - undo[5] < 500;
  4563. var unchanged = eq(px, undo);
  4564. if (!shouldContinue) {
  4565. break;
  4566. }
  4567. if (unchanged || this.setPixel(undo[3], undo[4], undo, true)) {
  4568. this.undoHistory.splice(i, 1);
  4569. if (!bulkUndo) {
  4570. break;
  4571. }
  4572. }
  4573. }
  4574. }
  4575. }
  4576. }, {
  4577. key: 'getChunkAt',
  4578. value: function getChunkAt(x, y) {
  4579. return this.chunks[x + ',' + y];
  4580. }
  4581. }, {
  4582. key: 'getPixel',
  4583. value: function getPixel(x, y, chunk) {
  4584. if (!chunk) {
  4585. var chunkSize = _conf.protocol.chunkSize;
  4586. chunk = this.chunks[Math.floor(x / chunkSize) + ',' + Math.floor(y / chunkSize)];
  4587. }
  4588.  
  4589. if (chunk) {
  4590. var clr = chunk.get(x, y);
  4591. return [clr & 0xFF, clr >> 8 & 0xFF, clr >> 16 & 0xFF];
  4592. }
  4593. return null;
  4594. }
  4595. }, {
  4596. key: 'validMousePos',
  4597. value: function validMousePos(tileX, tileY) {
  4598. return this.getPixel(tileX, tileY) !== null;
  4599. }
  4600. }, {
  4601. key: 'chunkLocked',
  4602. value: function chunkLocked(x, y, newState) {
  4603. var key = x + ',' + y;
  4604. var chunk = this.getChunkAt(x, y);
  4605. if (chunk) {
  4606. if (newState) {
  4607. this.protectedChunks[key] = chunk;
  4608. chunk.locked = true;
  4609. } else {
  4610. delete this.protectedChunks[key];
  4611. chunk.locked = false;
  4612. }
  4613. this.findNeighborLockedChunks(chunk, newState);
  4614. }
  4615. }
  4616. }, {
  4617. key: 'chunkLoaded',
  4618. value: function chunkLoaded(chunk) {
  4619. var key = chunk.x + ',' + chunk.y;
  4620. this.chunks[key] = chunk;
  4621. if (chunk.locked) {
  4622. this.protectedChunks[key] = chunk;
  4623. this.findNeighborLockedChunks(chunk, chunk.locked);
  4624. }
  4625. _global.eventSys.emit(_conf.EVENTS.renderer.addChunk, chunk);
  4626. }
  4627. }, {
  4628. key: 'chunkUnloaded',
  4629. value: function chunkUnloaded(chunk) {
  4630. var key = chunk.x + ',' + chunk.y;
  4631. delete this.chunks[key];
  4632. if (chunk.locked) {
  4633. delete this.protectedChunks[key];
  4634. chunk.locked = false;
  4635. this.findNeighborLockedChunks(chunk, chunk.locked);
  4636. }
  4637. _global.eventSys.emit(_conf.EVENTS.renderer.rmChunk, chunk);
  4638. }
  4639. }, {
  4640. key: 'chunkPasted',
  4641. value: function chunkPasted(x, y, data) {
  4642. var chunk = this.chunks[x + ',' + y];
  4643. if (chunk) {
  4644. chunk.set(data);
  4645. _global.eventSys.emit(_conf.EVENTS.renderer.updateChunk, chunk);
  4646. }
  4647. }
  4648. }, {
  4649. key: 'unloadAllChunks',
  4650. value: function unloadAllChunks() {
  4651. for (var c in this.chunks) {
  4652. this.chunks[c].remove();
  4653. }
  4654. }
  4655. }]);
  4656.  
  4657. return World;
  4658. }();
  4659.  
  4660. /***/ }),
  4661. /* 13 */
  4662. /***/ (function(module, exports, __webpack_require__) {
  4663.  
  4664. "use strict";
  4665.  
  4666.  
  4667. Object.defineProperty(exports, "__esModule", {
  4668. value: true
  4669. });
  4670. exports.cursors = undefined;
  4671.  
  4672. var _conf = __webpack_require__(1);
  4673.  
  4674. var _global = __webpack_require__(0);
  4675.  
  4676. var cursors = exports.cursors = {
  4677. set: new Image(),
  4678. cursor: { imgpos: [0, 0], hotspot: [0, 0] },
  4679. move: { imgpos: [1, 0], hotspot: [18, 18] },
  4680. pipette: { imgpos: [0, 1], hotspot: [0, 28] },
  4681. erase: { imgpos: [0, 2], hotspot: [4, 26] },
  4682. zoom: { imgpos: [1, 2], hotspot: [19, 10] },
  4683. fill: { imgpos: [1, 1], hotspot: [3, 29] },
  4684. brush: { imgpos: [0, 3], hotspot: [0, 26] },
  4685. select: { imgpos: [2, 0], hotspot: [0, 0] },
  4686. copy: { imgpos: [3, 0], hotspot: [0, 0] },
  4687. paste: { imgpos: [3, 1], hotspot: [0, 0] },
  4688. cut: { imgpos: [3, 2], hotspot: [11, 5] },
  4689. wand: { imgpos: [3, 3], hotspot: [0, 0] },
  4690. shield: { imgpos: [2, 3], hotspot: [18, 18] },
  4691. kick: { imgpos: [2, 1], hotspot: [3, 6] },
  4692. ban: { imgpos: [3, 0], hotspot: [10, 4] },
  4693. write: { imgpos: [1, 3], hotspot: [10, 4]
  4694. } };
  4695.  
  4696. _global.PublicAPI.cursors = cursors;
  4697.  
  4698. function reduce(canvas) {
  4699. /* Removes unused space from the image */
  4700. var nw = canvas.width;
  4701. var nh = canvas.height;
  4702. var ctx = canvas.getContext('2d');
  4703. var idat = ctx.getImageData(0, 0, canvas.width, canvas.height);
  4704. var u32dat = new Uint32Array(idat.data.buffer);
  4705. var xoff = 0;
  4706. var yoff = 0;
  4707. for (var y = 0, x, i = 0; y < idat.height; y++) {
  4708. for (x = idat.width; x--; i += u32dat[y * idat.width + x]) {}
  4709. if (i) {
  4710. break;
  4711. }
  4712. yoff++;
  4713. }
  4714. for (var x = 0, y, i = 0; x < idat.width; x++) {
  4715. for (y = nh; y--; i += u32dat[y * idat.width + x]) {}
  4716. if (i) {
  4717. break;
  4718. }
  4719. xoff++;
  4720. }
  4721. for (var y = idat.height, x, i = 0; y--;) {
  4722. for (x = idat.width; x--; i += u32dat[y * idat.width + x]) {}
  4723. if (i) {
  4724. break;
  4725. }
  4726. nh--;
  4727. }
  4728. for (var x = idat.width, y, i = 0; x--;) {
  4729. for (y = nh; y--; i += u32dat[y * idat.width + x]) {}
  4730. if (i) {
  4731. break;
  4732. }
  4733. nw--;
  4734. }
  4735. canvas.width = nw;
  4736. canvas.height = nh;
  4737. ctx.putImageData(idat, -xoff, -yoff);
  4738. }
  4739.  
  4740. function shadow(canvas, img) {
  4741. /* Make a bigger image so the shadow doesn't get cut */
  4742. canvas.width = 2 + img.width + 6;
  4743. canvas.height = 2 + img.height + 6;
  4744. var ctx = canvas.getContext('2d');
  4745. ctx.shadowColor = '#000000';
  4746. ctx.globalAlpha = 0.5; /* The shadow is too dark so we draw it transparent */
  4747. ctx.shadowBlur = 4;
  4748. ctx.shadowOffsetX = 2;
  4749. ctx.shadowOffsetY = 2;
  4750. ctx.drawImage(img, 2, 2);
  4751. ctx.globalAlpha = 1;
  4752. ctx.shadowColor = 'rgba(0, 0, 0, 0)'; /* disables the shadow */
  4753. ctx.drawImage(img, 2, 2);
  4754. }
  4755.  
  4756. /* makes a hole with the shape of the image */
  4757. function popOut(canvas, img) {
  4758. var shadowcolor = 0xFF3B314D;
  4759. var backgroundcolor = 0xFF5C637E;
  4760. canvas.width = img.width;
  4761. canvas.height = img.height;
  4762. var ctx = canvas.getContext('2d');
  4763. ctx.drawImage(img, 0, 0);
  4764. var idat = ctx.getImageData(0, 0, canvas.width, canvas.height);
  4765. var u32dat = new Uint32Array(idat.data.buffer);
  4766. var clr = function clr(x, y) {
  4767. return x < 0 || y < 0 || x >= idat.width || y >= idat.height ? 0 : u32dat[y * idat.width + x];
  4768. };
  4769. for (var i = u32dat.length; i--;) {
  4770. if (u32dat[i] !== 0) {
  4771. u32dat[i] = backgroundcolor;
  4772. }
  4773. }
  4774. for (var y = idat.height; y--;) {
  4775. for (var x = idat.width; x--;) {
  4776. if (clr(x, y) === backgroundcolor && (!clr(x, y - 1) || !clr(x - 1, y)) && !clr(x - 1, y - 1)) {
  4777. u32dat[y * idat.width + x] = shadowcolor;
  4778. }
  4779. }
  4780. }
  4781. for (var y = idat.height; y--;) {
  4782. for (var x = idat.width; x--;) {
  4783. if (clr(x, y - 1) === shadowcolor && clr(x - 1, y) === shadowcolor) {
  4784. u32dat[y * idat.width + x] = shadowcolor;
  4785. }
  4786. }
  4787. }
  4788. ctx.putImageData(idat, 0, 0);
  4789. }
  4790.  
  4791. function load(oncomplete) {
  4792. cursors.set.onload = function () {
  4793. var set = cursors.set;
  4794. var slotcanvas = document.createElement('canvas');
  4795. popOut(slotcanvas, set);
  4796. var j = Object.keys(cursors).length - 1 + 1; /* +1 slotset to blob url */
  4797. for (var tool in cursors) {
  4798. if (tool === 'set') {
  4799. continue;
  4800. }
  4801. tool = cursors[tool];
  4802. var original = document.createElement('canvas');
  4803. var i = tool.img = {
  4804. shadowed: document.createElement('canvas'),
  4805. shadowblob: null
  4806. };
  4807. original.width = original.height = 36;
  4808. original.getContext('2d').drawImage(set, tool.imgpos[0] * 36, tool.imgpos[1] * 36, 36, 36, 0, 0, 36, 36);
  4809. reduce(original);
  4810. shadow(i.shadowed, original);
  4811. tool.hotspot[0] += 2;
  4812. tool.hotspot[1] += 2; /* Check shadow() for explanation */
  4813.  
  4814. /* Blob-ify images */
  4815. i.shadowed.toBlob(function (blob) {
  4816. this.img.shadowblob = URL.createObjectURL(blob);
  4817. if (! --j) oncomplete();
  4818. }.bind(tool));
  4819. }
  4820. slotcanvas.toBlob(function (blob) {
  4821. cursors.slotset = URL.createObjectURL(blob);
  4822. if (! --j) oncomplete();
  4823. });
  4824. };
  4825.  
  4826. cursors.set.src = _conf.options.toolSetUrl;
  4827. }
  4828.  
  4829. _global.eventSys.once(_conf.EVENTS.loaded, function () {
  4830. load(function () {
  4831. return _global.eventSys.emit(_conf.EVENTS.misc.toolsRendered);
  4832. });
  4833. });
  4834.  
  4835. /***/ }),
  4836. /* 14 */
  4837. /***/ (function(module, exports, __webpack_require__) {
  4838.  
  4839. "use strict";
  4840.  
  4841.  
  4842. Object.defineProperty(exports, "__esModule", {
  4843. value: true
  4844. });
  4845. exports.Lerp = undefined;
  4846.  
  4847. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  4848.  
  4849. var _misc = __webpack_require__(2);
  4850.  
  4851. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  4852.  
  4853. /* Time function, time will be updated by the renderer */
  4854. var time = _misc.getTime /*() => getTime(true)*/;
  4855.  
  4856. var Lerp = exports.Lerp = function () {
  4857. function Lerp(start, end, ms) {
  4858. _classCallCheck(this, Lerp);
  4859.  
  4860. this.start = start;
  4861. this.end = end;
  4862. this.ms = ms;
  4863. this.time = time();
  4864. }
  4865.  
  4866. _createClass(Lerp, [{
  4867. key: 'val',
  4868. get: function get() {
  4869. var amt = Math.min((time() - this.time) / this.ms, 1);
  4870. return (1 - amt) * this.start + amt * this.end;
  4871. },
  4872. set: function set(v) {
  4873. this.start = this.val;
  4874. this.end = v;
  4875. this.time = time(true);
  4876. }
  4877. }]);
  4878.  
  4879. return Lerp;
  4880. }();
  4881.  
  4882. /***/ }),
  4883. /* 15 */
  4884. /***/ (function(module, exports, __webpack_require__) {
  4885.  
  4886. "use strict";
  4887. /**
  4888. * Copyright (c) 2015, Facebook, Inc.
  4889. * All rights reserved.
  4890. *
  4891. * This source code is licensed under the BSD-style license found in the
  4892. * LICENSE file in the root directory of this source tree. An additional grant
  4893. * of patent rights can be found in the PATENTS file in the same directory.
  4894. *
  4895. * @providesModule normalizeWheel
  4896. * @typechecks
  4897. */
  4898.  
  4899. /* source: https:
  4900.  
  4901.  
  4902.  
  4903.  
  4904.  
  4905. Object.defineProperty(exports, "__esModule", {
  4906. value: true
  4907. });
  4908. exports.normalizeWheel = normalizeWheel;
  4909. var PIXEL_STEP = 10;
  4910. var LINE_HEIGHT = 40;
  4911. var PAGE_HEIGHT = 800;
  4912.  
  4913. function normalizeWheel( /*object*/event) /*object*/{
  4914. var sX = 0,
  4915. sY = 0,
  4916.  
  4917. pX = 0,
  4918. pY = 0;
  4919.  
  4920.  
  4921. if ('detail' in event) {
  4922. sY = event.detail;
  4923. }
  4924. if ('wheelDelta' in event) {
  4925. sY = -event.wheelDelta / 120;
  4926. }
  4927. if ('wheelDeltaY' in event) {
  4928. sY = -event.wheelDeltaY / 120;
  4929. }
  4930. if ('wheelDeltaX' in event) {
  4931. sX = -event.wheelDeltaX / 120;
  4932. }
  4933.  
  4934.  
  4935. if ('axis' in event && event.axis === event.HORIZONTAL_AXIS) {
  4936. sX = sY;
  4937. sY = 0;
  4938. }
  4939.  
  4940. pX = sX * PIXEL_STEP;
  4941. pY = sY * PIXEL_STEP;
  4942.  
  4943. if ('deltaY' in event) {
  4944. pY = event.deltaY;
  4945. }
  4946. if ('deltaX' in event) {
  4947. pX = event.deltaX;
  4948. }
  4949.  
  4950. if ((pX || pY) && event.deltaMode) {
  4951. if (event.deltaMode == 1) {
  4952.  
  4953. pX *= LINE_HEIGHT;
  4954. pY *= LINE_HEIGHT;
  4955. } else {
  4956.  
  4957. pX *= PAGE_HEIGHT;
  4958. pY *= PAGE_HEIGHT;
  4959. }
  4960. }
  4961.  
  4962.  
  4963. if (pX && !sX) {
  4964. sX = pX < 1 ? -1 : 1;
  4965. }
  4966. if (pY && !sY) {
  4967. sY = pY < 1 ? -1 : 1;
  4968. }
  4969.  
  4970. return { spinX: sX,
  4971. spinY: sY,
  4972. pixelX: pX,
  4973. pixelY: pY };
  4974. }
  4975.  
  4976. /***/ }),
  4977. /* 16 */
  4978. /***/ (function(module, exports, __webpack_require__) {
  4979.  
  4980. "use strict";
  4981. var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_RESULT__;
  4982.  
  4983. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
  4984.  
  4985. !function (e, a) {
  4986. "object" == ( false ? "undefined" : _typeof(exports)) && "undefined" != typeof module ? module.exports = a() : true ? !(__WEBPACK_AMD_DEFINE_FACTORY__ = (a),
  4987. __WEBPACK_AMD_DEFINE_RESULT__ = (typeof __WEBPACK_AMD_DEFINE_FACTORY__ === 'function' ?
  4988. (__WEBPACK_AMD_DEFINE_FACTORY__.call(exports, __webpack_require__, exports, module)) :
  4989. __WEBPACK_AMD_DEFINE_FACTORY__),
  4990. __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__)) : e.anchorme = a();
  4991. }(undefined, function () {
  4992. "use strict";
  4993. function e(e, a) {
  4994. return a = { exports: {} }, e(a, a.exports), a.exports;
  4995. }var a = e(function (e, a) {
  4996. function n(e) {
  4997. return e || (e = { attributes: [], ips: !0, emails: !0, urls: !0, files: !0, truncate: 1 / 0, defaultProtocol: "http:
  4998. }function t(e) {
  4999. return !isNaN(Number(e)) && !(Number(e) > 65535);
  5000. }Object.defineProperty(a, "__esModule", { value: !0 }), a.defaultOptions = n, a.isPort = t;
  5001. }),
  5002. n = e(function (e, a) {
  5003. Object.defineProperty(a, "__esModule", { value: !0 }), a.tlds = ["com", "org", "net", "uk", "gov", "edu", "io", "cc", "co", "aaa", "aarp", "abarth", "abb", "abbott", "abbvie", "abc", "able", "abogado", "abudhabi", "ac", "academy", "accenture", "accountant", "accountants", "aco", "active", "actor", "ad", "adac", "ads", "adult", "ae", "aeg", "aero", "aetna", "af", "afamilycompany", "afl", "africa", "ag", "agakhan", "agency", "ai", "aig", "aigo", "airbus", "airforce", "airtel", "akdn", "al", "alfaromeo", "alibaba", "alipay", "allfinanz", "allstate", "ally", "alsace", "alstom", "am", "americanexpress", "americanfamily", "amex", "amfam", "amica", "amsterdam", "analytics", "android", "anquan", "anz", "ao", "aol", "apartments", "app", "apple", "aq", "aquarelle", "ar", "aramco", "archi", "army", "arpa", "art", "arte", "as", "asda", "asia", "associates", "at", "athleta", "attorney", "au", "auction", "audi", "audible", "audio", "auspost", "author", "auto", "autos", "avianca", "aw", "aws", "ax", "axa", "az", "azure", "ba", "baby", "baidu", "banamex", "bananarepublic", "band", "bank", "bar", "barcelona", "barclaycard", "barclays", "barefoot", "bargains", "baseball", "basketball", "bauhaus", "bayern", "bb", "bbc", "bbt", "bbva", "bcg", "bcn", "bd", "be", "beats", "beauty", "beer", "bentley", "berlin", "best", "bestbuy", "bet", "bf", "bg", "bh", "bharti", "bi", "bible", "bid", "bike", "bing", "bingo", "bio", "biz", "bj", "black", "blackfriday", "blanco", "blockbuster", "blog", "bloomberg", "blue", "bm", "bms", "bmw", "bn", "bnl", "bnpparibas", "bo", "boats", "boehringer", "bofa", "bom", "bond", "boo", "book", "booking", "boots", "bosch", "bostik", "boston", "bot", "boutique", "box", "br", "bradesco", "bridgestone", "broadway", "broker", "brother", "brussels", "bs", "bt", "budapest", "bugatti", "build", "builders", "business", "buy", "buzz", "bv", "bw", "by", "bz", "bzh", "ca", "cab", "cafe", "cal", "call", "calvinklein", "cam", "camera", "camp", "cancerresearch", "canon", "capetown", "capital", "capitalone", "car", "caravan", "cards", "care", "career", "careers", "cars", "cartier", "casa", "case", "caseih", "cash", "casino", "cat", "catering", "catholic", "cba", "cbn", "cbre", "cbs", "cd", "ceb", "center", "ceo", "cern", "cf", "cfa", "cfd", "cg", "ch", "chanel", "channel", "chase", "chat", "cheap", "chintai", "chloe", "christmas", "chrome", "chrysler", "church", "ci", "cipriani", "circle", "cisco", "citadel", "citi", "citic", "city", "cityeats", "ck", "cl", "claims", "cleaning", "click", "clinic", "clinique", "clothing", "cloud", "club", "clubmed", "cm", "cn", "coach", "codes", "coffee", "college", "cologne", "comcast", "commbank", "community", "company", "compare", "computer", "comsec", "condos", "construction", "consulting", "contact", "contractors", "cooking", "cookingchannel", "cool", "coop", "corsica", "country", "coupon", "coupons", "courses", "cr", "credit", "creditcard", "creditunion", "cricket", "crown", "crs", "cruise", "cruises", "csc", "cu", "cuisinella", "cv", "cw", "cx", "cy", "cymru", "cyou", "cz", "dabur", "dad", "dance", "data", "date", "dating", "datsun", "day", "dclk", "dds", "de", "deal", "dealer", "deals", "degree", "delivery", "dell", "deloitte", "delta", "democrat", "dental", "dentist", "desi", "design", "dev", "dhl", "diamonds", "diet", "digital", "direct", "directory", "discount", "discover", "dish", "diy", "dj", "dk", "dm", "dnp", "do", "docs", "doctor", "dodge", "dog", "doha", "domains", "dot", "download", "drive", "dtv", "dubai", "duck", "dunlop", "duns", "dupont", "durban", "dvag", "dvr", "dz", "earth", "eat", "ec", "eco", "edeka", "education", "ee", "eg", "email", "emerck", "energy", "engineer", "engineering", "enterprises", "epost", "epson", "equipment", "er", "ericsson", "erni", "es", "esq", "estate", "esurance", "et", "eu", "eurovision", "eus", "events", "everbank", "exchange", "expert", "exposed", "express", "extraspace", "fage", "fail", "fairwinds", "faith", "family", "fan", "fans", "farm", "farmers", "fashion", "fast", "fedex", "feedback", "ferrari", "ferrero", "fi", "fiat", "fidelity", "fido", "film", "final", "finance", "financial", "fire", "firestone", "firmdale", "fish", "fishing", "fit", "fitness", "fj", "fk", "flickr", "flights", "flir", "florist", "flowers", "fly", "fm", "fo", "foo", "food", "foodnetwork", "football", "ford", "forex", "forsale", "forum", "foundation", "fox", "fr", "free", "fresenius", "frl", "frogans", "frontdoor", "frontier", "ftr", "fujitsu", "fujixerox", "fun", "fund", "furniture", "futbol", "fyi", "ga", "gal", "gallery", "gallo", "gallup", "game", "games", "gap", "garden", "gb", "gbiz", "gd", "gdn", "ge", "gea", "gent", "genting", "george", "gf", "gg", "ggee", "gh", "gi", "gift", "gifts", "gives", "giving", "gl", "glade", "glass", "gle", "global", "globo", "gm", "gmail", "gmbh", "gmo", "gmx", "gn", "godaddy", "gold", "goldpoint", "golf", "goo", "goodhands", "goodyear", "goog", "google", "gop", "got", "gp", "gq", "gr", "grainger", "graphics", "gratis", "green", "gripe", "group", "gs", "gt", "gu", "guardian", "gucci", "guge", "guide", "guitars", "guru", "gw", "gy", "hair", "hamburg", "hangout", "haus", "hbo", "hdfc", "hdfcbank", "health", "healthcare", "help", "helsinki", "here", "hermes", "hgtv", "hiphop", "hisamitsu", "hitachi", "hiv", "hk", "hkt", "hm", "hn", "hockey", "holdings", "holiday", "homedepot", "homegoods", "homes", "homesense", "honda", "honeywell", "horse", "hospital", "host", "hosting", "hot", "hoteles", "hotmail", "house", "how", "hr", "hsbc", "ht", "htc", "hu", "hughes", "hyatt", "hyundai", "ibm", "icbc", "ice", "icu", "id", "ie", "ieee", "ifm", "ikano", "il", "im", "imamat", "imdb", "immo", "immobilien", "in", "industries", "infiniti", "info", "ing", "ink", "institute", "insurance", "insure", "int", "intel", "international", "intuit", "investments", "ipiranga", "iq", "ir", "irish", "is", "iselect", "ismaili", "ist", "istanbul", "it", "itau", "itv", "iveco", "iwc", "jaguar", "java", "jcb", "jcp", "je", "jeep", "jetzt", "jewelry", "jio", "jlc", "jll", "jm", "jmp", "jnj", "jo", "jobs", "joburg", "jot", "joy", "jp", "jpmorgan", "jprs", "juegos", "juniper", "kaufen", "kddi", "ke", "kerryhotels", "kerrylogistics", "kerryproperties", "kfh", "kg", "kh", "ki", "kia", "kim", "kinder", "kindle", "kitchen", "kiwi", "km", "kn", "koeln", "komatsu", "kosher", "kp", "kpmg", "kpn", "kr", "krd", "kred", "kuokgroup", "kw", "ky", "kyoto", "kz", "la", "lacaixa", "ladbrokes", "lamborghini", "lamer", "lancaster", "lancia", "lancome", "land", "landrover", "lanxess", "lasalle", "lat", "latino", "latrobe", "law", "lawyer", "lb", "lc", "lds", "lease", "leclerc", "lefrak", "legal", "lego", "lexus", "lgbt", "li", "liaison", "lidl", "life", "lifeinsurance", "lifestyle", "lighting", "like", "lilly", "limited", "limo", "lincoln", "linde", "link", "lipsy", "live", "living", "lixil", "lk", "loan", "loans", "locker", "locus", "loft", "lol", "london", "lotte", "lotto", "love", "lpl", "lplfinancial", "lr", "ls", "lt", "ltd", "ltda", "lu", "lundbeck", "lupin", "luxe", "luxury", "lv", "ly", "ma", "macys", "madrid", "maif", "maison", "makeup", "man", "management", "mango", "market", "marketing", "markets", "marriott", "marshalls", "maserati", "mattel", "mba", "mc", "mcd", "mcdonalds", "mckinsey", "md", "me", "med", "media", "meet", "melbourne", "meme", "memorial", "men", "menu", "meo", "metlife", "mg", "mh", "miami", "microsoft", "mil", "mini", "mint", "mit", "mitsubishi", "mk", "ml", "mlb", "mls", "mm", "mma", "mn", "mo", "mobi", "mobile", "mobily", "moda", "moe", "moi", "mom", "monash", "money", "monster", "montblanc", "mopar", "mormon", "mortgage", "moscow", "moto", "motorcycles", "mov", "movie", "movistar", "mp", "mq", "mr", "ms", "msd", "mt", "mtn", "mtpc", "mtr", "mu", "museum", "mutual", "mv", "mw", "mx", "my", "mz", "na", "nab", "nadex", "nagoya", "name", "nationwide", "natura", "navy", "nba", "nc", "ne", "nec", "netbank", "netflix", "network", "neustar", "new", "newholland", "news", "next", "nextdirect", "nexus", "nf", "nfl", "ng", "ngo", "nhk", "ni", "nico", "nike", "nikon", "ninja", "nissan", "nissay", "nl", "no", "nokia", "northwesternmutual", "norton", "now", "nowruz", "nowtv", "np", "nr", "nra", "nrw", "ntt", "nu", "nyc", "nz", "obi", "observer", "off", "office", "okinawa", "olayan", "olayangroup", "oldnavy", "ollo", "om", "omega", "one", "ong", "onl", "online", "onyourside", "ooo", "open", "oracle", "orange", "organic", "orientexpress", "origins", "osaka", "otsuka", "ott", "ovh", "pa", "page", "pamperedchef", "panasonic", "panerai", "paris", "pars", "partners", "parts", "party", "passagens", "pay", "pccw", "pe", "pet", "pf", "pfizer", "pg", "ph", "pharmacy", "philips", "phone", "photo", "photography", "photos", "physio", "piaget", "pics", "pictet", "pictures", "pid", "pin", "ping", "pink", "pioneer", "pizza", "pk", "pl", "place", "play", "playstation", "plumbing", "plus", "pm", "pn", "pnc", "pohl", "poker", "politie", "porn", "post", "pr", "pramerica", "praxi", "press", "prime", "pro", "prod", "productions", "prof", "progressive", "promo", "properties", "property", "protection", "pru", "prudential", "ps", "pt", "pub", "pw", "pwc", "py", "qa", "qpon", "quebec", "quest", "qvc", "racing", "radio", "raid", "re", "read", "realestate", "realtor", "realty", "recipes", "red", "redstone", "redumbrella", "rehab", "reise", "reisen", "reit", "reliance", "ren", "rent", "rentals", "repair", "report", "republican", "rest", "restaurant", "review", "reviews", "rexroth", "rich", "richardli", "ricoh", "rightathome", "ril", "rio", "rip", "rmit", "ro", "rocher", "rocks", "rodeo", "rogers", "room", "rs", "rsvp", "ru", "ruhr", "run", "rw", "rwe", "ryukyu", "sa", "saarland", "safe", "safety", "sakura", "sale", "salon", "samsclub", "samsung", "sandvik", "sandvikcoromant", "sanofi", "sap", "sapo", "sarl", "sas", "save", "saxo", "sb", "sbi", "sbs", "sc", "sca", "scb", "schaeffler", "schmidt", "scholarships", "school", "schule", "schwarz", "science", "scjohnson", "scor", "scot", "sd", "se", "seat", "secure", "security", "seek", "select", "sener", "services", "ses", "seven", "sew", "sex", "sexy", "sfr", "sg", "sh", "shangrila", "sharp", "shaw", "shell", "shia", "shiksha", "shoes", "shop", "shopping", "shouji", "show", "showtime", "shriram", "si", "silk", "sina", "singles", "site", "sj", "sk", "ski", "skin", "sky", "skype", "sl", "sling", "sm", "smart", "smile", "sn", "sncf", "so", "soccer", "social", "softbank", "software", "sohu", "solar", "solutions", "song", "sony", "soy", "space", "spiegel", "spot", "spreadbetting", "sr", "srl", "srt", "st", "stada", "staples", "star", "starhub", "statebank", "statefarm", "statoil", "stc", "stcgroup", "stockholm", "storage", "store", "stream", "studio", "study", "style", "su", "sucks", "supplies", "supply", "support", "surf", "surgery", "suzuki", "sv", "swatch", "swiftcover", "swiss", "sx", "sy", "sydney", "symantec", "systems", "sz", "tab", "taipei", "talk", "taobao", "target", "tatamotors", "tatar", "tattoo", "tax", "taxi", "tc", "tci", "td", "tdk", "team", "tech", "technology", "tel", "telecity", "telefonica", "temasek", "tennis", "teva", "tf", "tg", "th", "thd", "theater", "theatre", "tiaa", "tickets", "tienda", "tiffany", "tips", "tires", "tirol", "tj", "tjmaxx", "tjx", "tk", "tkmaxx", "tl", "tm", "tmall", "tn", "to", "today", "tokyo", "tools", "top", "toray", "toshiba", "total", "tours", "town", "toyota", "toys", "tr", "trade", "trading", "training", "travel", "travelchannel", "travelers", "travelersinsurance", "trust", "trv", "tt", "tube", "tui", "tunes", "tushu", "tv", "tvs", "tw", "tz", "ua", "ubank", "ubs", "uconnect", "ug", "unicom", "university", "uno", "uol", "ups", "us", "uy", "uz", "va", "vacations", "vana", "vanguard", "vc", "ve", "vegas", "ventures", "verisign", "versicherung", "vet", "vg", "vi", "viajes", "video", "vig", "viking", "villas", "vin", "vip", "virgin", "visa", "vision", "vista", "vistaprint", "viva", "vivo", "vlaanderen", "vn", "vodka", "volkswagen", "volvo", "vote", "voting", "voto", "voyage", "vu", "vuelos", "wales", "walmart", "walter", "wang", "wanggou", "warman", "watch", "watches", "weather", "weatherchannel", "webcam", "weber", "website", "wed", "wedding", "weibo", "weir", "wf", "whoswho", "wien", "wiki", "williamhill", "win", "windows", "wine", "winners", "wme", "wolterskluwer", "woodside", "work", "works", "world", "wow", "ws", "wtc", "wtf", "xbox", "xerox", "xfinity", "xihuan", "xin", "xn--11b4c3d", "xn--1ck2e1b", "xn--1qqw23a", "xn--30rr7y", "xn--3bst00m", "xn--3ds443g", "xn--3e0b707e", "xn--3oq18vl8pn36a", "xn--3pxu8k", "xn--42c2d9a", "xn--45brj9c", "xn--45q11c", "xn--4gbrim", "xn--54b7fta0cc", "xn--55qw42g", "xn--55qx5d", "xn--5su34j936bgsg", "xn--5tzm5g", "xn--6frz82g", "xn--6qq986b3xl", "xn--80adxhks", "xn--80ao21a", "xn--80aqecdr1a", "xn--80asehdb", "xn--80aswg", "xn--8y0a063a", "xn--90a3ac", "xn--90ae", "xn--90ais", "xn--9dbq2a", "xn--9et52u", "xn--9krt00a", "xn--b4w605ferd", "xn--bck1b9a5dre4c", "xn--c1avg", "xn--c2br7g", "xn--cck2b3b", "xn--cg4bki", "xn--clchc0ea0b2g2a9gcd", "xn--czr694b", "xn--czrs0t", "xn--czru2d", "xn--d1acj3b", "xn--d1alf", "xn--e1a4c", "xn--eckvdtc9d", "xn--efvy88h", "xn--estv75g", "xn--fct429k", "xn--fhbei", "xn--fiq228c5hs", "xn--fiq64b", "xn--fiqs8s", "xn--fiqz9s", "xn--fjq720a", "xn--flw351e", "xn--fpcrj9c3d", "xn--fzc2c9e2c", "xn--fzys8d69uvgm", "xn--g2xx48c", "xn--gckr3f0f", "xn--gecrj9c", "xn--gk3at1e", "xn--h2brj9c", "xn--hxt814e", "xn--i1b6b1a6a2e", "xn--imr513n", "xn--io0a7i", "xn--j1aef", "xn--j1amh", "xn--j6w193g", "xn--jlq61u9w7b", "xn--jvr189m", "xn--kcrx77d1x4a", "xn--kprw13d", "xn--kpry57d", "xn--kpu716f", "xn--kput3i", "xn--l1acc", "xn--lgbbat1ad8j", "xn--mgb9awbf", "xn--mgba3a3ejt", "xn--mgba3a4f16a", "xn--mgba7c0bbn0a", "xn--mgbaam7a8h", "xn--mgbab2bd", "xn--mgbai9azgqp6j", "xn--mgbayh7gpa", "xn--mgbb9fbpob", "xn--mgbbh1a71e", "xn--mgbc0a9azcg", "xn--mgbca7dzdo", "xn--mgberp4a5d4ar", "xn--mgbi4ecexp", "xn--mgbpl2fh", "xn--mgbt3dhd", "xn--mgbtx2b", "xn--mgbx4cd0ab", "xn--mix891f", "xn--mk1bu44c", "xn--mxtq1m", "xn--ngbc5azd", "xn--ngbe9e0a", "xn--node", "xn--nqv7f", "xn--nqv7fs00ema", "xn--nyqy26a", "xn--o3cw4h", "xn--ogbpf8fl", "xn--p1acf", "xn--p1ai", "xn--pbt977c", "xn--pgbs0dh", "xn--pssy2u", "xn--q9jyb4c", "xn--qcka1pmc", "xn--qxam", "xn--rhqv96g", "xn--rovu88b", "xn--s9brj9c", "xn--ses554g", "xn--t60b56a", "xn--tckwe", "xn--tiq49xqyj", "xn--unup4y", "xn--vermgensberater-ctb", "xn--vermgensberatung-pwb", "xn--vhquv", "xn--vuq861b", "xn--w4r85el8fhu5dnra", "xn--w4rs40l", "xn--wgbh1c", "xn--wgbl6a", "xn--xhq521b", "xn--xkc2al3hye2a", "xn--xkc2dl3a5ee0h", "xn--y9a3aq", "xn--yfro4i67o", "xn--ygbi2ammx", "xn--zfr164b", "xperia", "xxx", "xyz", "yachts", "yahoo", "yamaxun", "yandex", "ye", "yodobashi", "yoga", "yokohama", "you", "youtube", "yt", "yun", "za", "zappos", "zara", "zero", "zip", "zippo", "zm", "zone", "zuerich", "zw"], a.htmlAttrs = ["src=", "data=", "href=", "cite=", "formaction=", "icon=", "manifest=", "poster=", "codebase=", "background=", "profile=", "usemap="];
  5004. }),
  5005. t = e(function (e, a) {
  5006. function t(e) {
  5007. var a = e.match(o);if (null === a) return !1;for (var t = r.length - 1; t >= 0; t--) {
  5008. if (r[t].test(e)) return !1;
  5009. }var i = a[2];return !!i && -1 !== n.tlds.indexOf(i);
  5010. }Object.defineProperty(a, "__esModule", { value: !0 });var o = /^[a-z0-9!#$%&'*+\-\/=?^_`{|}~.]+@([a-z0-9%\-]+\.){1,}([a-z0-9\-]+)?$/i,
  5011. r = [/^[!#$%&'*+\-\/=?^_`{|}~.]/, /[.]{2,}[a-z0-9!#$%&'*+\-\/=?^_`{|}~.]+@/i, /\.@/];a.default = t;
  5012. }),
  5013. o = e(function (e, n) {
  5014. function t(e) {
  5015. if (!o.test(e)) return !1;var n = e.split("."),
  5016. t = Number(n[0]);if (isNaN(t) || t > 255 || t < 0) return !1;var r = Number(n[1]);if (isNaN(r) || r > 255 || r < 0) return !1;var i = Number(n[2]);if (isNaN(i) || i > 255 || i < 0) return !1;var s = Number((n[3].match(/^\d+/) || [])[0]);if (isNaN(s) || s > 255 || s < 0) return !1;var c = (n[3].match(/(^\d+)(:)(\d+)/) || [])[3];return !(c && !a.isPort(c));
  5017. }Object.defineProperty(n, "__esModule", { value: !0 });var o = /^(\d{1,3}\.){3}\d{1,3}(:\d{1,5})?(\/([a-z0-9\-._~:\/\?#\[\]@!$&'\(\)\*\+,;=%]+)?)?$/i;n.default = t;
  5018. }),
  5019. r = e(function (e, t) {
  5020. function o(e) {
  5021. var t = e.match(r);return null !== t && "string" == typeof t[3] && -1 !== n.tlds.indexOf(t[3].toLowerCase()) && !(t[5] && !a.isPort(t[5]));
  5022. }Object.defineProperty(t, "__esModule", { value: !0 });var r = /^(https?:\/\/|ftps?:\/\/)?([a-z0-9%\-]+\.){1,}([a-z0-9\-]+)?(:(\d{1,5}))?(\/([a-z0-9\-._~:\/\?#\[\]@!$&'\(\)\*\+,;=%]+)?)?$/i;t.default = o;
  5023. }),
  5024. i = e(function (e, a) {
  5025. function n(e, a, t) {
  5026. return e.forEach(function (o, r) {
  5027. !(o.indexOf(".") > -1) || e[r - 1] === a && e[r + 1] === t || e[r + 1] !== a && e[r + 1] !== t || (e[r] = e[r] + e[r + 1], "string" == typeof e[r + 2] && (e[r] = e[r] + e[r + 2]), "string" == typeof e[r + 3] && (e[r] = e[r] + e[r + 3]), "string" == typeof e[r + 4] && (e[r] = e[r] + e[r + 4]), e.splice(r + 1, 4), n(e, a, t));
  5028. }), e;
  5029. }function t(e) {
  5030. return e = n(e, "(", ")"), e = n(e, "[", "]"), e = n(e, '"', '"'), e = n(e, "'", "'");
  5031. }Object.defineProperty(a, "__esModule", { value: !0 }), a.fixSeparators = n, a.default = t;
  5032. }),
  5033. s = e(function (e, a) {
  5034. function n(e) {
  5035. var a = e.replace(/([\s\(\)\[\]<>"'])/g, "\0$1\0").replace(/([?;:,.!]+)(?=(\0|$|\s))/g, "\0$1\0").split("\0");return i.default(a);
  5036. }function t(e) {
  5037. return e.join("");
  5038. }Object.defineProperty(a, "__esModule", { value: !0 }), a.separate = n, a.deSeparate = t;
  5039. }),
  5040. c = e(function (e, a) {
  5041. function n(e) {
  5042. return e = e.toLowerCase(), 0 === e.indexOf("http:
  5043. }Object.defineProperty(a, "__esModule", { value: !0 }), a.default = n;
  5044. }),
  5045. l = e(function (e, a) {
  5046. function i(e, a) {
  5047. return e.map(function (i, s) {
  5048. var l = encodeURI(i);if (l.indexOf(".") < 1 && !c.default(l)) return i;var u = null,
  5049. d = c.default(l) || "";return d && (l = l.substr(d.length)), a.files && "file:
  5050. });
  5051. }Object.defineProperty(a, "__esModule", { value: !0 }), a.default = i;
  5052. }),
  5053. u = e(function (e, a) {
  5054. function n(e, a) {
  5055. var n = o.separate(e),
  5056. r = l.default(n, a);if (a.exclude) for (var i = 0; i < r.length; i++) {
  5057. var c = r[i];"object" == (typeof c === "undefined" ? "undefined" : _typeof(c)) && a.exclude(c) && (r[i] = c.raw);
  5058. }if (a.list) {
  5059. for (var u = [], d = 0; d < r.length; d++) {
  5060. var b = r[d];"string" != typeof b && u.push(b);
  5061. }return u;
  5062. }return r = r.map(function (e) {
  5063. return "string" == typeof e ? e : t(e, a);
  5064. }), s.deSeparate(r);
  5065. }function t(e, a) {
  5066. var n = e.protocol + e.encoded,
  5067. t = e.raw;return "number" == typeof a.truncate && t.length > a.truncate && (t = t.substring(0, a.truncate) + "..."), "object" == _typeof(a.truncate) && t.length > a.truncate[0] + a.truncate[1] && (t = t.substr(0, a.truncate[0]) + "..." + t.substr(t.length - a.truncate[1])), void 0 === a.attributes && (a.attributes = []), '<a href="' + n + '" ' + a.attributes.map(function (a) {
  5068. if ("function" != typeof a) return " " + a.name + '="' + a.value + '" ';var n = (a(e) || {}).name,
  5069. t = (a(e) || {}).value;return n && !t ? " name " : n && t ? " " + n + '="' + t + '" ' : void 0;
  5070. }).join("") + ">" + t + "</a>";
  5071. }Object.defineProperty(a, "__esModule", { value: !0 });var o = s;a.default = n;
  5072. }),
  5073. d = e(function (e, n) {
  5074. Object.defineProperty(n, "__esModule", { value: !0 });var i = function i(e, n) {
  5075. return n = a.defaultOptions(n), u.default(e, n);
  5076. };i.validate = { ip: o.default, url: function url(e) {
  5077. var a = c.default(e) || "";return e = e.substr(a.length), e = encodeURI(e), r.default(e);
  5078. }, email: t.default }, n.default = i;
  5079. });return function (e) {
  5080. return e && e.__esModule ? e.default : e;
  5081. }(d);
  5082. });
  5083.  
  5084. /***/ }),
  5085. /* 17 */
  5086. /***/ (function(module, exports) {
  5087.  
  5088.  
  5089. //
  5090.  
  5091.  
  5092.  
  5093.  
  5094.  
  5095.  
  5096.  
  5097. //
  5098.  
  5099.  
  5100. //
  5101.  
  5102.  
  5103.  
  5104.  
  5105.  
  5106.  
  5107.  
  5108.  
  5109. function EventEmitter() {
  5110. this._events = this._events || {};
  5111. this._maxListeners = this._maxListeners || undefined;
  5112. }
  5113. module.exports = EventEmitter;
  5114.  
  5115.  
  5116. EventEmitter.EventEmitter = EventEmitter;
  5117.  
  5118. EventEmitter.prototype._events = undefined;
  5119. EventEmitter.prototype._maxListeners = undefined;
  5120.  
  5121.  
  5122.  
  5123. EventEmitter.defaultMaxListeners = 10;
  5124.  
  5125.  
  5126.  
  5127. EventEmitter.prototype.setMaxListeners = function(n) {
  5128. if (!isNumber(n) || n < 0 || isNaN(n))
  5129. throw TypeError('n must be a positive number');
  5130. this._maxListeners = n;
  5131. return this;
  5132. };
  5133.  
  5134. EventEmitter.prototype.emit = function(type) {
  5135. var er, handler, len, args, i, listeners;
  5136.  
  5137. if (!this._events)
  5138. this._events = {};
  5139.  
  5140.  
  5141. if (type === 'error') {
  5142. if (!this._events.error ||
  5143. (isObject(this._events.error) && !this._events.error.length)) {
  5144. er = arguments[1];
  5145. if (er instanceof Error) {
  5146. throw er;
  5147. } else {
  5148.  
  5149. var err = new Error('Uncaught, unspecified "error" event. (' + er + ')');
  5150. err.context = er;
  5151. throw err;
  5152. }
  5153. }
  5154. }
  5155.  
  5156. handler = this._events[type];
  5157.  
  5158. if (isUndefined(handler))
  5159. return false;
  5160.  
  5161. if (isFunction(handler)) {
  5162. switch (arguments.length) {
  5163.  
  5164. case 1:
  5165. handler.call(this);
  5166. break;
  5167. case 2:
  5168. handler.call(this, arguments[1]);
  5169. break;
  5170. case 3:
  5171. handler.call(this, arguments[1], arguments[2]);
  5172. break;
  5173.  
  5174. default:
  5175. args = Array.prototype.slice.call(arguments, 1);
  5176. handler.apply(this, args);
  5177. }
  5178. } else if (isObject(handler)) {
  5179. args = Array.prototype.slice.call(arguments, 1);
  5180. listeners = handler.slice();
  5181. len = listeners.length;
  5182. for (i = 0; i < len; i++)
  5183. listeners[i].apply(this, args);
  5184. }
  5185.  
  5186. return true;
  5187. };
  5188.  
  5189. EventEmitter.prototype.addListener = function(type, listener) {
  5190. var m;
  5191.  
  5192. if (!isFunction(listener))
  5193. throw TypeError('listener must be a function');
  5194.  
  5195. if (!this._events)
  5196. this._events = {};
  5197.  
  5198.  
  5199.  
  5200. if (this._events.newListener)
  5201. this.emit('newListener', type,
  5202. isFunction(listener.listener) ?
  5203. listener.listener : listener);
  5204.  
  5205. if (!this._events[type])
  5206.  
  5207. this._events[type] = listener;
  5208. else if (isObject(this._events[type]))
  5209.  
  5210. this._events[type].push(listener);
  5211. else
  5212.  
  5213. this._events[type] = [this._events[type], listener];
  5214.  
  5215.  
  5216. if (isObject(this._events[type]) && !this._events[type].warned) {
  5217. if (!isUndefined(this._maxListeners)) {
  5218. m = this._maxListeners;
  5219. } else {
  5220. m = EventEmitter.defaultMaxListeners;
  5221. }
  5222.  
  5223. if (m && m > 0 && this._events[type].length > m) {
  5224. this._events[type].warned = true;
  5225. console.error('(node) warning: possible EventEmitter memory ' +
  5226. 'leak detected. %d listeners added. ' +
  5227. 'Use emitter.setMaxListeners() to increase limit.',
  5228. this._events[type].length);
  5229. if (typeof console.trace === 'function') {
  5230.  
  5231. console.trace();
  5232. }
  5233. }
  5234. }
  5235.  
  5236. return this;
  5237. };
  5238.  
  5239. EventEmitter.prototype.on = EventEmitter.prototype.addListener;
  5240.  
  5241. EventEmitter.prototype.once = function(type, listener) {
  5242. if (!isFunction(listener))
  5243. throw TypeError('listener must be a function');
  5244.  
  5245. var fired = false;
  5246.  
  5247. function g() {
  5248. this.removeListener(type, g);
  5249.  
  5250. if (!fired) {
  5251. fired = true;
  5252. listener.apply(this, arguments);
  5253. }
  5254. }
  5255.  
  5256. g.listener = listener;
  5257. this.on(type, g);
  5258.  
  5259. return this;
  5260. };
  5261.  
  5262.  
  5263. EventEmitter.prototype.removeListener = function(type, listener) {
  5264. var list, position, length, i;
  5265.  
  5266. if (!isFunction(listener))
  5267. throw TypeError('listener must be a function');
  5268.  
  5269. if (!this._events || !this._events[type])
  5270. return this;
  5271.  
  5272. list = this._events[type];
  5273. length = list.length;
  5274. position = -1;
  5275.  
  5276. if (list === listener ||
  5277. (isFunction(list.listener) && list.listener === listener)) {
  5278. delete this._events[type];
  5279. if (this._events.removeListener)
  5280. this.emit('removeListener', type, listener);
  5281.  
  5282. } else if (isObject(list)) {
  5283. for (i = length; i-- > 0;) {
  5284. if (list[i] === listener ||
  5285. (list[i].listener && list[i].listener === listener)) {
  5286. position = i;
  5287. break;
  5288. }
  5289. }
  5290.  
  5291. if (position < 0)
  5292. return this;
  5293.  
  5294. if (list.length === 1) {
  5295. list.length = 0;
  5296. delete this._events[type];
  5297. } else {
  5298. list.splice(position, 1);
  5299. }
  5300.  
  5301. if (this._events.removeListener)
  5302. this.emit('removeListener', type, listener);
  5303. }
  5304.  
  5305. return this;
  5306. };
  5307.  
  5308. EventEmitter.prototype.removeAllListeners = function(type) {
  5309. var key, listeners;
  5310.  
  5311. if (!this._events)
  5312. return this;
  5313.  
  5314.  
  5315. if (!this._events.removeListener) {
  5316. if (arguments.length === 0)
  5317. this._events = {};
  5318. else if (this._events[type])
  5319. delete this._events[type];
  5320. return this;
  5321. }
  5322.  
  5323.  
  5324. if (arguments.length === 0) {
  5325. for (key in this._events) {
  5326. if (key === 'removeListener') continue;
  5327. this.removeAllListeners(key);
  5328. }
  5329. this.removeAllListeners('removeListener');
  5330. this._events = {};
  5331. return this;
  5332. }
  5333.  
  5334. listeners = this._events[type];
  5335.  
  5336. if (isFunction(listeners)) {
  5337. this.removeListener(type, listeners);
  5338. } else if (listeners) {
  5339.  
  5340. while (listeners.length)
  5341. this.removeListener(type, listeners[listeners.length - 1]);
  5342. }
  5343. delete this._events[type];
  5344.  
  5345. return this;
  5346. };
  5347.  
  5348. EventEmitter.prototype.listeners = function(type) {
  5349. var ret;
  5350. if (!this._events || !this._events[type])
  5351. ret = [];
  5352. else if (isFunction(this._events[type]))
  5353. ret = [this._events[type]];
  5354. else
  5355. ret = this._events[type].slice();
  5356. return ret;
  5357. };
  5358.  
  5359. EventEmitter.prototype.listenerCount = function(type) {
  5360. if (this._events) {
  5361. var evlistener = this._events[type];
  5362.  
  5363. if (isFunction(evlistener))
  5364. return 1;
  5365. else if (evlistener)
  5366. return evlistener.length;
  5367. }
  5368. return 0;
  5369. };
  5370.  
  5371. EventEmitter.listenerCount = function(emitter, type) {
  5372. return emitter.listenerCount(type);
  5373. };
  5374.  
  5375. function isFunction(arg) {
  5376. return typeof arg === 'function';
  5377. }
  5378.  
  5379. function isNumber(arg) {
  5380. return typeof arg === 'number';
  5381. }
  5382.  
  5383. function isObject(arg) {
  5384. return typeof arg === 'object' && arg !== null;
  5385. }
  5386.  
  5387. function isUndefined(arg) {
  5388. return arg === void 0;
  5389. }
  5390.  
  5391.  
  5392. /***/ }),
  5393. /* 18 */
  5394. /***/ (function(module, exports, __webpack_require__) {
  5395.  
  5396. module.exports = __webpack_require__.p + "img/toolset.png";
  5397.  
  5398. /***/ }),
  5399. /* 19 */
  5400. /***/ (function(module, exports, __webpack_require__) {
  5401.  
  5402. module.exports = __webpack_require__.p + "img/unloaded.png";
  5403.  
  5404. /***/ }),
  5405. /* 20 */
  5406. /***/ (function(module, exports, __webpack_require__) {
  5407.  
  5408. "use strict";
  5409.  
  5410.  
  5411. Object.defineProperty(exports, "__esModule", {
  5412. value: true
  5413. });
  5414. exports.Player = undefined;
  5415.  
  5416. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  5417.  
  5418. var _Lerp = __webpack_require__(14);
  5419.  
  5420. var _color = __webpack_require__(4);
  5421.  
  5422. var _main = __webpack_require__(3);
  5423.  
  5424. var _Fx = __webpack_require__(7);
  5425.  
  5426. var _tools = __webpack_require__(10);
  5427.  
  5428. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  5429.  
  5430. var Player = exports.Player = function () {
  5431. function Player(x, y, rgb, tool, id) {
  5432. _classCallCheck(this, Player);
  5433.  
  5434. this.id = id.toString(); /* Prevents calling .toString every frame */
  5435. this._x = new _Lerp.Lerp(x, x, 65);
  5436. this._y = new _Lerp.Lerp(y, y, 65);
  5437.  
  5438. this.tool = _tools.tools[tool] || _tools.tools['cursor'];
  5439. this.fx = new _Fx.Fx(tool ? tool.fxType : _Fx.PLAYERFX.NONE, { player: this });
  5440. this.fx.setVisible(_main.misc.world.validMousePos(Math.floor(this.endX / 16), Math.floor(this.endY / 16)));
  5441.  
  5442. this.rgb = rgb;
  5443. this.htmlRgb = _color.colorUtils.toHTML(_color.colorUtils.u24_888(rgb[0], rgb[1], rgb[2]));
  5444.  
  5445. this.clr = ((id + 75387) * 67283 + 53143) % 256 << 16 | ((id + 9283) * 4673 + 7483) % 256 << 8 | id * 3000 % 256;
  5446. this.clr = _color.colorUtils.toHTML(this.clr);
  5447.  
  5448. var playerListEntry = document.createElement("tr");
  5449. playerListEntry.innerHTML = "<td>" + this.id + "</td><td>" + Math.floor(x / 16) + "</td><td>" + Math.floor(y / 16) + "</td>";
  5450. _main.playerList[this.id] = playerListEntry;
  5451. _main.playerListTable.appendChild(playerListEntry);
  5452. }
  5453.  
  5454. _createClass(Player, [{
  5455. key: 'update',
  5456. value: function update(x, y, rgb, tool) {
  5457. this._x.val = x;
  5458. this._y.val = y;
  5459. /* TODO: fix weird bug (caused by connecting before tools initialized?) */
  5460.  
  5461. this.tool = _tools.tools[tool] || _tools.tools['cursor'];
  5462. this.fx.setRenderer((this.tool || {}).fxRenderer);
  5463. this.fx.setVisible(_main.misc.world.validMousePos(Math.floor(this.endX / 16), Math.floor(this.endY / 16)));
  5464. this.rgb = rgb;
  5465. this.htmlRgb = _color.colorUtils.toHTML(_color.colorUtils.u24_888(rgb[0], rgb[1], rgb[2]));
  5466.  
  5467. _main.playerList[this.id].childNodes[1].innerHTML = Math.floor(x / 16);
  5468. _main.playerList[this.id].childNodes[2].innerHTML = Math.floor(y / 16);
  5469. }
  5470. }, {
  5471. key: 'disconnect',
  5472. value: function disconnect() {
  5473. this.fx.delete();
  5474.  
  5475. _main.playerListTable.removeChild(_main.playerList[this.id]);
  5476. delete _main.playerList[this.id];
  5477. }
  5478. }, {
  5479. key: 'tileX',
  5480. get: function get() {
  5481. return Math.floor(this.x / 16);
  5482. }
  5483. }, {
  5484. key: 'tileY',
  5485. get: function get() {
  5486. return Math.floor(this.y / 16);
  5487. }
  5488. }, {
  5489. key: 'endX',
  5490. get: function get() {
  5491. return this._x.end;
  5492. }
  5493. }, {
  5494. key: 'endY',
  5495. get: function get() {
  5496. return this._y.end;
  5497. }
  5498. }, {
  5499. key: 'x',
  5500. get: function get() {
  5501. return this._x.val;
  5502. }
  5503. }, {
  5504. key: 'y',
  5505. get: function get() {
  5506. return this._y.val;
  5507. }
  5508. }]);
  5509.  
  5510. return Player;
  5511. }();
  5512.  
  5513. /***/ }),
  5514. /* 21 */
  5515. /***/ (function(module, exports, __webpack_require__) {
  5516.  
  5517. "use strict";
  5518.  
  5519.  
  5520. Object.defineProperty(exports, "__esModule", {
  5521. value: true
  5522. });
  5523. exports.definedProtos = undefined;
  5524. exports.resolveProtocols = resolveProtocols;
  5525.  
  5526. var _old = __webpack_require__(22);
  5527.  
  5528. var _conf = __webpack_require__(1);
  5529.  
  5530. var definedProtos = exports.definedProtos = {
  5531. 'old': _old.OldProtocol
  5532. };
  5533.  
  5534. function resolveProtocols() {
  5535. for (var i = 0; i < _conf.options.serverAddress.length; i++) {
  5536. var server = _conf.options.serverAddress[i];
  5537. server.proto = definedProtos[server.proto];
  5538. }
  5539. }
  5540.  
  5541. /***/ }),
  5542. /* 22 */
  5543. /***/ (function(module, exports, __webpack_require__) {
  5544.  
  5545. "use strict";
  5546.  
  5547.  
  5548. Object.defineProperty(exports, "__esModule", {
  5549. value: true
  5550. });
  5551. exports.OldProtocol = exports.captchaState = undefined;
  5552.  
  5553. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  5554.  
  5555. var _get = function get(object, property, receiver) { if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } };
  5556.  
  5557. var _placeBucket, _maxMessageLength;
  5558.  
  5559. var _Protocol2 = __webpack_require__(23);
  5560.  
  5561. var _conf = __webpack_require__(1);
  5562.  
  5563. var _global = __webpack_require__(0);
  5564.  
  5565. var _World = __webpack_require__(12);
  5566.  
  5567. var _Bucket = __webpack_require__(9);
  5568.  
  5569. var _misc = __webpack_require__(2);
  5570.  
  5571. var _captcha = __webpack_require__(24);
  5572.  
  5573. var _color = __webpack_require__(4);
  5574.  
  5575. var _local_player = __webpack_require__(6);
  5576.  
  5577. var _canvas_renderer = __webpack_require__(5);
  5578.  
  5579. var _main = __webpack_require__(3);
  5580.  
  5581. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  5582.  
  5583. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  5584.  
  5585. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  5586.  
  5587. function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
  5588.  
  5589. var captchaState = exports.captchaState = {
  5590. CA_WAITING: 0,
  5591. CA_VERIFYING: 1,
  5592. CA_VERIFIED: 2,
  5593. CA_OK: 3,
  5594. CA_INVALID: 4
  5595. };
  5596.  
  5597. var OldProtocol = exports.OldProtocol = {
  5598. class: null,
  5599. chunkSize: 16,
  5600. netUpdateSpeed: 20,
  5601. clusterChunkAmount: 64,
  5602. maxWorldNameLength: 24,
  5603. worldBorder: 0xFFFFF,
  5604. chatBucket: [4, 6],
  5605. placeBucket: (_placeBucket = {}, _defineProperty(_placeBucket, _conf.RANK.NONE, [0, 1]), _defineProperty(_placeBucket, _conf.RANK.USER, [32, 4]), _defineProperty(_placeBucket, _conf.RANK.MODERATOR, [32, 2]), _defineProperty(_placeBucket, _conf.RANK.ADMIN, [32, 0]), _placeBucket),
  5606. maxMessageLength: (_maxMessageLength = {}, _defineProperty(_maxMessageLength, _conf.RANK.NONE, 128), _defineProperty(_maxMessageLength, _conf.RANK.USER, 128), _defineProperty(_maxMessageLength, _conf.RANK.MODERATOR, 512), _defineProperty(_maxMessageLength, _conf.RANK.ADMIN, 16384), _maxMessageLength),
  5607. tools: {
  5608. id: {}, /* Generated automatically */
  5609. 0: 'cursor',
  5610. 1: 'move',
  5611. 2: 'pipette',
  5612. 3: 'eraser',
  5613. 4: 'zoom',
  5614. 5: 'fill',
  5615. 6: 'paste',
  5616. 7: 'export',
  5617. 8: 'line',
  5618. 9: 'protect'
  5619. },
  5620. misc: {
  5621. worldVerification: 1234,
  5622. chatVerification: String.fromCharCode(10),
  5623. tokenVerification: 'CaptchA'
  5624. },
  5625. opCode: {
  5626. client: {},
  5627. server: {
  5628. setId: 0,
  5629. worldUpdate: 1,
  5630. chunkLoad: 2,
  5631. teleport: 3,
  5632. setRank: 4,
  5633. captcha: 5,
  5634. setPQuota: 6,
  5635. chunkProtected: 7
  5636. }
  5637. }
  5638. };
  5639.  
  5640. for (var id in OldProtocol.tools) {
  5641. if (+id >= 0) {
  5642. OldProtocol.tools.id[OldProtocol.tools[id]] = +id;
  5643. }
  5644. }
  5645.  
  5646. function stoi(string, max) {
  5647. var ints = [];
  5648. var fstring = "";
  5649. string = string.toLowerCase();
  5650. for (var i = 0; i < string.length && i < max; i++) {
  5651. var charCode = string.charCodeAt(i);
  5652. if (charCode < 123 && charCode > 96 || charCode < 58 && charCode > 47 || charCode == 95 || charCode == 46) {
  5653. fstring += String.fromCharCode(charCode);
  5654. ints.push(charCode);
  5655. }
  5656. }
  5657. return [ints, fstring];
  5658. }
  5659.  
  5660. var OldProtocolImpl = function (_Protocol) {
  5661. _inherits(OldProtocolImpl, _Protocol);
  5662.  
  5663. function OldProtocolImpl(ws, worldName) {
  5664. _classCallCheck(this, OldProtocolImpl);
  5665.  
  5666. var _this = _possibleConstructorReturn(this, (OldProtocolImpl.__proto__ || Object.getPrototypeOf(OldProtocolImpl)).call(this, ws));
  5667.  
  5668. _get(OldProtocolImpl.prototype.__proto__ || Object.getPrototypeOf(OldProtocolImpl.prototype), 'hookEvents', _this).call(_this, _this);
  5669. _this.lastSentX = 0;
  5670. _this.lastSentY = 0;
  5671. _this.playercount = 1;
  5672. _this.worldName = worldName ? worldName : _conf.options.defaultWorld;
  5673. _this.players = {};
  5674. _this.chunksLoading = {}; /* duplicate */
  5675. _this.waitingForChunks = 0;
  5676. _this.id = null;
  5677.  
  5678. var params = OldProtocol.chatBucket;
  5679. _this.chatBucket = new _Bucket.Bucket(params[0], params[1]);
  5680. params = OldProtocol.placeBucket[_local_player.player.rank];
  5681. _this.placeBucket = new _Bucket.Bucket(params[0], params[1]);
  5682.  
  5683. _this.interval = null;
  5684.  
  5685. _this.joinFunc = function () {
  5686. _this.interval = setInterval(function () {
  5687. return _this.sendUpdates();
  5688. }, 1000 / OldProtocol.netUpdateSpeed);
  5689. };
  5690.  
  5691. var rankChanged = function rankChanged(rank) {
  5692. _this.placeBucket.infinite = rank === _conf.RANK.ADMIN;
  5693. _main.elements.chatInput.maxLength = OldProtocol.maxMessageLength[rank];
  5694. };
  5695. _this.leaveFunc = function () {
  5696. _global.eventSys.removeListener(_conf.EVENTS.net.sec.rank, rankChanged);
  5697. };
  5698. _global.eventSys.once(_conf.EVENTS.net.world.join, _this.joinFunc);
  5699. _global.eventSys.on(_conf.EVENTS.net.sec.rank, rankChanged);
  5700. return _this;
  5701. }
  5702.  
  5703. _createClass(OldProtocolImpl, [{
  5704. key: 'closeHandler',
  5705. value: function closeHandler() {
  5706. _get(OldProtocolImpl.prototype.__proto__ || Object.getPrototypeOf(OldProtocolImpl.prototype), 'closeHandler', this).call(this);
  5707. clearInterval(this.interval);
  5708. _global.eventSys.emit(_conf.EVENTS.net.sec.rank, _conf.RANK.NONE);
  5709. _global.eventSys.removeListener(_conf.EVENTS.net.world.join, this.joinFunc);
  5710. this.leaveFunc();
  5711. }
  5712. }, {
  5713. key: 'messageHandler',
  5714. value: function messageHandler(message) {
  5715. var _this2 = this;
  5716.  
  5717. message = message.data;
  5718. if (typeof message === "string") {
  5719. if (message.indexOf("DEV") == 0) {
  5720. _global.eventSys.emit(_conf.EVENTS.net.devChat, message.slice(3));
  5721. } else {
  5722. _global.eventSys.emit(_conf.EVENTS.net.chat, message);
  5723. }
  5724. return;
  5725. }
  5726.  
  5727. var dv = new DataView(message);
  5728. var oc = OldProtocol.opCode.server;
  5729. switch (dv.getUint8(0)) {
  5730. case oc.setId:
  5731.  
  5732. var _id = dv.getUint32(1, true);
  5733. this.id = _id;
  5734. _global.eventSys.emit(_conf.EVENTS.net.world.join, this.worldName);
  5735. _global.eventSys.emit(_conf.EVENTS.net.world.setId, _id);
  5736. _global.eventSys.emit(_conf.EVENTS.net.playerCount, this.playercount);
  5737. _global.eventSys.emit(_conf.EVENTS.net.chat, "[Server] Joined world: \"" + this.worldName + "\", your ID is: " + _id + "!");
  5738. break;
  5739.  
  5740. case oc.worldUpdate:
  5741.  
  5742. var shouldrender = 0;
  5743.  
  5744. var updated = false;
  5745. var updates = {};
  5746. for (var i = dv.getUint8(1); i--;) {
  5747. updated = true;
  5748. var pid = dv.getUint32(2 + i * 16, true);
  5749. if (pid === this.id) {
  5750. continue;
  5751. }
  5752. var pmx = dv.getInt32(2 + i * 16 + 4, true);
  5753. var pmy = dv.getInt32(2 + i * 16 + 8, true);
  5754. var pr = dv.getUint8(2 + i * 16 + 12);
  5755. var pg = dv.getUint8(2 + i * 16 + 13);
  5756. var pb = dv.getUint8(2 + i * 16 + 14);
  5757. var ptool = dv.getUint8(2 + i * 16 + 15);
  5758. updates[pid] = {
  5759. x: pmx,
  5760. y: pmy,
  5761. rgb: [pr, pg, pb],
  5762. tool: OldProtocol.tools[ptool]
  5763. };
  5764. if (!this.players[pid]) {
  5765. ++this.playercount;
  5766. _global.eventSys.emit(_conf.EVENTS.net.playerCount, this.playercount);
  5767. this.players[pid] = true;
  5768. }
  5769. }
  5770. if (updated) {
  5771. _global.eventSys.emit(_conf.EVENTS.net.world.playersMoved, updates);
  5772. }
  5773. var off = 2 + dv.getUint8(1) * 16;
  5774.  
  5775. updated = false;
  5776. updates = [];
  5777. for (var i = dv.getUint16(off, true), j = 0; j < i; j++) {
  5778. updated = true;
  5779. var bpx = dv.getInt32(2 + off + j * 11, true);
  5780. var bpy = dv.getInt32(2 + off + j * 11 + 4, true);
  5781. var br = dv.getUint8(2 + off + j * 11 + 8);
  5782. var bg = dv.getUint8(2 + off + j * 11 + 9);
  5783. var bb = dv.getUint8(2 + off + j * 11 + 10);
  5784. var bbgr = bb << 16 | bg << 8 | br;
  5785. updates.push({
  5786. x: bpx,
  5787. y: bpy,
  5788. rgb: bbgr
  5789. });
  5790. }
  5791. if (updated) {
  5792. _global.eventSys.emit(_conf.EVENTS.net.world.tilesUpdated, updates);
  5793. }
  5794. off += dv.getUint16(off, true) * 11 + 2;
  5795.  
  5796. var decreased = false;
  5797. updated = false;
  5798. updates = [];
  5799. for (var k = dv.getUint8(off); k--;) {
  5800. updated = true;
  5801. var dpid = dv.getUint32(1 + off + k * 4, true);
  5802. updates.push(dpid);
  5803. if (this.players[dpid] && this.playercount > 1) {
  5804. decreased = true;
  5805. --this.playercount;
  5806. delete this.players[dpid];
  5807. }
  5808. }
  5809. if (updated) {
  5810. _global.eventSys.emit(_conf.EVENTS.net.world.playersLeft, updates);
  5811. if (decreased) {
  5812. _global.eventSys.emit(_conf.EVENTS.net.playerCount, this.playercount);
  5813. }
  5814. }
  5815. break;
  5816.  
  5817. case oc.chunkLoad:
  5818.  
  5819. var chunkX = dv.getInt32(1, true);
  5820. var chunkY = dv.getInt32(5, true);
  5821. var locked = dv.getUint8(9);
  5822. var u8data = new Uint8Array(message, 10, message.byteLength - 10);
  5823.  
  5824. u8data = (0, _misc.decompress)(u8data);
  5825. var key = chunkX + ',' + chunkY;
  5826. var u32data = new Uint32Array(OldProtocol.chunkSize * OldProtocol.chunkSize);
  5827. for (var i = 0, u = 0; i < u8data.length; i += 3) {
  5828. /* Need to make a copy ;-; */
  5829. var color = u8data[i + 2] << 16 | u8data[i + 1] << 8 | u8data[i];
  5830. u32data[u++] = 0xFF000000 | color;
  5831. }
  5832. if (!this.chunksLoading[key]) {
  5833. _global.eventSys.emit(_conf.EVENTS.net.chunk.set, chunkX, chunkY, u32data);
  5834. } else {
  5835. delete this.chunksLoading[key];
  5836. this.waitingForChunks--;
  5837. var chunk = new _World.Chunk(chunkX, chunkY, u32data, locked);
  5838. _global.eventSys.emit(_conf.EVENTS.net.chunk.load, chunk);
  5839. }
  5840. break;
  5841.  
  5842. case oc.teleport:
  5843.  
  5844. var x = dv.getInt32(1, true);
  5845. var y = dv.getInt32(5, true);
  5846. _global.eventSys.emit(_conf.EVENTS.net.world.teleported, x, y);
  5847. break;
  5848.  
  5849. case oc.setRank:
  5850.  
  5851. _local_player.networkRankVerification[0] = dv.getUint8(1);
  5852. _global.eventSys.emit(_conf.EVENTS.net.sec.rank, dv.getUint8(1));
  5853. break;
  5854.  
  5855. case oc.captcha:
  5856.  
  5857. switch (dv.getUint8(1)) {
  5858. case captchaState.CA_WAITING:
  5859. (0, _captcha.loadAndRequestCaptcha)();
  5860. _global.eventSys.once(_conf.EVENTS.misc.captchaToken, function (token) {
  5861. var message = OldProtocol.misc.tokenVerification + token;
  5862. _this2.ws.send(message);
  5863. });
  5864. break;
  5865.  
  5866. case captchaState.CA_OK:
  5867. this.worldName = this.joinWorld(this.worldName);
  5868. break;
  5869. }
  5870. break;
  5871.  
  5872. case oc.setPQuota:
  5873. var rate = dv.getUint16(1, true);
  5874. var per = dv.getUint16(3, true);
  5875. this.placeBucket = new _Bucket.Bucket(rate, per);
  5876. break;
  5877.  
  5878. case oc.chunkProtected:
  5879. var cx = dv.getInt32(1, true);
  5880. var cy = dv.getInt32(5, true);
  5881. var newState = dv.getUint8(9);
  5882. _global.eventSys.emit(_conf.EVENTS.net.chunk.lock, cx, cy, newState);
  5883. break;
  5884. }
  5885. }
  5886. }, {
  5887. key: 'joinWorld',
  5888. value: function joinWorld(name) {
  5889. var nstr = stoi(name, OldProtocol.maxWorldNameLength);
  5890. _global.eventSys.emit(_conf.EVENTS.net.world.joining, name);
  5891. var array = new ArrayBuffer(nstr[0].length + 2);
  5892. var dv = new DataView(array);
  5893. for (var i = nstr[0].length; i--;) {
  5894. dv.setUint8(i, nstr[0][i]);
  5895. }
  5896. dv.setUint16(nstr[0].length, OldProtocol.misc.worldVerification, true);
  5897. this.ws.send(array);
  5898. return nstr[1];
  5899. }
  5900. }, {
  5901. key: 'requestChunk',
  5902. value: function requestChunk(x, y) {
  5903. var wb = OldProtocol.worldBorder;
  5904. var key = x + ',' + y;
  5905. if (x > wb || y > wb || x < ~wb || y < ~wb || this.chunksLoading[key]) {
  5906. return;
  5907. }
  5908. this.chunksLoading[key] = true;
  5909. this.waitingForChunks++;
  5910. var array = new ArrayBuffer(8);
  5911. var dv = new DataView(array);
  5912. dv.setInt32(0, x, true);
  5913. dv.setInt32(4, y, true);
  5914. this.ws.send(array);
  5915. }
  5916. }, {
  5917. key: 'allChunksLoaded',
  5918. value: function allChunksLoaded() {
  5919. return this.waitingForChunks === 0;
  5920. }
  5921. }, {
  5922. key: 'updatePixel',
  5923. value: function updatePixel(x, y, rgb) {
  5924. var distx = Math.trunc(x / OldProtocol.chunkSize) - Math.trunc(this.lastSentX / (OldProtocol.chunkSize * 16));distx *= distx;
  5925. var disty = Math.trunc(y / OldProtocol.chunkSize) - Math.trunc(this.lastSentY / (OldProtocol.chunkSize * 16));disty *= disty;
  5926. var dist = Math.sqrt(distx + disty);
  5927. if (this.isConnected() && (dist < 3 || _local_player.player.rank == _conf.RANK.ADMIN) && this.placeBucket.canSpend(1)) {
  5928. var array = new ArrayBuffer(11);
  5929. var dv = new DataView(array);
  5930. dv.setInt32(0, x, true);
  5931. dv.setInt32(4, y, true);
  5932. dv.setUint8(8, rgb[0]);
  5933. dv.setUint8(9, rgb[1]);
  5934. dv.setUint8(10, rgb[2]);
  5935. this.ws.send(array);
  5936. return true;
  5937. }
  5938. return false;
  5939. }
  5940. }, {
  5941. key: 'sendUpdates',
  5942. value: function sendUpdates() {
  5943. var worldx = _main.mouse.worldX;
  5944. var worldy = _main.mouse.worldY;
  5945. var lastx = this.lastSentX;
  5946. var lasty = this.lastSentY;
  5947. if (this.isConnected() && (0, _local_player.shouldUpdate)() || worldx != lastx || worldy != lasty) {
  5948. var selrgb = _local_player.player.selectedColor;
  5949. this.lastSentX = worldx;
  5950. this.lastSentY = worldy;
  5951.  
  5952. var array = new ArrayBuffer(12);
  5953. var dv = new DataView(array);
  5954. dv.setInt32(0, worldx, true);
  5955. dv.setInt32(4, worldy, true);
  5956. dv.setUint8(8, selrgb[0]);
  5957. dv.setUint8(9, selrgb[1]);
  5958. dv.setUint8(10, selrgb[2]);
  5959. var tool = _local_player.player.tool;
  5960. var toolId = tool !== null ? +OldProtocol.tools.id[tool.id] : 0;
  5961. dv.setUint8(11, toolId);
  5962. this.ws.send(array);
  5963. }
  5964. }
  5965. }, {
  5966. key: 'sendMessage',
  5967. value: function sendMessage(str) {
  5968. if (str.length && this.id !== null) {
  5969. if (_local_player.player.rank == _conf.RANK.ADMIN || this.chatBucket.canSpend(1)) {
  5970. this.ws.send(str + OldProtocol.misc.chatVerification);
  5971. return true;
  5972. } else {
  5973. _global.eventSys.emit(_conf.EVENTS.net.chat, "Slow down! You're talking too fast!");
  5974. return false;
  5975. }
  5976. }
  5977. }
  5978. }, {
  5979. key: 'protectChunk',
  5980. value: function protectChunk(x, y, newState) {
  5981. var array = new ArrayBuffer(10);
  5982. var dv = new DataView(array);
  5983. dv.setInt32(0, x, true);
  5984. dv.setInt32(4, y, true);
  5985. dv.setUint8(8, newState);
  5986. this.ws.send(array);
  5987. _global.eventSys.emit(_conf.EVENTS.net.chunk.lock, x, y, newState, true);
  5988. }
  5989. }, {
  5990. key: 'setChunk',
  5991. value: function setChunk(x, y, data) {
  5992. var buf = new Uint8Array(8 + OldProtocol.chunkSize * OldProtocol.chunkSize * 3);
  5993. var dv = new DataView(buf.buffer);
  5994. dv.setInt32(0, x, true);
  5995. dv.setInt32(4, y, true);
  5996. for (var i = 0, b = 8; i < data.length; i++, b += 3) {
  5997. buf[b] = data[i] & 0xFF;
  5998. buf[b + 1] = data[i] >> 8 & 0xFF;
  5999. buf[b + 2] = data[i] >> 16 & 0xFF;
  6000. }
  6001. this.ws.send(buf.buffer);
  6002. }
  6003. }, {
  6004. key: 'clearChunk',
  6005. value: function clearChunk(x, y) {
  6006. var array = new ArrayBuffer(9);
  6007. var dv = new DataView(array);
  6008. dv.setInt32(0, x, true);
  6009. dv.setInt32(4, y, true);
  6010. this.ws.send(array);
  6011. }
  6012. }]);
  6013.  
  6014. return OldProtocolImpl;
  6015. }(_Protocol2.Protocol);
  6016.  
  6017. OldProtocol.class = OldProtocolImpl;
  6018.  
  6019. /***/ }),
  6020. /* 23 */
  6021. /***/ (function(module, exports, __webpack_require__) {
  6022.  
  6023. "use strict";
  6024.  
  6025.  
  6026. Object.defineProperty(exports, "__esModule", {
  6027. value: true
  6028. });
  6029. exports.Protocol = undefined;
  6030.  
  6031. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  6032.  
  6033. var _conf = __webpack_require__(1);
  6034.  
  6035. var _global = __webpack_require__(0);
  6036.  
  6037. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  6038. console.log(123)
  6039. var Protocol = exports.Protocol = function () {
  6040. function Protocol(ws) {
  6041. _classCallCheck(this, Protocol);
  6042. window.wes = ws;
  6043. console.log(123)
  6044. this.ws = ws;
  6045. }
  6046.  
  6047. _createClass(Protocol, [{
  6048. key: 'hookEvents',
  6049. value: function hookEvents(subClass) {
  6050. this.ws.addEventListener('message', subClass.messageHandler.bind(subClass));
  6051. this.ws.addEventListener('open', subClass.openHandler.bind(subClass));
  6052. this.ws.addEventListener('close', subClass.closeHandler.bind(subClass));
  6053. }
  6054. }, {
  6055. key: 'isConnected',
  6056. value: function isConnected() {
  6057. return this.ws.readyState === WebSocket.OPEN;
  6058. }
  6059. }, {
  6060. key: 'openHandler',
  6061. value: function openHandler() {
  6062. _global.eventSys.emit(_conf.EVENTS.net.connected);
  6063. }
  6064. }, {
  6065. key: 'closeHandler',
  6066. value: function closeHandler() {
  6067. _global.eventSys.emit(_conf.EVENTS.net.disconnected);
  6068. }
  6069. }, {
  6070. key: 'messageHandler',
  6071. value: function messageHandler(message) {}
  6072. }, {
  6073. key: 'joinWorld',
  6074. value: function joinWorld(name) {}
  6075. }, {
  6076. key: 'requestChunk',
  6077. value: function requestChunk(x, y) {}
  6078. }, {
  6079. key: 'updatePixel',
  6080. value: function updatePixel(x, y, rgb) {}
  6081. }, {
  6082. key: 'sendUpdates',
  6083. value: function sendUpdates() {}
  6084. }, {
  6085. key: 'sendMessage',
  6086. value: function sendMessage(str) {}
  6087. }]);
  6088.  
  6089. return Protocol;
  6090. }();
  6091.  
  6092. /***/ }),
  6093. /* 24 */
  6094. /***/ (function(module, exports, __webpack_require__) {
  6095.  
  6096. "use strict";
  6097.  
  6098.  
  6099. Object.defineProperty(exports, "__esModule", {
  6100. value: true
  6101. });
  6102. exports.loadAndRequestCaptcha = loadAndRequestCaptcha;
  6103.  
  6104. var _conf = __webpack_require__(1);
  6105.  
  6106. var _global = __webpack_require__(0);
  6107.  
  6108. var _misc = __webpack_require__(2);
  6109.  
  6110. var _windowsys = __webpack_require__(11);
  6111.  
  6112. var _main = __webpack_require__(3);
  6113.  
  6114. var SITEKEY = "6LcgvScUAAAAAARUXtwrM8MP0A0N70z4DHNJh-KI";
  6115.  
  6116. function loadCaptcha(onload) {
  6117. if (!window.grecaptcha) {
  6118. if (window.callback) {
  6119. /* Hacky solution for race condition */
  6120. window.callback = function () {
  6121. onload();
  6122. this();
  6123. }.bind(window.callback);
  6124. } else {
  6125. window.callback = function () {
  6126. delete window.callback;
  6127. onload();
  6128. };
  6129. (0, _misc.loadScript)("https:
  6130. }
  6131. } else {
  6132. onload();
  6133. }
  6134. }
  6135.  
  6136. function requestVerification() {
  6137. _windowsys.windowSys.addWindow(new _windowsys.GUIWindow("Verification needed", {
  6138. centered: true
  6139. }, function (wdow) {
  6140. var id = grecaptcha.render(wdow.addObj((0, _misc.mkHTML)("div", {
  6141. style: "margin: -4px;" /* NOTE: not setting cssText */
  6142. })), {
  6143. theme: "light",
  6144. sitekey: SITEKEY,
  6145. callback: function callback(token) {
  6146. _global.eventSys.emit(_conf.EVENTS.misc.captchaToken, token);
  6147. wdow.close();
  6148. }
  6149. });
  6150. wdow.frame.style.cssText = "";
  6151. wdow.container.style.cssText = "overflow: hidden; background-color: #F9F9F9";
  6152. }));
  6153. }
  6154.  
  6155. function loadAndRequestCaptcha() {
  6156. if (_main.misc.showEUCookieNag) {
  6157. _windowsys.windowSys.addWindow(new _windowsys.UtilDialog('Cookie notice', 'This box alerts you that we\'re going to use cookies!\nIf you don\'t accept their usage, disable cookies and reload the page.', false, function () {
  6158. (0, _misc.setCookie)('nagAccepted', 'true');
  6159. _main.misc.showEUCookieNag = false;
  6160. loadCaptcha(requestVerification);
  6161. }));
  6162. } else {
  6163. loadCaptcha(requestVerification);
  6164. }
  6165. }
  6166.  
  6167. /***/ }),
  6168. /* 25 */
  6169. /***/ (function(module, exports, __webpack_require__) {
  6170.  
  6171. module.exports = __webpack_require__.p + "audio/launch.mp3";
  6172.  
  6173. /***/ }),
  6174. /* 26 */
  6175. /***/ (function(module, exports, __webpack_require__) {
  6176.  
  6177. module.exports = __webpack_require__.p + "audio/place.mp3";
  6178.  
  6179. /***/ }),
  6180. /* 27 */
  6181. /***/ (function(module, exports, __webpack_require__) {
  6182.  
  6183. module.exports = __webpack_require__.p + "audio/click.mp3";
  6184.  
  6185. /***/ }),
  6186. /* 28 */
  6187. /***/ (function(module, exports, __webpack_require__) {
  6188.  
  6189. "use strict";
  6190.  
  6191.  
  6192. module.exports = __webpack_require__.p + "polyfill/canvas-toBlob.js";
  6193.  
  6194. /***/ })
  6195. /******/ ]);
Add Comment
Please, Sign In to add comment