c200814.js 73 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353
  1. clearSaveState();
  2. var gameState=0;
  3. function Block(a, b, d, c, e) {
  4. this.settled = void 0 === e ? 0 : 1;
  5. this.height = settings.blockHeight;
  6. this.fallingLane = a;
  7. this.checked = 0;
  8. this.angle = 90 - (30 + 60 * a);
  9. this.angularVelocity = 0;
  10. this.targetAngle = this.angle;
  11. this.color = b;
  12. this.tint = this.removed = this.deleted = 0;
  13. this.initializing = this.opacity = 1;
  14. this.ict = MainHex.ct;
  15. this.iter = d;
  16. this.initLen = settings.creationDt;
  17. this.attachedLane = 0;
  18. this.distFromHex = c || settings.startDist * settings.scale;
  19. this.incrementOpacity = function() {
  20. if (this.deleted) {
  21. if (.925 <= this.opacity) {
  22. for (var b =
  23. this.attachedLane - MainHex.position, b = MainHex.sides - b; 0 > b;) b += MainHex.sides;
  24. b %= MainHex.sides;
  25. MainHex.shakes.push({
  26. lane: b,
  27. magnitude: 3 * (window.devicePixelRatio ? window.devicePixelRatio : 1) * settings.scale
  28. })
  29. }
  30. this.opacity -= .075;
  31. 0 >= this.opacity && (this.opacity = 0, this.deleted = 2, 1 != gameState && 0 != gameState || localStorage.setItem("saveState", exportSaveState()))
  32. }
  33. };
  34. this.getIndex = function() {
  35. for (var b = MainHex.blocks[this.attachedLane], a = 0; a < b.length; a++)
  36. if (b[a] == this) return a
  37. };
  38. this.draw = function(b, a) {
  39. this.height = settings.blockHeight;
  40. 1E-9 < Math.abs(settings.scale - settings.prevScale) && (this.distFromHex *= settings.scale / settings.prevScale);
  41. this.incrementOpacity();
  42. this.angle > this.targetAngle ? this.angularVelocity -= angularVelocityConst : this.angle < this.targetAngle && (this.angularVelocity += angularVelocityConst);
  43. Math.abs(this.angle - this.targetAngle + this.angularVelocity) <= Math.abs(this.angularVelocity) ? (this.angle = this.targetAngle, this.angularVelocity = 0) : this.angle += this.angularVelocity;
  44. this.width = 2 * this.distFromHex / Math.sqrt(3);
  45. this.widthWide =
  46. 2 * (this.distFromHex + this.height) / Math.sqrt(3);
  47. var d, c, e, v;
  48. this.initializing ? (v = (MainHex.ct - this.ict) / this.initLen, d = rotatePoint(-this.width / 2 * v, this.height / 2, this.angle), c = rotatePoint(this.width / 2 * v, this.height / 2, this.angle), e = rotatePoint(this.widthWide / 2 * v, -this.height / 2, this.angle), v = rotatePoint(-this.widthWide / 2 * v, -this.height / 2, this.angle), MainHex.ct - this.ict >= this.initLen && (this.initializing = 0)) : (d = rotatePoint(-this.width / 2, this.height / 2, this.angle), c = rotatePoint(this.width / 2, this.height / 2, this.angle),
  49. e = rotatePoint(this.widthWide / 2, -this.height / 2, this.angle), v = rotatePoint(-this.widthWide / 2, -this.height / 2, this.angle));
  50. this.deleted ? ctx.fillStyle = "#FFF" : 0 === gameState ? "r" == this.color.charAt(0) ? ctx.fillStyle = rgbColorsToTintedColors[this.color] : ctx.fillStyle = hexColorsToTintedColors[this.color] : ctx.fillStyle = this.color;
  51. ctx.globalAlpha = this.opacity;
  52. var w = trueCanvas.width / 2 + Math.sin(Math.PI / 180 * this.angle) * (this.distFromHex + this.height / 2) + gdx,
  53. n = trueCanvas.height / 2 - Math.cos(Math.PI / 180 * this.angle) * (this.distFromHex +
  54. this.height / 2) + gdy;
  55. ctx.beginPath();
  56. ctx.moveTo(w + d.x, n + d.y);
  57. ctx.lineTo(w + c.x, n + c.y);
  58. ctx.lineTo(w + e.x, n + e.y);
  59. ctx.lineTo(w + v.x, n + v.y);
  60. ctx.closePath();
  61. ctx.fill();
  62. this.tint && (1 > this.opacity && (1 != gameState && 0 != gameState || localStorage.setItem("saveState", exportSaveState()), this.iter = 2.25, this.tint = 0), ctx.fillStyle = "#FFF", ctx.globalAlpha = this.tint, ctx.beginPath(), ctx.moveTo(w + d.x, n + d.y), ctx.lineTo(w + c.x, n + c.y), ctx.lineTo(w + e.x, n + e.y), ctx.lineTo(w + v.x, n + v.y), ctx.lineTo(w + d.x, n + d.y), ctx.closePath(), ctx.fill(),
  63. this.tint -= .02, 0 > this.tint && (this.tint = 0));
  64. ctx.globalAlpha = 1
  65. }
  66. }
  67. function findCenterOfBlocks(a) {
  68. for (var b = 0, d = 0, c = 0; c < a.length; c++) {
  69. for (var b = b + a[c].distFromHex, e = a[c].angle; 0 > e;) e += 360;
  70. d += e % 360
  71. }
  72. b /= a.length;
  73. d /= a.length;
  74. return {
  75. x: trueCanvas.width / 2 + Math.cos(Math.PI / 180 * d) * b,
  76. y: trueCanvas.height / 2 + Math.sin(Math.PI / 180 * d) * b
  77. }
  78. };
  79. function search(a, b) {
  80. for (var d = 0; d < a.length; d++)
  81. if (a[d][0] == b[0] && a[d][1] == b[1]) return !0;
  82. return !1
  83. }
  84. function floodFill(a, b, d, c) {
  85. if (void 0 !== a.blocks[b] && void 0 !== a.blocks[b][d])
  86. for (var e = a.blocks[b][d].color, f = -1; 2 > f; f++)
  87. for (var h = -1; 2 > h; h++)
  88. if (Math.abs(f) != Math.abs(h)) {
  89. var q = (b + f + a.sides) % a.sides,
  90. u = d + h;
  91. void 0 !== a.blocks[q] && void 0 !== a.blocks[q][u] && a.blocks[q][u].color == e && !1 === search(c, [q, u]) && 0 === a.blocks[q][u].deleted && (c.push([q, u]), floodFill(a, q, u, c))
  92. }
  93. }
  94. function consolidateBlocks(a, b, d) {
  95. var c = [],
  96. e = [],
  97. f = [];
  98. e.push([b, d]);
  99. floodFill(a, b, d, e);
  100. if (!(3 > e.length)) {
  101. for (b = 0; b < e.length; b++) d = e[b], void 0 !== d && 2 == d.length && (-1 == c.indexOf(d[0]) && c.push(d[0]), a.blocks[d[0]][d[1]].deleted = 1, f.push(a.blocks[d[0]][d[1]]));
  102. c = MainHex.ct;
  103. c - a.lastCombo < settings.comboTime ? (settings.comboTime = 1 / settings.creationSpeedModifier * (waveone.nextGen / 16.666667) * 3, a.comboMultiplier += 1, a.lastCombo = c, c = findCenterOfBlocks(f), a.texts.push(new Text(c.x, c.y, "x " + a.comboMultiplier.toString(),
  104. "bold Q", "#fff", fadeUpAndOut))) : (settings.comboTime = 240, a.lastCombo = c, a.comboMultiplier = 1);
  105. e = e.length * e.length * a.comboMultiplier;
  106. a.texts.push(new Text(a.x, a.y, "+ " + e.toString(), "bold Q ", f[0].color, fadeUpAndOut));
  107. a.lastColorScored = f[0].color;
  108. score += e
  109. }
  110. };
  111. function drawTimer() {
  112. if (1 == gameState) {
  113. var a = [],
  114. b = [];
  115. if (MainHex.ct - MainHex.lastCombo < settings.comboTime)
  116. for (var d = 0; 6 > d; d++) {
  117. var c = MainHex.ct - MainHex.lastCombo;
  118. if (c < 1 / 6 * (5 - d) * settings.comboTime) a.push(calcSide(d, d + 1, 1, 1)), b.push(calcSide(12 - d, 11 - d, 1, 1));
  119. else {
  120. a.push(calcSide(d, d + 1, 1 - 6 * c / settings.comboTime % 1, 1));
  121. b.push(calcSide(12 - d, 11 - d, 1 - 6 * c / settings.comboTime % 1, 1));
  122. break
  123. }
  124. }
  125. 0 !== b.length && drawSide(b);
  126. 0 !== a.length && drawSide(a)
  127. }
  128. }
  129. function calcSide(a, b, d, c) {
  130. a = (a + c) % 12;
  131. b = (b + c) % 12;
  132. ctx.globalAlpha = 1;
  133. ctx.beginPath();
  134. ctx.lineCap = "round";
  135. c = settings.rows * settings.blockHeight * (2 / Math.sqrt(3)) + settings.hexWidth;
  136. var e = c / 2,
  137. f = c * (Math.sqrt(3) / 2);
  138. c = [
  139. [3 * e / 2, f / 2],
  140. [c, 0],
  141. [3 * e / 2, -f / 2],
  142. [e, -f],
  143. [0, -f],
  144. [-e, -f],
  145. [-(3 * e) / 2, -f / 2],
  146. [-c, 0],
  147. [-(3 * e) / 2, f / 2],
  148. [-e, f],
  149. [0, f],
  150. [e, f]
  151. ].reverse();
  152. e = trueCanvas.width / 2 + c[a][0];
  153. a = trueCanvas.height / 2 + c[a][1];
  154. return [[e, a], [(trueCanvas.width / 2 + c[b][0] - e) * d + e, (trueCanvas.height / 2 + c[b][1] - a) * d + a]]
  155. }
  156. function drawSide(a) {
  157. ctx.strokeStyle = 0 === gameState ? hexColorsToTintedColors[MainHex.lastColorScored] : MainHex.lastColorScored;
  158. ctx.lineWidth = 4 * settings.scale;
  159. ctx.moveTo(a[0][0][0], a[0][0][1]);
  160. ctx.lineTo(a[0][1][0], a[0][1][1]);
  161. for (var b = 1; b < a.length; b++) ctx.lineTo(a[b][1][0], a[b][1][1]), ctx.moveTo(a[b][1][0], a[b][1][1]);
  162. ctx.closePath();
  163. ctx.fill();
  164. ctx.stroke()
  165. };
  166. function Hex(a) {
  167. this.playThrough = 0;
  168. this.fillColor = [44, 62, 80];
  169. this.tempColor = [44, 62, 80];
  170. this.dy = this.position = this.angularVelocity = 0;
  171. this.sides = 6;
  172. this.blocks = [];
  173. this.targetAngle = this.angle = 180 / this.sides;
  174. this.shakes = [];
  175. this.sideLength = a;
  176. this.strokeColor = "blue";
  177. this.x = trueCanvas.width / 2;
  178. this.y = trueCanvas.height / 2;
  179. this.ct = 0;
  180. this.lastCombo = this.ct - settings.comboTime;
  181. this.lastColorScored = "#000";
  182. this.comboTime = 1;
  183. this.texts = [];
  184. this.lastRotate = Date.now();
  185. for (a = 0; a < this.sides; a++) this.blocks.push([]);
  186. this.shake =
  187. function(b) {
  188. var a = 30 + 60 * b.lane,
  189. a = Math.PI / 180 * a,
  190. c = Math.cos(a) * b.magnitude,
  191. a = Math.sin(a) * b.magnitude;
  192. gdx -= c;
  193. gdy += a;
  194. b.magnitude /= 2;
  195. if (1 > b.magnitude)
  196. for (c = 0; c < this.shakes.length; c++) this.shakes[c] == b && this.shakes.splice(c, 1)
  197. };
  198. this.addBlock = function(b) {
  199. if (1 == gameState || 0 === gameState) {
  200. b.settled = 1;
  201. b.tint = .6;
  202. var a = this.sides - b.fallingLane;
  203. this.shakes.push({
  204. lane: b.fallingLane,
  205. magnitude: 4.5 * (window.devicePixelRatio ? window.devicePixelRatio : 1) * settings.scale
  206. });
  207. a += this.position;
  208. a = (a + this.sides) % this.sides;
  209. b.distFromHex =
  210. MainHex.sideLength / 2 * Math.sqrt(3) + b.height * this.blocks[a].length;
  211. this.blocks[a].push(b);
  212. b.attachedLane = a;
  213. b.checked = 1
  214. }
  215. };
  216. this.doesBlockCollide = function(b, a, c) {
  217. b.settled || (void 0 !== a ? 0 >= a ? 0 >= b.distFromHex - b.iter * settings.scale - this.sideLength / 2 * Math.sqrt(3) ? (b.distFromHex = this.sideLength / 2 * Math.sqrt(3), b.settled = 1, b.checked = 1) : (b.settled = 0, b.iter = 1.5 + waveone.difficulty / 15 * 3) : c[a - 1].settled && 0 >= b.distFromHex - b.iter * settings.scale - c[a - 1].distFromHex - c[a - 1].height ? (b.distFromHex = c[a - 1].distFromHex + c[a -
  218. 1].height, b.settled = 1, b.checked = 1) : (b.settled = 0, b.iter = 1.5 + waveone.difficulty / 15 * 3) : (a = this.sides - b.fallingLane, a += this.position, a = (a + this.sides) % this.sides, c = this.blocks[a], 0 < c.length ? 0 >= b.distFromHex + b.iter * settings.scale - c[c.length - 1].distFromHex - c[c.length - 1].height && (b.distFromHex = c[c.length - 1].distFromHex + c[c.length - 1].height, this.addBlock(b)) : 0 >= b.distFromHex + b.iter * settings.scale - this.sideLength / 2 * Math.sqrt(3) && (b.distFromHex = this.sideLength / 2 * Math.sqrt(3), this.addBlock(b))))
  219. };
  220. this.rotate =
  221. function(a) {
  222. if (!(75 > Date.now() - this.lastRotate) || /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent))
  223. if (1 === gameState || 0 === gameState) {
  224. this.position += a;
  225. history[this.ct] || (history[this.ct] = {});
  226. for (history[this.ct].rotate = history[this.ct].rotate ? history[this.ct].rotate + a : a; 0 > this.position;) this.position += 6;
  227. this.position %= this.sides;
  228. this.blocks.forEach(function(d) {
  229. d.forEach(function(c) {
  230. c.targetAngle -= 60 * a
  231. })
  232. });
  233. this.targetAngle -= 60 * a;
  234. this.lastRotate = Date.now()
  235. }
  236. };
  237. this.draw =
  238. function() {
  239. this.x = trueCanvas.width / 2; - 2 != gameState && (this.y = trueCanvas.height / 2);
  240. this.sideLength = settings.hexWidth;
  241. for (var a = gdy = gdx = 0; a < this.shakes.length; a++) this.shake(this.shakes[a]);
  242. this.angle > this.targetAngle ? this.angularVelocity -= angularVelocityConst : this.angle < this.targetAngle && (this.angularVelocity += angularVelocityConst);
  243. Math.abs(this.angle - this.targetAngle + this.angularVelocity) <= Math.abs(this.angularVelocity) ? (this.angle = this.targetAngle, this.angularVelocity = 0) : this.angle += this.angularVelocity;
  244. drawPolygon(this.x + gdx, this.y + gdy + this.dy, this.sides, this.sideLength, this.angle, arrayToColor(this.fillColor), 0, "rgba(0,0,0,0)")
  245. }
  246. }
  247. function arrayToColor(a) {
  248. return "rgb(" + a[0] + "," + a[1] + "," + a[2] + ")"
  249. };
  250. $(document).ready(function() {
  251. initialize();
  252. $("#bottombar").hide()
  253. });
  254. function showbottombar() {
  255. "onLine" in navigator && !navigator.onLine ? setTimeout(showbottombar, 1E3) : (window.iframeHasLoaded = !0, 1 != gameState && $("#bottombar").fadeIn(150, "linear"))
  256. }
  257. function hidebottombar() {
  258. $("#bottombar").fadeOut(150, "linear");
  259. $("#overlayMask").hide();
  260. }
  261. function initialize(a) {
  262. window.iframHasLoaded = !1;
  263. window.colors = ["#e74c3c", "#f1c40f", "#3498db", "#2ecc71"];
  264. window.hexColorsToTintedColors = {
  265. "#e74c3c": "rgb(241,163,155)",
  266. "#f1c40f": "rgb(246,223,133)",
  267. "#3498db": "rgb(151,201,235)",
  268. "#2ecc71": "rgb(150,227,183)"
  269. };
  270. window.rgbToHex = {
  271. "rgb(231,76,60)": "#e74c3c",
  272. "rgb(241,196,15)": "#f1c40f",
  273. "rgb(52,152,219)": "#3498db",
  274. "rgb(46,204,113)": "#2ecc71"
  275. };
  276. window.rgbColorsToTintedColors = {
  277. "rgb(231,76,60)": "rgb(241,163,155)",
  278. "rgb(241,196,15)": "rgb(246,223,133)",
  279. "rgb(52,152,219)": "rgb(151,201,235)",
  280. "rgb(46,204,113)": "rgb(150,227,183)"
  281. };
  282. window.hexagonBackgroundColor = "rgb(236, 240, 241)";
  283. window.hexagonBackgroundColorClear = "rgba(236, 240, 241, 0.5)";
  284. window.centerBlue = "rgb(44,62,80)";
  285. window.angularVelocityConst = 4;
  286. window.scoreOpacity = 0;
  287. window.textOpacity = 0;
  288. window.prevGameState = void 0;
  289. window.op = 0;
  290. window.saveState = localStorage.getItem("saveState") || "{}";
  291. "{}" !== saveState && (op = 1);
  292. window.textShown = !1;
  293. window.requestAnimFrame = function() {
  294. return window.requestAnimationFrame || window.webkitRequestAnimationFrame ||
  295. window.mozRequestAnimationFrame || function(a) {
  296. window.setTimeout(a, 1E3 / framerate)
  297. }
  298. }();
  299. $("#clickToExit").bind("click", toggleDevTools);
  300. window.settings;
  301. /Mobile|Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ? settings = {
  302. platform: "mobile",
  303. startDist: 227,
  304. creationDt: 40,
  305. baseScale: 1.4,
  306. scale: 1,
  307. prevScale: 1,
  308. baseHexWidth: 87,
  309. hexWidth: 87,
  310. baseBlockHeight: 20,
  311. blockHeight: 20,
  312. rows: 7,
  313. speedModifier: 1.73,
  314. creationSpeedModifier: 0.73,
  315. comboTime: 240
  316. } : (settings = {
  317. platform: "nonmobile",
  318. baseScale: 1,
  319. startDist: 340,
  320. creationDt: 9,
  321. scale: 1,
  322. prevScale: 1,
  323. hexWidth: 65,
  324. baseHexWidth: 87,
  325. baseBlockHeight: 20,
  326. blockHeight: 15,
  327. rows: 8,
  328. speedModifier: 1.65,
  329. creationSpeedModifier:0.65,
  330. comboTime: 240
  331. });
  332. window.canvas = document.getElementById("canvas");
  333. window.ctx = canvas.getContext("2d");
  334. window.trueCanvas = {
  335. width: canvas.width,
  336. height: canvas.height
  337. };
  338. scaleCanvas();
  339. window.framerate = 60;
  340. window.history = {};
  341. window.score = 0;
  342. window.isGameOver = 3;
  343. window.scoreAdditionCoeff = 1;
  344. window.prevScore = 0;
  345. window.numHighScores = 3;
  346. highscores = [];
  347. if (localStorage.getItem("highscores")) try {
  348. highscores = JSON.parse(localStorage.getItem("highscores"))
  349. } catch (b) {
  350. highscores = []
  351. }
  352. window.blocks = [];
  353. window.MainHex;
  354. window.gdx = 0;
  355. window.gdy = 0;
  356. window.devMode = 0;
  357. window.lastGen = void 0;
  358. window.prevTimeScored =
  359. void 0;
  360. window.nextGen = void 0;
  361. window.spawnLane = 0;
  362. window.importing = 0;
  363. window.importedHistory = void 0;
  364. window.startTime = void 0;
  365. window.gameState;
  366. setStartScreen();
  367. if (1 != a) {
  368. window.canRestart = 1;
  369. $("#startBtn").off();
  370. if ("mobile" == settings.platform) $("#startBtn").on("touchstart", startBtnHandler);
  371. else $("#startBtn").on("mousedown", startBtnHandler);
  372. document.addEventListener("touchmove", function(a) {
  373. a.preventDefault()
  374. }, !1);
  375. $(window).resize(scaleCanvas).resize();
  376. $(window).unload(function() {
  377. 1 ==
  378. gameState || -1 == gameState || 0 === gameState ? localStorage.setItem("saveState", exportSaveState()) : localStorage.setItem("saveState", "{}")
  379. });
  380. addKeyListeners();
  381. document.addEventListener("pause", handlePause, !1);
  382. document.addEventListener("backbutton", handlePause, !1);
  383. document.addEventListener("menubutton", handlePause, !1);
  384. setTimeout(function() {
  385. if ("mobile" == settings.platform) {
  386. try {
  387. document.body.removeEventListener("touchstart", handleTapBefore, !1)
  388. } catch (a) {}
  389. try {
  390. document.body.removeEventListener("touchstart", handleTap, !1)
  391. } catch (b) {}
  392. document.body.addEventListener("touchstart", handleTapBefore, !1)
  393. } else {
  394. try {
  395. document.body.removeEventListener("mousedown",
  396. handleClickBefore, !1)
  397. } catch (e) {}
  398. try {
  399. document.body.removeEventListener("mousedown", handleClick, !1)
  400. } catch (f) {}
  401. document.body.addEventListener("mousedown", handleClickBefore, !1)
  402. }
  403. }, 1)
  404. }
  405. }
  406. function startBtnHandler() {
  407. setTimeout(function() {
  408. if ("mobile" == settings.platform) {
  409. try {
  410. document.body.removeEventListener("touchstart", handleTapBefore, !1)
  411. } catch (a) {}
  412. try {
  413. document.body.removeEventListener("touchstart", handleTap, !1)
  414. } catch (b) {}
  415. document.body.addEventListener("touchstart", handleTap, !1)
  416. } else {
  417. try {
  418. document.body.removeEventListener("mousedown", handleClickBefore, !1)
  419. } catch (d) {}
  420. try {
  421. document.body.removeEventListener("mousedown", handleClick, !1)
  422. } catch (c) {}
  423. document.body.addEventListener("mousedown",
  424. handleClick, !1)
  425. }
  426. }, 5);
  427. if (!canRestart) return !1;
  428. $("#helpScreen").is(":visible") && $("#helpScreen").fadeOut(150, "linear");
  429. 1 == importing ? init(1) : resumeGame();
  430. }
  431. function handlePause() {
  432. 1 != gameState && 2 != gameState || pause()
  433. }
  434. function handleTap(a) {
  435. handleClickTap(a.changedTouches[0].clientX, a.changedTouches[0].clientY,a)
  436. }
  437. function handleClick(a) {
  438. handleClickTap(a.clientX, a.clientY,a)
  439. }
  440. function handleTapBefore(a) {
  441. var b = a.changedTouches[0].clientY;
  442. 120 > a.changedTouches[0].clientX && 50 > b && $(".helpText").is(":visible") && showHelp()
  443. }
  444. function handleClickBefore(a) {
  445. var b = a.clientY;
  446. 120 > a.clientX && 50 > b && $(".helpText").is(":visible") && showHelp()
  447. };
  448. function addKeyListeners() {
  449. keypress.register_combo({
  450. keys: "left",
  451. on_keydown: function() {
  452. MainHex && 0 !== gameState && MainHex.rotate(1)
  453. }
  454. });
  455. keypress.register_combo({
  456. keys: "right",
  457. on_keydown: function() {
  458. MainHex && 0 !== gameState && MainHex.rotate(-1)
  459. }
  460. });
  461. keypress.register_combo({
  462. keys: "a",
  463. on_keydown: function() {
  464. MainHex && 0 !== gameState && MainHex.rotate(1)
  465. }
  466. });
  467. keypress.register_combo({
  468. keys: "d",
  469. on_keydown: function() {
  470. MainHex && 0 !== gameState && MainHex.rotate(-1)
  471. }
  472. });
  473. keypress.register_combo({
  474. keys: "p",
  475. on_keydown: function() {
  476. pause()
  477. }
  478. });
  479. keypress.register_combo({
  480. keys: "q",
  481. on_keydown: function() {
  482. devMode && toggleDevTools()
  483. }
  484. });
  485. keypress.register_combo({
  486. keys: "enter",
  487. on_keydown: function() {
  488. 2 != gameState && 1 != gameState && 1 != importing || init(1);
  489. 0 === gameState && resumeGame()
  490. }
  491. });
  492. $("#pauseBtn").on("touchstart mousedown", function() {
  493. if (1 == gameState || -1 == gameState) return $("#helpScreen").is(":visible") && $("#helpScreen").fadeOut(150, "linear"), pause(), !1
  494. });
  495. $("#colorBlindBtn").on("touchstart mousedown", function() {
  496. window.colors = ["#8e44ad", "#f1c40f", "#3498db",
  497. "#d35400"
  498. ];
  499. window.hexColorsToTintedColors = {
  500. "#8e44ad": "rgb(229,152,102)",
  501. "#f1c40f": "rgb(246,223,133)",
  502. "#3498db": "rgb(151,201,235)",
  503. "#d35400": "rgb(210,180,222)"
  504. };
  505. window.rgbToHex = {
  506. "rgb(142,68,173)": "#8e44ad",
  507. "rgb(241,196,15)": "#f1c40f",
  508. "rgb(52,152,219)": "#3498db",
  509. "rgb(211,84,0)": "#d35400"
  510. };
  511. window.rgbColorsToTintedColors = {
  512. "rgb(142,68,173)": "rgb(229,152,102)",
  513. "rgb(241,196,15)": "rgb(246,223,133)",
  514. "rgb(52,152,219)": "rgb(151,201,235)",
  515. "rgb(46,204,113)": "rgb(210,180,222)"
  516. }
  517. });
  518. if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)){
  519. $("body").on("touchstart",".irestartBtn",function(){
  520. init(1);
  521. canRestart = !1;
  522. })
  523. $("body").on("touchstart",".moreGame",function(){
  524. clickMore();
  525. return false;
  526. })
  527. }
  528. else {
  529. $("body").on("click",".irestartBtn",function(){
  530. init(1);
  531. canRestart = !1;
  532. })
  533. $("body").on("click",".moreGame",function(){
  534. clickMore();
  535. return false;
  536. })
  537. }
  538. }
  539. function handleClickTap(a, b,evt) {
  540. if($(evt.target).hasClass("bt-play-share-tip")){
  541. return false;
  542. }
  543. if(gameState==2){
  544. return false;
  545. }
  546. 120 > a && 50 > b && $(".helpText").is(":visible") ? showHelp() : 2 == gameState && canRestart ? init(1) : MainHex && 0 !== gameState && -1 != gameState && (a < window.innerWidth / 2 && (1 != gameState && -2 != gameState && -1 != gameState && (0 === importing ? resumeGame() : init(1)), MainHex.rotate(1)), a > window.innerWidth / 2 && (1 != gameState && -2 != gameState && -1 != gameState && (0 === importing ? resumeGame() : init(1)), MainHex.rotate(-1)))
  547. };
  548. function scaleCanvas() {
  549. canvas.width = $(window).width();
  550. canvas.height = $(window).height();
  551. settings.scale = canvas.height > canvas.width ? canvas.width / 800 * settings.baseScale : canvas.height / 800 * settings.baseScale;
  552. trueCanvas = {
  553. width: canvas.width,
  554. height: canvas.height
  555. };
  556. if (window.devicePixelRatio) {
  557. var a = $("#canvas").attr("width"),
  558. b = $("#canvas").attr("height");
  559. $("#canvas").attr("width", a * window.devicePixelRatio);
  560. $("#canvas").attr("height", b * window.devicePixelRatio);
  561. $("#canvas").css("width", a);
  562. $("#canvas").css("height",
  563. b);
  564. trueCanvas = {
  565. width: a,
  566. height: b
  567. };
  568. ctx.scale(window.devicePixelRatio, window.devicePixelRatio)
  569. }
  570. $("html").css("font-size",~~$(window).width()*12/640+"px");
  571. }
  572. function toggleDevTools() {
  573. $("#devtools").toggle()
  574. }
  575. function resumeGame() {
  576. gameState = 1;
  577. hideUIElements();
  578. $("#pauseBtn").show();
  579. $("#restartBtn").hide();
  580. importing = 0;
  581. startTime = Date.now();
  582. setTimeout(function() {
  583. 1 != gameState && 2 != gameState || $("#helpScreen").is(":visible") || $(".helpText").fadeOut(150, "linear")
  584. }, 7E3);
  585. checkVisualElements()
  586. }
  587. function checkVisualElements() {
  588. $(".helpText").is(":visible") || $(".helpText").fadeIn(150, "linear");
  589. $("#pauseBtn").is(":visible") || $("#pauseBtn").fadeIn(150, "linear");
  590. $("#restartBtn").is(":visible") || $("#restartBtn").fadeOut(150, "linear")
  591. }
  592. function hideUIElements() {
  593. $("#pauseBtn").hide();
  594. $("#restartBtn").hide();
  595. $("#startBtn").hide();
  596. $("#attributions").hide();
  597. $("#bottombar").hide();
  598. $(".doudouLink").hide();
  599. }
  600. function init(a) {
  601. a ? (hidebottombar(), $("#helpScreen").is(":visible") && $("#helpScreen").fadeOut(150, "linear"), setTimeout(function() {
  602. $(".helpText").fadeOut(150, "linear")
  603. }, 7E3), clearSaveState()) : void(0);
  604. $("#pauseBtnInner").html('<i class="fa fa-pause fa-2x"></i>');
  605. hideUIElements();
  606. a = localStorage.getItem("saveState") || "{}";
  607. a = JSONfn.parse(a);
  608. document.getElementById("canvas").className = "";
  609. history = {};
  610. importedHistory = void 0;
  611. importing = 0;
  612. isGameOver = 2;
  613. score = a.score ||0;
  614. scoreOpacity = op = spawnLane = prevScore = 0;
  615. gameState = 1;
  616. $("#restartBtn").hide();
  617. $("#pauseBtn").show();
  618. void 0 !== a.hex && (gameState = 1);
  619. settings.blockHeight = settings.baseBlockHeight * settings.scale;
  620. settings.hexWidth = settings.baseHexWidth * settings.scale;
  621. MainHex = a.hex || new Hex(settings.hexWidth);
  622. a.hex && (MainHex.playThrough += 1);
  623. MainHex.sideLength = settings.hexWidth;
  624. var b, d;
  625. if (a.blocks)
  626. for (a.blocks.map(function(a) {
  627. rgbToHex[a.color] && (a.color = rgbToHex[a.color])
  628. }), b = 0; b < a.blocks.length; b++) d = a.blocks[b], blocks.push(d);
  629. else blocks = [];
  630. gdx = a.gdx || 0;
  631. gdy = a.gdy || 0;
  632. comboTime = a.comboTime || 0;
  633. for (b = 0; b < MainHex.blocks.length; b++)
  634. for (d = 0; d < MainHex.blocks[b].length; d++) MainHex.blocks[b][d].height = settings.blockHeight, MainHex.blocks[b][d].settled = 0;
  635. MainHex.blocks.map(function(a) {
  636. a.map(function(a) {
  637. rgbToHex[a.color] && (a.color = rgbToHex[a.color])
  638. })
  639. });
  640. MainHex.y = -100;
  641. startTime = Date.now();
  642. waveone = a.wavegen || new waveGen(MainHex);
  643. MainHex.texts = [];
  644. MainHex.delay = 15;
  645. hideText();
  646. document.getElementById('moregame2').style.display='none';
  647. }
  648. function addNewBlock(a, b, d, c, e) {
  649. d *= settings.speedModifier;
  650. history[MainHex.ct] || (history[MainHex.ct] = {});
  651. history[MainHex.ct].block = {
  652. blocklane: a,
  653. color: b,
  654. iter: d
  655. };
  656. c && (history[MainHex.ct].distFromHex = c);
  657. e && (blockHist[MainHex.ct].settled = e);
  658. blocks.push(new Block(a, b, d, c, e))
  659. }
  660. function exportHistory() {
  661. $("#devtoolsText").html(JSON.stringify(history));
  662. toggleDevTools()
  663. }
  664. function setStartScreen() {
  665. $("#startBtn").show();
  666. init();
  667. importing = isStateSaved() ? 0 : 1;
  668. $("#pauseBtn").hide();
  669. $("#restartBtn").hide();
  670. $("#startBtn").show();
  671. $(".doudouLink").show();
  672. $("#attributions").show();
  673. showbottombar();
  674. gameState = 0;
  675. requestAnimFrame(animLoop)
  676. }
  677. setInterval(function() {
  678. 1 == gameState && (MainHex.delay ? MainHex.delay-- : update())
  679. }, 17);
  680. function animLoop() {
  681. switch (gameState) {
  682. case 1:
  683. requestAnimFrame(animLoop);
  684. render();
  685. if (checkGameOver() && !importing) {
  686. var a = localStorage.getItem("saveState") || "{}",
  687. a = JSONfn.parse(a);
  688. gameState = 2;
  689. setTimeout(function() {
  690. enableRestart()
  691. }, 150);
  692. $("#helpScreen").is(":visible") && $("#helpScreen").fadeOut(150, "linear");
  693. $("#pauseBtn").is(":visible") && $("#pauseBtn").fadeOut(150, "linear");
  694. $("#restartBtn").is(":visible") && $("#restartBtn").fadeOut(150, "linear");
  695. $(".helpText").is(":visible") || $(".helpText").fadeIn(150,
  696. "linear");
  697. showbottombar();
  698. canRestart = 0;
  699. clearSaveState()
  700. }
  701. break;
  702. case 0:
  703. requestAnimFrame(animLoop);
  704. importing && update();
  705. render();
  706. break;
  707. case -1:
  708. requestAnimFrame(animLoop);
  709. render();
  710. break;
  711. case 2:
  712. requestAnimFrame(animLoop);
  713. update();
  714. render();
  715. break;
  716. case 3:
  717. requestAnimFrame(animLoop);
  718. fadeOutObjectsOnScreen();
  719. render();
  720. break;
  721. case 4:
  722. setTimeout(function() {
  723. initialize(1)
  724. }, 1);
  725. render();
  726. break;
  727. default:
  728. initialize(), setStartScreen()
  729. }
  730. }
  731. function enableRestart() {
  732. canRestart = 1
  733. }
  734. function isInfringing(a) {
  735. for (var b = 0; b < a.sides; b++) {
  736. for (var d = 0, c = 0; c < a.blocks[b].length; c++) d += a.blocks[b][c].deleted;
  737. if (a.blocks[b].length - d > settings.rows) return !0
  738. }
  739. return !1
  740. }
  741. function checkGameOver() {
  742. for (var a = 0; a < MainHex.sides; a++)
  743. if (isInfringing(MainHex)) return -1 == highscores.indexOf(score) && highscores.push(score), writeHighScores(), gameOverDisplay(),(function(){
  744. dp_submitScore(score);
  745. document.getElementById('moregame2').style.display='block';
  746. })(), !0;
  747. return !1
  748. }
  749. function showHelp() {
  750. 1 == gameState && pause();
  751. $("#helpScreen").fadeToggle(150, "linear")
  752. };
  753. function rotatePoint(a, b, d) {
  754. var c = Math.PI / 180 * d;
  755. d = Math.cos(c) * a - Math.sin(c) * b;
  756. a = Math.sin(c) * a + Math.cos(c) * b;
  757. return {
  758. x: d,
  759. y: a
  760. }
  761. }
  762. function randInt(a, b) {
  763. return Math.floor(Math.random() * b + a)
  764. };
  765. function render() {
  766. var a = "#bdc3c7";
  767. 0 === gameState && (a = "rgb(220, 223, 225)");
  768. ctx.clearRect(0, 0, trueCanvas.width, trueCanvas.height);
  769. clearGameBoard();
  770. if (1 === gameState || 2 === gameState || -1 === gameState || 0 === gameState) 1 > op && (op += .01), ctx.globalAlpha = 1, drawPolygon(trueCanvas.width / 2, trueCanvas.height / 2, 6, settings.rows * settings.blockHeight * (2 / Math.sqrt(3)) + settings.hexWidth, 30, a, !1, 6), drawTimer(), ctx.globalAlpha = 1;
  771. for (a = 0; a < MainHex.blocks.length; a++)
  772. for (var b = 0; b < MainHex.blocks[a].length; b++) MainHex.blocks[a][b].draw(!0,
  773. b);
  774. for (a = 0; a < blocks.length; a++) blocks[a].draw();
  775. MainHex.draw();
  776. 1 != gameState && -1 != gameState && 0 !== gameState || drawScoreboard();
  777. for (a = 0; a < MainHex.texts.length; a++) MainHex.texts[a].draw() || (MainHex.texts.splice(a, 1), a--);
  778. 400 > MainHex.ct && 0 !== gameState && !MainHex.playThrough && (350 < MainHex.ct && (ctx.globalAlpha = (50 - (MainHex.ct - 350)) / 50), 50 > MainHex.ct && (ctx.globalAlpha = MainHex.ct / 50), renderBeginningText(), ctx.globalAlpha = 1); - 1 == gameState && (ctx.globalAlpha = 0.9, ctx.fillStyle = "rgb(236,240,241)", ctx.fillRect(0, 0,
  779. trueCanvas.width, trueCanvas.height), ctx.globalAlpha = 1);
  780. settings.prevScale = settings.scale;
  781. settings.hexWidth = settings.baseHexWidth * settings.scale;
  782. settings.blockHeight = settings.baseBlockHeight * settings.scale
  783. }
  784. function renderBeginningText() {
  785. renderText(trueCanvas.width / 2 + 1.5 * settings.scale, trueCanvas.height / 2 - 208 * settings.scale-20, 35, "#2c3e50", "\u63a7\u5236", "35px 微软雅黑");
  786. renderText(trueCanvas.width / 2 - 85 * settings.scale, trueCanvas.height / 2 - 169 * settings.scale, 20, "#2c3e50", "\u65cb\u8f6c:", "20px 微软雅黑");
  787. renderText(trueCanvas.width / 2 - 21 * settings.scale, trueCanvas.height / 2 - 141 * settings.scale+10, 14, "#2c3e50", "\u5de6", "14px 微软雅黑");
  788. renderText(trueCanvas.width / 2 + 25 * settings.scale, trueCanvas.height / 2 - 141 * settings.scale+10,14, "#2c3e50", "\u53f3", "14px 微软雅黑");
  789. /*加提示语*/
  790. renderText(trueCanvas.width / 2 + 0 * settings.scale, trueCanvas.height / 2 - 121 * settings.scale+20,
  791. 16, "#2c3e50", "\u70b9\u51fb\u5c4f\u5e55\u5de6\u53f3\u6d4b\uff0c\u5411\u5de6\u3001\u5411\u53f3\u65cb\u8f6c\u516d\u8fb9\u5f62\u3002", "16px 微软雅黑");
  792. drawKey("right", trueCanvas.width / 2 + 23 * settings.scale - 17.5 * settings.scale, trueCanvas.height / 2 - 195 * settings.scale);
  793. drawKey("left", trueCanvas.width / 2 - 23 * settings.scale - 17.5 * settings.scale, trueCanvas.height / 2 - 195 * settings.scale)
  794. }
  795. function drawKey(a, b, d) {
  796. ctx.save();
  797. ctx.beginPath();
  798. ctx.fillStyle = "#2c3e50";
  799. ctx.strokeStyle = "#2c3e50";
  800. ctx.lineWidth = 4 * settings.scale;
  801. ctx.rect(b + 2.5 * settings.scale, d + 2.5 * settings.scale, 35 * settings.scale, 35 * settings.scale);
  802. ctx.stroke();
  803. switch (a) {
  804. case "left":
  805. ctx.translate(b + 28 * settings.scale, d + 13 * settings.scale);
  806. ctx.rotate(3.14159);
  807. ctx.font = "20px Fontawesome";
  808. ctx.scale(settings.scale, settings.scale);
  809. ctx.fillText(String.fromCharCode("0xf04b"), 0, 0);
  810. break;
  811. case "right":
  812. ctx.font = "20px Fontawesome";
  813. ctx.translate(b +
  814. 12.5 * settings.scale, d + 27.5 * settings.scale);
  815. ctx.scale(settings.scale, settings.scale);
  816. ctx.fillText(String.fromCharCode("0xf04b"), 0, 0);
  817. break;
  818. default:
  819. ctx.font = "35px Roboto", ctx.translate(b + 25 * settings.scale, d + 39.5 * settings.scale), ctx.scale(settings.scale, settings.scale), ctx.fillText(a, 0, 0)
  820. }
  821. ctx.restore()
  822. };
  823. function exportSaveState() {
  824. var a = {};
  825. if (1 == gameState || -1 == gameState || 0 === gameState && void 0 !== localStorage.getItem("saveState")) {
  826. a = {
  827. hex: $.extend(!0, {}, MainHex),
  828. blocks: $.extend(!0, [], blocks),
  829. score: score,
  830. wavegen: waveone,
  831. gdx: gdx,
  832. gdy: gdy,
  833. comboTime: settings.comboTime
  834. };
  835. a.hex.blocks.map(function(a) {
  836. for (var b = 0; b < a.length; b++) a[b] = $.extend(!0, {}, a[b]);
  837. a.map(descaleBlock)
  838. });
  839. for (var b = 0; b < a.blocks.length; b++) a.blocks[b] = $.extend(!0, {}, a.blocks[b]);
  840. a.blocks.map(descaleBlock)
  841. }
  842. localStorage.setItem("highscores",
  843. JSON.stringify(highscores));
  844. return JSONfn.stringify(a)
  845. }
  846. function descaleBlock(a) {
  847. a.distFromHex /= settings.scale
  848. }
  849. function writeHighScores() {
  850. highscores.sort(function(a, b) {
  851. a = parseInt(a, 10);
  852. b = parseInt(b, 10);
  853. return a < b ? 1 : a > b ? -1 : 0
  854. });
  855. highscores = highscores.slice(0, 3);
  856. localStorage.setItem("highscores", JSON.stringify(highscores))
  857. }
  858. function clearSaveState() {
  859. localStorage.setItem("saveState", "{}");
  860. }
  861. function isStateSaved() {
  862. return "{}" != localStorage.getItem("saveState") && void 0 != localStorage.getItem("saveState")
  863. };
  864. function Text(a, b, d, c, e, f) {
  865. this.x = a;
  866. this.y = b;
  867. this.font = c;
  868. this.color = e;
  869. this.opacity = 1;
  870. this.text = d;
  871. this.alive = 1;
  872. this.draw = function() {
  873. return 0 < this.alive ? (ctx.globalAlpha = this.opacity, renderText(this.x + gdx, this.y + gdy, 50, this.color, this.text), ctx.globalAlpha = 1, f(this), !0) : !1
  874. }
  875. }
  876. function fadeUpAndOut(a) {
  877. a.opacity -= Math.pow(Math.pow(1 - a.opacity, 1 / 3) + 1, 3) / 100;
  878. a.alive = a.opacity;
  879. a.y -= 3
  880. };
  881. function update() {
  882. var a = MainHex.ct;
  883. 1 == gameState && (waveone.update(), 1E3 < a - waveone.prevTimeScored && (waveone.prevTimeScored = a));
  884. var a = 99,
  885. b, d, c;
  886. for (b = 0; b < blocks.length; b++)(MainHex.doesBlockCollide(blocks[b]), blocks[b].settled) ? blocks[b].removed || (blocks[b].removed = 1) : blocks[b].initializing || (blocks[b].distFromHex -= blocks[b].iter * settings.scale);
  887. for (b = 0; b < MainHex.blocks.length; b++)
  888. for (d = 0; d < MainHex.blocks[b].length; d++) 1 == MainHex.blocks[b][d].checked && (consolidateBlocks(MainHex, MainHex.blocks[b][d].attachedLane,
  889. MainHex.blocks[b][d].getIndex()), MainHex.blocks[b][d].checked = 0);
  890. for (b = 0; b < MainHex.blocks.length; b++) {
  891. a = 99;
  892. for (d = 0; d < MainHex.blocks[b].length; d++) c = MainHex.blocks[b][d], 2 == c.deleted && (MainHex.blocks[b].splice(d, 1), blockDestroyed(), d < a && (a = d), d--);
  893. if (a < MainHex.blocks[b].length)
  894. for (d = a; d < MainHex.blocks[b].length; d++) MainHex.blocks[b][d].settled = 0
  895. }
  896. for (b = 0; b < MainHex.blocks.length; b++)
  897. for (d = 0; d < MainHex.blocks[b].length; d++) c = MainHex.blocks[b][d], MainHex.doesBlockCollide(c, d, MainHex.blocks[b]), MainHex.blocks[b][d].settled ||
  898. (MainHex.blocks[b][d].distFromHex -= c.iter * settings.scale);
  899. for (b = 0; b < blocks.length; b++) 1 == blocks[b].removed && (blocks.splice(b, 1), b--);
  900. MainHex.ct++
  901. };
  902. function easeOutCubic(a, b, d, c) {
  903. return d * ((a = a / c - 1) * a * a + 1) + b
  904. }
  905. function renderText(a, b, d, c, e, f) {
  906. ctx.save();
  907. f || (f = "px/0 微软雅黑");
  908. d *= settings.scale;
  909. ctx.font = d + f;
  910. ctx.textAlign = "center";
  911. ctx.fillStyle = c;
  912. ctx.fillText(e, a, b + d / 2 - 9 * settings.scale);
  913. ctx.restore()
  914. }
  915. var doudouIcon=new Image();
  916. doudouIcon.src="doudouIcon.png";
  917. function drawScoreboard() {
  918. 1 > scoreOpacity && (scoreOpacity += .01, textOpacity += .01);
  919. ctx.globalAlpha = textOpacity;
  920. var a = 50,
  921. b = String(score);
  922. 6 == b.length ? a = 43 : 7 == b.length ? a = 35 : 8 == b.length ? a = 31 : 9 == b.length && (a = 27);
  923. 0 === gameState ? (renderText(trueCanvas.width / 2 + gdx + 6 * settings.scale, trueCanvas.height / 2 + gdy, 60, "rgb(236, 240, 241)", String.fromCharCode("0xf04b"), "px FontAwesome"), renderText(trueCanvas.width / 2 + gdx + 6 * settings.scale, trueCanvas.height / 2 + gdy - 170 * settings.scale, 150, "#2c3e50", "\u8f6c\u4f60\u59b9"), renderText(trueCanvas.width /
  924. 2 + gdx + 5 * settings.scale, trueCanvas.height / 2 + gdy + 100 * settings.scale, 20, "rgb(44,62,80)", "\u5f00\u59cb!"),ctx.drawImage(doudouIcon,0,0,266,120,trueCanvas.width / 2 -120 * settings.scale, trueCanvas.height / 2 +250 * settings.scale,266*settings.scale,120*settings.scale)) : (0 != gameState && 0 < textOpacity && (textOpacity -= .05, renderText(trueCanvas.width / 2 + gdx + 6 * settings.scale, trueCanvas.height / 2 + gdy, 60, "rgb(236, 240, 241)", String.fromCharCode("0xf04b"), "px FontAwesome"), renderText(trueCanvas.width / 2 + gdx + 6 * settings.scale, trueCanvas.height / 2 + gdy - 170 * settings.scale, 150, "#2c3e50", "\u8f6c\u4f60\u59b9"), renderText(trueCanvas.width / 2 + gdx + 5 * settings.scale, trueCanvas.height / 2 + gdy +
  925. 100 * settings.scale, 20, "rgb(44,62,80)", "\u5f00\u59cb!")), ctx.globalAlpha = scoreOpacity, renderText(trueCanvas.width / 2 + gdx, trueCanvas.height / 2 + gdy, a, "rgb(236, 240, 241)", score));
  926. ctx.globalAlpha = 1
  927. }
  928. function clearGameBoard() {
  929. drawPolygon(trueCanvas.width / 2, trueCanvas.height / 2, 6, trueCanvas.width / 2, 30, hexagonBackgroundColor, 0, "rgba(0,0,0,0)")
  930. }
  931. function drawPolygon(a, b, d, c, e, f, h, q) {
  932. ctx.fillStyle = f;
  933. ctx.lineWidth = h;
  934. ctx.strokeStyle = q;
  935. ctx.beginPath();
  936. f = rotatePoint(0, c, e);
  937. ctx.moveTo(f.x + a, f.y + b);
  938. c = f.x;
  939. f = f.y;
  940. for (e = 0; e < d; e++) f = rotatePoint(c, f, 360 / d), ctx.lineTo(f.x + a, f.y + b), c = f.x, f = f.y;
  941. ctx.closePath();
  942. ctx.fill();
  943. ctx.stroke();
  944. ctx.strokeStyle = "rgba(0,0,0,0)"
  945. }
  946. function toggleClass(a, b) {
  947. $(a).hasClass(b) ? $(a).removeClass(b) : $(a).addClass(b)
  948. }
  949. function showText(a) {
  950. var b = {
  951. paused: "<div class='centeredHeader unselectable'>\u6682\u505c</div><br><div class='unselectable centeredSubHeader'>\u6309 p \u7ee7\u7eed</div><div style='height:100px;line-height:100px;cursor:pointer;'></div>",
  952. pausedMobile: "<div class='centeredHeader unselectable'>\u6682\u505c</div><br><div class='unselectable centeredSubHeader'>\u6309 <i class='fa fa-play'></i> \u7ee7\u7eed</div><div style='height:100px;line-height:100px;cursor:pointer;'></div>",
  953. start: "<div class='centeredHeader unselectable' style='line-height:80px;'>Press enter to start</div>",
  954. gameover: "<div class='centeredHeader unselectable' style='color: #2C3E50;font-weight: bold;font-size: 3rem;'> Game Over</div><div style='color: #2C3E50;margin-top: 5%;font-size: 2.5rem;'>得分</div><div style='font-size: 6rem;color: #2C3E50;'>"+ score +"</div>"
  955. };
  956. "paused" == a && "mobile" == settings.platform && (a = "pausedMobile");
  957. if ("gameover" == a) {
  958. var d = 1,
  959. c, e;
  960. b.gameover += "<div class='unselectable centeredSubHeader endBtn'><a href=\"###\" class='moreGame'></a><a href=\"###\" class=\"irestartBtn\" ></a></div>";
  961. if (d)
  962. for (c = 0; c < highscores.length; c++) 0 !== highscores[c] && (d = 0)
  963. }
  964. $("#overlay").html(b[a]);
  965. $("#overlay").fadeIn("1000", "swing");
  966. $("#overlayMask").show();
  967. "gameover" == a && ("mobile" == settings.platform && $(".tg").css("margin-top", "4px"))
  968. }
  969. function setMainMenu() {
  970. gameState = 4;
  971. canRestart = !1;
  972. setTimeout(function() {
  973. canRestart = "s"
  974. }, 500);
  975. $("#restartBtn").hide(); - 1 == $($("#pauseBtn").children()[0]).attr("class").indexOf("pause") ? $("#pauseBtnInner").html('<i class="fa fa-pause fa-2x"></i>') : $("#pauseBtnInner").html('<i class="fa fa-play fa-2x"></i>')
  976. }
  977. function hideText() {
  978. $("#overlay").fadeOut("1000", function() {
  979. $("#overlay").html("")
  980. });
  981. $("#overlayMask").hide();
  982. }
  983. function gameOverDisplay() {
  984. $("#attributions").show();
  985. document.getElementById("canvas").className = "blur";
  986. showText("gameover");
  987. showbottombar();
  988. }
  989. function pause(a) {
  990. writeHighScores();
  991. a = a ? "" : "paused";
  992. document.getElementById("canvas"); - 1 == gameState ? ($("#restartBtn").fadeOut(150, "linear"), $("#helpScreen").is(":visible") && $("#helpScreen").fadeOut(150, "linear"), $("#pauseBtnInner").html('<i class="fa fa-pause fa-2x"></i>'), $(".helpText").fadeOut(200, "linear"), hideText(), hidebottombar(), setTimeout(function() {
  993. gameState = prevGameState
  994. }, 200)) : -2 != gameState && 0 !== gameState && 2 !== gameState && ($("#restartBtn").fadeIn(150, "linear"), $(".helpText").fadeIn(200,
  995. "linear"), showbottombar(), "paused" == a && showText(a), $("#pauseBtnInner").html('<i class="fa fa-play fa-2x"></i>'), prevGameState = gameState, gameState = -1)
  996. };
  997. function blockDestroyed() {
  998. waveone.nextGen = 1350 < waveone.nextGen ? waveone.nextGen - 24 * settings.creationSpeedModifier : 600 < waveone.nextGen ? waveone.nextGen - 10 * settings.creationSpeedModifier : 600;
  999. waveone.difficulty = 35 > waveone.difficulty ? waveone.difficulty + .17 * settings.speedModifier : 35
  1000. }
  1001. function waveGen(a) {
  1002. this.last = this.lastGen = 0;
  1003. this.nextGen = 2300;
  1004. this.start = 0;
  1005. this.colors = colors;
  1006. this.ct = 0;
  1007. this.hex = a;
  1008. this.difficulty = 1;
  1009. this.dt = 0;
  1010. this.update = function() {
  1011. this.currentFunction();
  1012. this.dt = 16.6666667 * MainHex.ct;
  1013. this.computeDifficulty();
  1014. (this.dt - this.lastGen) * settings.creationSpeedModifier > this.nextGen && 600 < this.nextGen && (this.nextGen -= this.nextGen / 1300 * 10 * settings.creationSpeedModifier)
  1015. };
  1016. this.randomGeneration = function() {
  1017. if (this.dt - this.lastGen > this.nextGen) {
  1018. this.ct++;
  1019. this.lastGen = this.dt;
  1020. var a = randInt(0, MainHex.sides);
  1021. addNewBlock(a, colors[randInt(0, colors.length)], 1.6 + this.difficulty / 15 * 3);
  1022. 5 < this.ct && (a = randInt(0, 24), 15 < a ? (this.ct = 0, this.currentFunction = this.doubleGeneration) : 10 < a ? (this.ct = 0, this.currentFunction = this.crosswiseGeneration) : 7 < a ? (this.ct = 0, this.currentFunction = this.spiralGeneration) : 4 < a ? (this.ct = 0, this.currentFunction = this.circleGeneration) : 1 < a && (this.ct = 0, this.currentFunction = this.halfCircleGeneration))
  1023. }
  1024. };
  1025. this.computeDifficulty = function() {
  1026. 35 > this.difficulty && (this.difficulty =
  1027. 8 > this.difficulty ? this.difficulty + (this.dt - this.last) / 2566667 * settings.speedModifier : 15 > this.difficulty ? this.difficulty + (this.dt - this.last) / 53333333 * settings.speedModifier : this.difficulty + (this.dt - this.last) / 12E7 * settings.speedModifier)
  1028. };
  1029. this.circleGeneration = function() {
  1030. if (this.dt - this.lastGen > this.nextGen + 500) {
  1031. var a = randInt(1, 4);
  1032. 3 == a && (a = randInt(1, 4));
  1033. var d = [],
  1034. c = 0;
  1035. a: for (; c < a; c++) {
  1036. var e = randInt(0, colors.length),
  1037. f;
  1038. for (f in d)
  1039. if (d[f] == colors[e]) {
  1040. c--;
  1041. continue a
  1042. }
  1043. d.push(colors[e])
  1044. }
  1045. for (c = 0; c < MainHex.sides; c++) addNewBlock(c,
  1046. d[c % a], 1.5 + this.difficulty / 15 * 3);
  1047. this.ct += 15;
  1048. this.lastGen = this.dt;
  1049. this.shouldChangePattern(1)
  1050. }
  1051. };
  1052. this.halfCircleGeneration = function() {
  1053. if (this.dt - this.lastGen > (this.nextGen + 500) / 2) {
  1054. var a = randInt(1, 3),
  1055. d = colors[randInt(0, colors.length)],
  1056. c = [d, d, d];
  1057. 2 == a && (c = [d, colors[randInt(0, colors.length)], d]);
  1058. a = randInt(0, 6);
  1059. for (d = 0; 3 > d; d++) addNewBlock((a + d) % 6, c[d], 1.5 + this.difficulty / 15 * 3);
  1060. this.ct += 8;
  1061. this.lastGen = this.dt;
  1062. this.shouldChangePattern()
  1063. }
  1064. };
  1065. this.crosswiseGeneration = function() {
  1066. if (this.dt - this.lastGen > this.nextGen) {
  1067. var a =
  1068. randInt(0, colors.length),
  1069. d = randInt(0, colors.length);
  1070. addNewBlock(d, colors[a], .6 + this.difficulty / 15 * 3);
  1071. addNewBlock((d + 3) % MainHex.sides, colors[a], .6 + this.difficulty / 15 * 3);
  1072. this.ct += 1.5;
  1073. this.lastGen = this.dt;
  1074. this.shouldChangePattern()
  1075. }
  1076. };
  1077. this.spiralGeneration = function() {
  1078. var a = randInt(0, 2);
  1079. this.dt - this.lastGen > 2 / 3 * this.nextGen && (a ? addNewBlock(5 - this.ct % MainHex.sides, colors[randInt(0, colors.length)], 1.5 + this.difficulty / 15 * 1.5) : addNewBlock(this.ct % MainHex.sides, colors[randInt(0, colors.length)], 1.5 + this.difficulty /
  1080. 15 * 1.5), this.ct += 1, this.lastGen = this.dt, this.shouldChangePattern())
  1081. };
  1082. this.doubleGeneration = function() {
  1083. if (this.dt - this.lastGen > this.nextGen) {
  1084. var a = randInt(0, colors.length);
  1085. addNewBlock(a, colors[randInt(0, colors.length)], 1.5 + this.difficulty / 15 * 3);
  1086. addNewBlock((a + 1) % MainHex.sides, colors[randInt(0, colors.length)], 1.5 + this.difficulty / 15 * 3);
  1087. this.ct += 2;
  1088. this.lastGen = this.dt;
  1089. this.shouldChangePattern()
  1090. }
  1091. };
  1092. this.setRandom = function() {
  1093. this.ct = 0;
  1094. this.currentFunction = this.randomGeneration
  1095. };
  1096. this.shouldChangePattern =
  1097. function(a) {
  1098. if (a) switch (a = randInt(0, 4), this.ct = 0, a) {
  1099. case 0:
  1100. this.currentFunction = this.doubleGeneration;
  1101. break;
  1102. case 1:
  1103. this.currentFunction = this.spiralGeneration;
  1104. break;
  1105. case 2:
  1106. this.currentFunction = this.crosswiseGeneration
  1107. } else if (8 < this.ct && 0 === randInt(0, 2)) return this.setRandom(), 1;
  1108. return 0
  1109. };
  1110. this.currentFunction = this.randomGeneration
  1111. };
  1112. ! function(a, b) {
  1113. function d() {
  1114. c.READY || (B.determineEventTypes(), g.each(c.gestures, function(a) {
  1115. x.register(a)
  1116. }), B.onTouch(c.DOCUMENT, y, x.detect), B.onTouch(c.DOCUMENT, r, x.detect), c.READY = !0)
  1117. }
  1118. var c = function K(a, b) {
  1119. return new K.Instance(a, b || {})
  1120. };
  1121. c.VERSION = "1.1.2";
  1122. c.defaults = {
  1123. behavior: {
  1124. userSelect: "none",
  1125. touchAction: "none",
  1126. touchCallout: "none",
  1127. contentZooming: "none",
  1128. userDrag: "none",
  1129. tapHighlightColor: "rgba(0,0,0,0)"
  1130. }
  1131. };
  1132. c.DOCUMENT = document;
  1133. c.HAS_POINTEREVENTS = navigator.pointerEnabled || navigator.msPointerEnabled;
  1134. c.HAS_TOUCHEVENTS = "ontouchstart" in a;
  1135. c.IS_MOBILE = /mobile|tablet|ip(ad|hone|od)|android|silk/i.test(navigator.userAgent);
  1136. c.NO_MOUSEEVENTS = c.HAS_TOUCHEVENTS && c.IS_MOBILE || c.HAS_POINTEREVENTS;
  1137. c.CALCULATE_INTERVAL = 25;
  1138. var e = {}, f = c.DIRECTION_DOWN = "down",
  1139. h = c.DIRECTION_LEFT = "left",
  1140. q = c.DIRECTION_UP = "up",
  1141. u = c.DIRECTION_RIGHT = "right",
  1142. A = c.POINTER_MOUSE = "mouse",
  1143. v = c.POINTER_TOUCH = "touch",
  1144. w = c.POINTER_PEN = "pen",
  1145. n = c.EVENT_START = "start",
  1146. y = c.EVENT_MOVE = "move",
  1147. r = c.EVENT_END = "end",
  1148. z = c.EVENT_RELEASE = "release",
  1149. D = c.EVENT_TOUCH =
  1150. "touch";
  1151. c.READY = !1;
  1152. c.plugins = c.plugins || {};
  1153. c.gestures = c.gestures || {};
  1154. var g = c.utils = {
  1155. extend: function(a, c, d) {
  1156. for (var l in c)!c.hasOwnProperty(l) || a[l] !== b && d || (a[l] = c[l]);
  1157. return a
  1158. },
  1159. on: function(a, b, c) {
  1160. a.addEventListener(b, c, !1)
  1161. },
  1162. off: function(a, b, c) {
  1163. a.removeEventListener(b, c, !1)
  1164. },
  1165. each: function(a, c, d) {
  1166. var l, e;
  1167. if ("forEach" in a) a.forEach(c, d);
  1168. else if (a.length !== b)
  1169. for (l = 0, e = a.length; e > l && !1 !== c.call(d, a[l], l, a); l++);
  1170. else
  1171. for (l in a)
  1172. if (a.hasOwnProperty(l) && !1 === c.call(d, a[l], l, a)) break
  1173. },
  1174. inStr: function(a, b) {
  1175. return -1 <
  1176. a.indexOf(b)
  1177. },
  1178. inArray: function(a, b) {
  1179. if (a.indexOf) {
  1180. var c = a.indexOf(b);
  1181. return -1 === c ? !1 : c
  1182. }
  1183. for (var c = 0, d = a.length; d > c; c++)
  1184. if (a[c] === b) return c;
  1185. return !1
  1186. },
  1187. toArray: function(a) {
  1188. return Array.prototype.slice.call(a, 0)
  1189. },
  1190. hasParent: function(a, b) {
  1191. for (; a;) {
  1192. if (a == b) return !0;
  1193. a = a.parentNode
  1194. }
  1195. return !1
  1196. },
  1197. getCenter: function(a) {
  1198. var b = [],
  1199. c = [],
  1200. d = [],
  1201. e = [],
  1202. m = Math.min,
  1203. f = Math.max;
  1204. return 1 === a.length ? {
  1205. pageX: a[0].pageX,
  1206. pageY: a[0].pageY,
  1207. clientX: a[0].clientX,
  1208. clientY: a[0].clientY
  1209. } : (g.each(a, function(a) {
  1210. b.push(a.pageX);
  1211. c.push(a.pageY);
  1212. d.push(a.clientX);
  1213. e.push(a.clientY)
  1214. }), {
  1215. pageX: (m.apply(Math, b) + f.apply(Math, b)) / 2,
  1216. pageY: (m.apply(Math, c) + f.apply(Math, c)) / 2,
  1217. clientX: (m.apply(Math, d) + f.apply(Math, d)) / 2,
  1218. clientY: (m.apply(Math, e) + f.apply(Math, e)) / 2
  1219. })
  1220. },
  1221. getVelocity: function(a, b, c) {
  1222. return {
  1223. x: Math.abs(b / a) || 0,
  1224. y: Math.abs(c / a) || 0
  1225. }
  1226. },
  1227. getAngle: function(a, b) {
  1228. return 180 * Math.atan2(b.clientY - a.clientY, b.clientX - a.clientX) / Math.PI
  1229. },
  1230. getDirection: function(a, b) {
  1231. var c = Math.abs(a.clientX - b.clientX),
  1232. d = Math.abs(a.clientY - b.clientY);
  1233. return c >= d ? 0 < a.clientX -
  1234. b.clientX ? h : u : 0 < a.clientY - b.clientY ? q : f
  1235. },
  1236. getDistance: function(a, b) {
  1237. var c = b.clientX - a.clientX,
  1238. d = b.clientY - a.clientY;
  1239. return Math.sqrt(c * c + d * d)
  1240. },
  1241. getScale: function(a, b) {
  1242. return 2 <= a.length && 2 <= b.length ? this.getDistance(b[0], b[1]) / this.getDistance(a[0], a[1]) : 1
  1243. },
  1244. getRotation: function(a, b) {
  1245. return 2 <= a.length && 2 <= b.length ? this.getAngle(b[1], b[0]) - this.getAngle(a[1], a[0]) : 0
  1246. },
  1247. isVertical: function(a) {
  1248. return a == q || a == f
  1249. },
  1250. setPrefixedCss: function(a, b, c, d) {
  1251. var e = ["", "Webkit", "Moz", "O", "ms"];
  1252. b = g.toCamelCase(b);
  1253. for (var f =
  1254. 0; f < e.length; f++) {
  1255. var s = b;
  1256. if (e[f] && (s = e[f] + s.slice(0, 1).toUpperCase() + s.slice(1)), s in a.style) {
  1257. a.style[s] = (null == d || d) && c || "";
  1258. break
  1259. }
  1260. }
  1261. },
  1262. toggleBehavior: function(a, b, c) {
  1263. if (b && a && a.style) {
  1264. g.each(b, function(b, d) {
  1265. g.setPrefixedCss(a, d, b, c)
  1266. });
  1267. var d = c && function() {
  1268. return !1
  1269. };
  1270. "none" == b.userSelect && (a.onselectstart = d);
  1271. "none" == b.userDrag && (a.ondragstart = d)
  1272. }
  1273. },
  1274. toCamelCase: function(a) {
  1275. return a.replace(/[_-]([a-z])/g, function(a) {
  1276. return a[1].toUpperCase()
  1277. })
  1278. }
  1279. }, B = c.event = {
  1280. preventMouseEvents: !1,
  1281. started: !1,
  1282. shouldDetect: !1,
  1283. on: function(a, b, c, d) {
  1284. b = b.split(" ");
  1285. g.each(b, function(b) {
  1286. g.on(a, b, c);
  1287. d && d(b)
  1288. })
  1289. },
  1290. off: function(a, b, c, d) {
  1291. b = b.split(" ");
  1292. g.each(b, function(b) {
  1293. g.off(a, b, c);
  1294. d && d(b)
  1295. })
  1296. },
  1297. onTouch: function(a, b, d) {
  1298. var l = this,
  1299. f = function(e) {
  1300. var f, F = e.type.toLowerCase(),
  1301. h = c.HAS_POINTEREVENTS;
  1302. (F = g.inStr(F, "mouse")) && l.preventMouseEvents || (F && b == n && 0 === e.button ? (l.preventMouseEvents = !1, l.shouldDetect = !0) : h && b == n ? l.shouldDetect = 1 === e.buttons : F || b != n || (l.preventMouseEvents = !0, l.shouldDetect = !0), h && b != r && C.updatePointer(b, e), l.shouldDetect &&
  1303. (f = l.doDetect.call(l, e, b, a, d)), f == r && (l.preventMouseEvents = !1, l.shouldDetect = !1, C.reset()), h && b == r && C.updatePointer(b, e))
  1304. };
  1305. return this.on(a, e[b], f), f
  1306. },
  1307. doDetect: function(a, b, c, d) {
  1308. var e = this.getTouchList(a, b),
  1309. f = b,
  1310. g = e.trigger,
  1311. k = e.length;
  1312. b == n ? g = D : b == r && (g = z, k = e.length - (a.changedTouches ? a.changedTouches.length : 1));
  1313. 0 < k && this.started && (f = y);
  1314. this.started = !0;
  1315. a = this.collectEventData(c, f, e, a);
  1316. return b != r && d.call(x, a), g && (a.changedLength = k, a.eventType = g, d.call(x, a), a.eventType = f, delete a.changedLength), f == r &&
  1317. (d.call(x, a), this.started = !1), f
  1318. },
  1319. determineEventTypes: function() {
  1320. var b;
  1321. return b = c.HAS_POINTEREVENTS ? a.PointerEvent ? ["pointerdown", "pointermove", "pointerup pointercancel lostpointercapture"] : ["MSPointerDown", "MSPointerMove", "MSPointerUp MSPointerCancel MSLostPointerCapture"] : c.NO_MOUSEEVENTS ? ["touchstart", "touchmove", "touchend touchcancel"] : ["touchstart mousedown", "touchmove mousemove", "touchend touchcancel mouseup"], e[n] = b[0], e[y] = b[1], e[r] = b[2], e
  1322. },
  1323. getTouchList: function(a, b) {
  1324. if (c.HAS_POINTEREVENTS) return C.getTouchList();
  1325. if (a.touches) {
  1326. if (b == y) return a.touches;
  1327. var d = [],
  1328. l = [].concat(g.toArray(a.touches), g.toArray(a.changedTouches)),
  1329. e = [];
  1330. return g.each(l, function(a) {
  1331. !1 === g.inArray(d, a.identifier) && e.push(a);
  1332. d.push(a.identifier)
  1333. }), e
  1334. }
  1335. return a.identifier = 1, [a]
  1336. },
  1337. collectEventData: function(a, b, c, d) {
  1338. a = v;
  1339. return g.inStr(d.type, "mouse") || C.matchType(A, d) ? a = A : C.matchType(w, d) && (a = w), {
  1340. center: g.getCenter(c),
  1341. timeStamp: Date.now(),
  1342. target: d.target,
  1343. touches: c,
  1344. eventType: b,
  1345. pointerType: a,
  1346. srcEvent: d,
  1347. preventDefault: function() {
  1348. var a = this.srcEvent;
  1349. a.preventManipulation && a.preventManipulation();
  1350. a.preventDefault && a.preventDefault()
  1351. },
  1352. stopPropagation: function() {
  1353. this.srcEvent.stopPropagation()
  1354. },
  1355. stopDetect: function() {
  1356. return x.stopDetect()
  1357. }
  1358. }
  1359. }
  1360. }, C = c.PointerEvent = {
  1361. pointers: {},
  1362. getTouchList: function() {
  1363. var a = [];
  1364. return g.each(this.pointers, function(b) {
  1365. a.push(b)
  1366. }), a
  1367. },
  1368. updatePointer: function(a, b) {
  1369. a == r || a != r && 1 !== b.buttons ? delete this.pointers[b.pointerId] : (b.identifier = b.pointerId, this.pointers[b.pointerId] = b)
  1370. },
  1371. matchType: function(a, b) {
  1372. if (!b.pointerType) return !1;
  1373. var c = b.pointerType,
  1374. d = {};
  1375. return d[A] = c === (b.MSPOINTER_TYPE_MOUSE || A), d[v] = c === (b.MSPOINTER_TYPE_TOUCH || v), d[w] = c === (b.MSPOINTER_TYPE_PEN || w), d[a]
  1376. },
  1377. reset: function() {
  1378. this.pointers = {}
  1379. }
  1380. }, x = c.detection = {
  1381. gestures: [],
  1382. current: null,
  1383. previous: null,
  1384. stopped: !1,
  1385. startDetect: function(a, b) {
  1386. this.current || (this.stopped = !1, this.current = {
  1387. inst: a,
  1388. startEvent: g.extend({}, b),
  1389. lastEvent: !1,
  1390. lastCalcEvent: !1,
  1391. futureCalcEvent: !1,
  1392. lastCalcData: {},
  1393. name: ""
  1394. }, this.detect(b))
  1395. },
  1396. detect: function(a) {
  1397. if (this.current && !this.stopped) {
  1398. a = this.extendEventData(a);
  1399. var b = this.current.inst,
  1400. c = b.options;
  1401. return g.each(this.gestures, function(d) {
  1402. return !this.stopped && b.enabled && c[d.name] && !1 === d.handler.call(d, a, b) ? (this.stopDetect(), !1) : void 0
  1403. }, this), this.current && (this.current.lastEvent = a), a.eventType == r && this.stopDetect(), a
  1404. }
  1405. },
  1406. stopDetect: function() {
  1407. this.previous = g.extend({}, this.current);
  1408. this.current = null;
  1409. this.stopped = !0
  1410. },
  1411. getCalculatedData: function(a, b, d, e, f) {
  1412. var m = this.current,
  1413. s = !1,
  1414. k = m.lastCalcEvent,
  1415. h = m.lastCalcData;
  1416. k && a.timeStamp - k.timeStamp > c.CALCULATE_INTERVAL &&
  1417. (b = k.center, d = a.timeStamp - k.timeStamp, e = a.center.clientX - k.center.clientX, f = a.center.clientY - k.center.clientY, s = !0);
  1418. a.eventType != D && a.eventType != z || (m.futureCalcEvent = a);
  1419. (!m.lastCalcEvent || s) && (h.velocity = g.getVelocity(d, e, f), h.angle = g.getAngle(b, a.center), h.direction = g.getDirection(b, a.center), m.lastCalcEvent = m.futureCalcEvent || a, m.futureCalcEvent = a);
  1420. a.velocityX = h.velocity.x;
  1421. a.velocityY = h.velocity.y;
  1422. a.interimAngle = h.angle;
  1423. a.interimDirection = h.direction
  1424. },
  1425. extendEventData: function(a) {
  1426. var b = this.current,
  1427. c = b.startEvent,
  1428. b = b.lastEvent || c;
  1429. a.eventType != D && a.eventType != z || (c.touches = [], g.each(a.touches, function(a) {
  1430. c.touches.push({
  1431. clientX: a.clientX,
  1432. clientY: a.clientY
  1433. })
  1434. }));
  1435. var d = a.timeStamp - c.timeStamp,
  1436. e = a.center.clientX - c.center.clientX,
  1437. f = a.center.clientY - c.center.clientY;
  1438. return this.getCalculatedData(a, b.center, d, e, f), g.extend(a, {
  1439. startEvent: c,
  1440. deltaTime: d,
  1441. deltaX: e,
  1442. deltaY: f,
  1443. distance: g.getDistance(c.center, a.center),
  1444. angle: g.getAngle(c.center, a.center),
  1445. direction: g.getDirection(c.center, a.center),
  1446. scale: g.getScale(c.touches,
  1447. a.touches),
  1448. rotation: g.getRotation(c.touches, a.touches)
  1449. }), a
  1450. },
  1451. register: function(a) {
  1452. var d = a.defaults || {};
  1453. return d[a.name] === b && (d[a.name] = !0), g.extend(c.defaults, d, !0), a.index = a.index || 1E3, this.gestures.push(a), this.gestures.sort(function(a, b) {
  1454. return a.index < b.index ? -1 : a.index > b.index ? 1 : 0
  1455. }), this.gestures
  1456. }
  1457. };
  1458. c.Instance = function(a, b) {
  1459. var e = this;
  1460. d();
  1461. this.element = a;
  1462. this.enabled = !0;
  1463. g.each(b, function(a, c) {
  1464. delete b[c];
  1465. b[g.toCamelCase(c)] = a
  1466. });
  1467. this.options = g.extend(g.extend({}, c.defaults), b || {});
  1468. this.options.behavior &&
  1469. g.toggleBehavior(this.element, this.options.behavior, !0);
  1470. this.eventStartHandler = B.onTouch(a, n, function(a) {
  1471. e.enabled && a.eventType == n ? x.startDetect(e, a) : a.eventType == D && x.detect(a)
  1472. });
  1473. this.eventHandlers = []
  1474. };
  1475. c.Instance.prototype = {
  1476. on: function(a, b) {
  1477. var c = this;
  1478. return B.on(c.element, a, b, function(a) {
  1479. c.eventHandlers.push({
  1480. gesture: a,
  1481. handler: b
  1482. })
  1483. }), c
  1484. },
  1485. off: function(a, b) {
  1486. var c = this;
  1487. return B.off(c.element, a, b, function(a) {
  1488. a = g.inArray({
  1489. gesture: a,
  1490. handler: b
  1491. });
  1492. !1 !== a && c.eventHandlers.splice(a, 1)
  1493. }), c
  1494. },
  1495. trigger: function(a,
  1496. b) {
  1497. b || (b = {});
  1498. var d = c.DOCUMENT.createEvent("Event");
  1499. d.initEvent(a, !0, !0);
  1500. d.gesture = b;
  1501. var e = this.element;
  1502. return g.hasParent(b.target, e) && (e = b.target), e.dispatchEvent(d), this
  1503. },
  1504. enable: function(a) {
  1505. return this.enabled = a, this
  1506. },
  1507. dispose: function() {
  1508. var a, b;
  1509. g.toggleBehavior(this.element, this.options.behavior, !1);
  1510. for (a = -1; b = this.eventHandlers[++a];) g.off(this.element, b.gesture, b.handler);
  1511. return this.eventHandlers = [], B.off(this.element, e[n], this.eventStartHandler), null
  1512. }
  1513. };
  1514. (function(a) {
  1515. var b = !1;
  1516. c.gestures.Drag = {
  1517. name: a,
  1518. index: 50,
  1519. handler: function(c, d) {
  1520. var e = x.current;
  1521. if (!(0 < d.options.dragMaxTouches && c.touches.length > d.options.dragMaxTouches)) switch (c.eventType) {
  1522. case n:
  1523. b = !1;
  1524. break;
  1525. case y:
  1526. if (c.distance < d.options.dragMinDistance && e.name != a) break;
  1527. var m = e.startEvent.center;
  1528. if (e.name != a && (e.name = a, d.options.dragDistanceCorrection && 0 < c.distance)) {
  1529. var s = Math.abs(d.options.dragMinDistance / c.distance);
  1530. m.pageX += c.deltaX * s;
  1531. m.pageY += c.deltaY * s;
  1532. m.clientX += c.deltaX * s;
  1533. m.clientY += c.deltaY * s;
  1534. c = x.extendEventData(c)
  1535. }(e.lastEvent.dragLockToAxis ||
  1536. d.options.dragLockToAxis && d.options.dragLockMinDistance <= c.distance) && (c.dragLockToAxis = !0);
  1537. e = e.lastEvent.direction;
  1538. c.dragLockToAxis && e !== c.direction && (c.direction = g.isVertical(e) ? 0 > c.deltaY ? q : f : 0 > c.deltaX ? h : u);
  1539. b || (d.trigger(a + "start", c), b = !0);
  1540. d.trigger(a, c);
  1541. d.trigger(a + c.direction, c);
  1542. e = g.isVertical(c.direction);
  1543. (d.options.dragBlockVertical && e || d.options.dragBlockHorizontal && !e) && c.preventDefault();
  1544. break;
  1545. case z:
  1546. b && c.changedLength <= d.options.dragMaxTouches && (d.trigger(a + "end", c), b = !1);
  1547. break;
  1548. case r:
  1549. b = !1
  1550. }
  1551. },
  1552. defaults: {
  1553. dragMinDistance: 10,
  1554. dragDistanceCorrection: !0,
  1555. dragMaxTouches: 1,
  1556. dragBlockHorizontal: !1,
  1557. dragBlockVertical: !1,
  1558. dragLockToAxis: !1,
  1559. dragLockMinDistance: 25
  1560. }
  1561. }
  1562. })("drag");
  1563. c.gestures.Gesture = {
  1564. name: "gesture",
  1565. index: 1337,
  1566. handler: function(a, b) {
  1567. b.trigger(this.name, a)
  1568. }
  1569. };
  1570. (function(a) {
  1571. var b;
  1572. c.gestures.Hold = {
  1573. name: a,
  1574. index: 10,
  1575. defaults: {
  1576. holdTimeout: 500,
  1577. holdThreshold: 2
  1578. },
  1579. handler: function(c, d) {
  1580. var e = d.options,
  1581. f = x.current;
  1582. switch (c.eventType) {
  1583. case n:
  1584. clearTimeout(b);
  1585. f.name = a;
  1586. b = setTimeout(function() {
  1587. f && f.name == a &&
  1588. d.trigger(a, c)
  1589. }, e.holdTimeout);
  1590. break;
  1591. case y:
  1592. c.distance > e.holdThreshold && clearTimeout(b);
  1593. break;
  1594. case z:
  1595. clearTimeout(b)
  1596. }
  1597. }
  1598. }
  1599. })("hold");
  1600. c.gestures.Release = {
  1601. name: "release",
  1602. index: 1 / 0,
  1603. handler: function(a, b) {
  1604. a.eventType == z && b.trigger(this.name, a)
  1605. }
  1606. };
  1607. c.gestures.Swipe = {
  1608. name: "swipe",
  1609. index: 40,
  1610. defaults: {
  1611. swipeMinTouches: 1,
  1612. swipeMaxTouches: 1,
  1613. swipeVelocityX: .6,
  1614. swipeVelocityY: .6
  1615. },
  1616. handler: function(a, b) {
  1617. if (a.eventType == z) {
  1618. var c = a.touches.length,
  1619. d = b.options;
  1620. c < d.swipeMinTouches || c > d.swipeMaxTouches || (a.velocityX > d.swipeVelocityX ||
  1621. a.velocityY > d.swipeVelocityY) && (b.trigger(this.name, a), b.trigger(this.name + a.direction, a))
  1622. }
  1623. }
  1624. };
  1625. (function(a) {
  1626. var b = !1;
  1627. c.gestures.Tap = {
  1628. name: a,
  1629. index: 100,
  1630. handler: function(c, d) {
  1631. var e, f, g = d.options,
  1632. k = x.current,
  1633. h = x.previous;
  1634. switch (c.eventType) {
  1635. case n:
  1636. b = !1;
  1637. break;
  1638. case y:
  1639. b = b || c.distance > g.tapMaxDistance;
  1640. break;
  1641. case r:
  1642. "touchcancel" != c.srcEvent.type && c.deltaTime < g.tapMaxTime && !b && (e = h && h.lastEvent && c.timeStamp - h.lastEvent.timeStamp, f = !1, h && h.name == a && e && e < g.doubleTapInterval && c.distance < g.doubleTapDistance && (d.trigger("doubletap",
  1643. c), f = !0), (!f || g.tapAlways) && (k.name = a, d.trigger(k.name, c)))
  1644. }
  1645. },
  1646. defaults: {
  1647. tapMaxTime: 250,
  1648. tapMaxDistance: 10,
  1649. tapAlways: !0,
  1650. doubleTapDistance: 20,
  1651. doubleTapInterval: 300
  1652. }
  1653. }
  1654. })("tap");
  1655. c.gestures.Touch = {
  1656. name: "touch",
  1657. index: -1 / 0,
  1658. defaults: {
  1659. preventDefault: !1,
  1660. preventMouse: !1
  1661. },
  1662. handler: function(a, b) {
  1663. return b.options.preventMouse && a.pointerType == A ? void a.stopDetect() : (b.options.preventDefault && a.preventDefault(), void(a.eventType == D && b.trigger("touch", a)))
  1664. }
  1665. };
  1666. (function(a) {
  1667. var b = !1;
  1668. c.gestures.Transform = {
  1669. name: a,
  1670. index: 45,
  1671. defaults: {
  1672. transformMinScale: .01,
  1673. transformMinRotation: 1
  1674. },
  1675. handler: function(c, d) {
  1676. switch (c.eventType) {
  1677. case n:
  1678. b = !1;
  1679. break;
  1680. case y:
  1681. if (2 > c.touches.length) break;
  1682. var e = Math.abs(1 - c.scale),
  1683. f = Math.abs(c.rotation);
  1684. if (e < d.options.transformMinScale && f < d.options.transformMinRotation) break;
  1685. x.current.name = a;
  1686. b || (d.trigger(a + "start", c), b = !0);
  1687. d.trigger(a, c);
  1688. f > d.options.transformMinRotation && d.trigger("rotate", c);
  1689. e > d.options.transformMinScale && (d.trigger("pinch", c), d.trigger("pinch" + (1 > c.scale ? "in" : "out"), c));
  1690. break;
  1691. case z:
  1692. b &&
  1693. 2 > c.changedLength && (d.trigger(a + "end", c), b = !1)
  1694. }
  1695. }
  1696. }
  1697. })("transform");
  1698. "function" == typeof define && define.amd ? define(function() {
  1699. return c
  1700. }) : "undefined" != typeof module && module.exports ? module.exports = c : a.Hammer = c
  1701. }(window);
  1702. (function(a) {
  1703. a.stringify = function(a) {
  1704. return JSON.stringify(a, function(a, b) {
  1705. return b instanceof Function || "function" == typeof b ? b.toString() : b instanceof RegExp ? "_PxEgEr_" + b : b
  1706. })
  1707. };
  1708. a.parse = function(a, d) {
  1709. var c = d ? /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)Z$/ : !1;
  1710. return JSON.parse(a, function(a, b) {
  1711. var d;
  1712. if ("string" != typeof b || 8 > b.length) return b;
  1713. d = b.substring(0, 8);
  1714. return c && b.match(c) ? new Date(b) : "function" === d ? eval("(" + b + ")") : "_PxEgEr_" === d ? eval(b.slice(8)) : b
  1715. })
  1716. };
  1717. a.clone = function(b, d) {
  1718. return a.parse(a.stringify(b),
  1719. d)
  1720. }
  1721. })("undefined" === typeof exports ? window.JSONfn = {} : exports);
  1722. (function() {
  1723. var a, b, d, c, e, f, h, q, u, A, v, w, n, y, r, z, D, g, B, C, x, W, K, X, Y, l, F, m, s, k, Q, H, Z, R, I, S, L, J, T, M, t, U, N, E, O, V, P, aa, p = [].indexOf || function(a) {
  1724. for (var b = 0, c = this.length; b < c; b++)
  1725. if (b in this && this[b] === a) return b;
  1726. return -1
  1727. }, ba = {}.hasOwnProperty;
  1728. t = [];
  1729. E = [];
  1730. O = null;
  1731. k = [];
  1732. d = [];
  1733. L = !1;
  1734. R = "ctrl";
  1735. S = "meta alt option ctrl shift cmd".split(" ");
  1736. P = [];
  1737. u = {
  1738. keys: [],
  1739. count: 0
  1740. };
  1741. y = function(a, b) {
  1742. var c;
  1743. if (a.filter) return a.filter(b);
  1744. var d, e, f;
  1745. f = [];
  1746. d = 0;
  1747. for (e = a.length; d < e; d++) c = a[d], b(c) && f.push(c);
  1748. return f
  1749. };
  1750. H = function() {
  1751. return console.log.apply(console,
  1752. arguments)
  1753. };
  1754. A = function(a, b) {
  1755. var c, d, e;
  1756. if (a.length !== b.length) return !1;
  1757. d = 0;
  1758. for (e = a.length; d < e; d++)
  1759. if (c = a[d], !(0 <= p.call(b, c))) return !1;
  1760. return !0
  1761. };
  1762. v = function(a, b) {
  1763. var c, d, e;
  1764. if (a.length !== b.length) return !1;
  1765. c = d = 0;
  1766. for (e = a.length; 0 <= e ? d < e : d > e; c = 0 <= e ? ++d : --d)
  1767. if (a[c] !== b[c]) return !1;
  1768. return !0
  1769. };
  1770. K = function(a, b) {
  1771. var c, d, e;
  1772. d = 0;
  1773. for (e = a.length; d < e; d++)
  1774. if (c = a[d], 0 > p.call(b, c)) return !1;
  1775. return !0
  1776. };
  1777. X = function(a, b) {
  1778. var c, d, e, f;
  1779. e = d = 0;
  1780. for (f = a.length; e < f; e++)
  1781. if (c = a[e], c = b.indexOf(c), c >= d) d = c;
  1782. else return !1;
  1783. return !0
  1784. };
  1785. J = function(a,
  1786. b) {
  1787. if ((b || keypress.suppress_event_defaults) && !keypress.force_event_defaults && (a.preventDefault ? a.preventDefault() : a.returnValue = !1, a.stopPropagation)) return a.stopPropagation()
  1788. };
  1789. f = function(a) {
  1790. if (a.prevent_repeat) return !1;
  1791. if ("function" === typeof a.on_keydown) return !0
  1792. };
  1793. Q = function(a) {
  1794. var b, c, d, e;
  1795. e = a.keys;
  1796. c = 0;
  1797. for (d = e.length; c < d; c++)
  1798. if (a = e[c], 0 <= p.call(k, a)) {
  1799. b = !0;
  1800. break
  1801. }
  1802. return b
  1803. };
  1804. r = function(a, b, c) {
  1805. "function" === typeof b["on_" + a] && J(c, !1 === b["on_" + a].call(b["this"], c, b.count));
  1806. "release" === a && (b.count = 0);
  1807. if ("keyup" ===
  1808. a) return b.keyup_fired = !0
  1809. };
  1810. Z = function(a, b) {
  1811. var c, d, e;
  1812. d = 0;
  1813. for (e = t.length; d < e; d++) c = t[d], (c.is_ordered && v(a, c.keys) || !c.is_ordered && A(a, c.keys)) && b(c)
  1814. };
  1815. z = function(a, b) {
  1816. var c, d, e;
  1817. d = 0;
  1818. for (e = t.length; d < e; d++) c = t[d], (c.is_ordered && X(c.keys, a) || !c.is_ordered && K(c.keys, a)) && b(c)
  1819. };
  1820. q = function(a) {
  1821. return 0 <= p.call(k, "cmd") && 0 > p.call(a, "cmd") ? !1 : !0
  1822. };
  1823. D = function(a) {
  1824. var b, c;
  1825. b = [];
  1826. c = y(k, function(b) {
  1827. return b !== a
  1828. });
  1829. c.push(a);
  1830. Z(c, function(a) {
  1831. if (q(a.keys)) return b.push(a)
  1832. });
  1833. z(c, function(a) {
  1834. if (!(0 <= p.call(b, a) || a.is_solitary) &&
  1835. q(a.keys)) return b.push(a)
  1836. });
  1837. return b
  1838. };
  1839. B = function(a) {
  1840. var b, c, d, e;
  1841. c = [];
  1842. d = 0;
  1843. for (e = t.length; d < e; d++) b = t[d], b.is_sequence || 0 <= p.call(b.keys, a) && q(b.keys) && c.push(b);
  1844. return c
  1845. };
  1846. e = function(a) {
  1847. var b, c, e, f, G, g, k, h, l, m, n;
  1848. g = !1;
  1849. G = !0;
  1850. e = !1;
  1851. if (0 <= p.call(d, a)) return !0;
  1852. if (d.length)
  1853. for (f = k = 0, m = d.length; 0 <= m ? k < m : k > m; f = 0 <= m ? ++k : --k)
  1854. if ((b = d[f]) && b.is_exclusive && a.is_exclusive) {
  1855. b = b.keys;
  1856. if (!g)
  1857. for (h = 0, l = b.length; h < l; h++)
  1858. if (c = b[h], g = !0, 0 > p.call(a.keys, c)) {
  1859. g = !1;
  1860. break
  1861. }
  1862. if (G && !g)
  1863. for (n = a.keys, h = 0, l = n.length; h < l; h++)
  1864. if (c = n[h],
  1865. G = !1, 0 > p.call(b, c)) {
  1866. G = !0;
  1867. break
  1868. }
  1869. g && (e ? N(d.splice(f, 1)) : (N(d.splice(f, 1, a)), e = !0), G = !1)
  1870. }
  1871. G && d.unshift(a);
  1872. return g || G
  1873. };
  1874. U = function(a) {
  1875. var b, c, e, f;
  1876. c = e = 0;
  1877. for (f = d.length; 0 <= f ? e < f : e > f; c = 0 <= f ? ++e : --e)
  1878. if (b = d[c], b === a) {
  1879. N(d.splice(c, 1));
  1880. break
  1881. }
  1882. };
  1883. N = function(a) {
  1884. if (a) return a.count = null, a.keyup_fired = null
  1885. };
  1886. c = function(a, b) {
  1887. var c, d, e, f;
  1888. E.push(a);
  1889. d = g();
  1890. if (d.length) {
  1891. e = 0;
  1892. for (f = d.length; e < f; e++) c = d[e], J(b, c.prevent_default);
  1893. O && clearTimeout(O); - 1 < keypress.sequence_delay && (O = setTimeout(function() {
  1894. return E = []
  1895. }, keypress.sequence_delay))
  1896. } else E =
  1897. []
  1898. };
  1899. g = function() {
  1900. var a, b, c, d, e, f, g, k, h, l, m;
  1901. d = [];
  1902. f = 0;
  1903. for (h = t.length; f < h; f++)
  1904. for (a = t[f], b = g = 1, l = E.length; 1 <= l ? g <= l : g >= l; b = 1 <= l ? ++g : --g)
  1905. if ((e = E.slice(-b), a.is_sequence) && (!(0 > p.call(a.keys, "shift")) || (e = y(e, function(a) {
  1906. return "shift" !== a
  1907. }), e.length))) {
  1908. b = k = 0;
  1909. for (m = e.length; 0 <= m ? k < m : k > m; b = 0 <= m ? ++k : --k)
  1910. if (a.keys[b] === e[b]) c = !0;
  1911. else {
  1912. c = !1;
  1913. break
  1914. }
  1915. c && d.push(a)
  1916. }
  1917. return d
  1918. };
  1919. C = function(a) {
  1920. var b, c, d, e, f, g, k, h, l, m, n;
  1921. g = 0;
  1922. for (l = t.length; g < l; g++)
  1923. if (b = t[g], b.is_sequence) {
  1924. c = k = 1;
  1925. for (m = E.length; 1 <= m ? k <= m : k >= m; c = 1 <= m ? ++k : --k)
  1926. if (f =
  1927. y(E, function(a) {
  1928. return 0 <= p.call(b.keys, "shift") ? !0 : "shift" !== a
  1929. }).slice(-c), b.keys.length === f.length)
  1930. for (c = h = 0, n = f.length; 0 <= n ? h < n : h > n; c = 0 <= n ? ++h : --h)
  1931. if (e = f[c], !(0 > p.call(b.keys, "shift") && "shift" === e || "shift" === a && 0 > p.call(b.keys, "shift")))
  1932. if (b.keys[c] === e) d = !0;
  1933. else {
  1934. d = !1;
  1935. break
  1936. }
  1937. if (d) return b
  1938. }
  1939. return !1
  1940. };
  1941. n = function(a, b) {
  1942. var c;
  1943. if (!b.shiftKey) return !1;
  1944. c = s[a];
  1945. return null != c ? c : !1
  1946. };
  1947. x = function(a, b, c) {
  1948. if (0 > p.call(a.keys, b)) return !1;
  1949. J(c, a && a.prevent_default);
  1950. if (0 <= p.call(k, b) && !f(a)) return !1;
  1951. b = e(a, b);
  1952. a.keyup_fired = !1;
  1953. a.is_counting && "function" === typeof a.on_keydown && (a.count += 1);
  1954. if (b) return r("keydown", a, c)
  1955. };
  1956. Y = function(a, b) {
  1957. var d, e, f, g;
  1958. (e = n(a, b)) && (a = e);
  1959. c(a, b);
  1960. (e = C(a)) && r("keydown", e, b);
  1961. for (d in I) e = I[d], b[e] && (d === a || 0 <= p.call(k, d) || k.push(d));
  1962. for (d in I)
  1963. if (e = I[d], d !== a && 0 <= p.call(k, d) && !b[e])
  1964. for (e = f = 0, g = k.length; 0 <= g ? f < g : f > g; e = 0 <= g ? ++f : --f) k[e] === d && k.splice(e, 1);
  1965. e = D(a);
  1966. f = 0;
  1967. for (g = e.length; f < g; f++) d = e[f], x(d, a, b);
  1968. e = B(a);
  1969. if (e.length)
  1970. for (f = 0, g = e.length; f < g; f++) d = e[f], J(b, d.prevent_default);
  1971. 0 > p.call(k, a) && k.push(a)
  1972. };
  1973. W = function(a, b, c) {
  1974. var d, e;
  1975. e = Q(a);
  1976. a.keyup_fired || (d = k.slice(), d.push(c), a.is_solitary && !A(d, a.keys)) || (r("keyup", a, b), a.is_counting && "function" === typeof a.on_keyup && "function" !== typeof a.on_keydown && (a.count += 1));
  1977. e || (r("release", a, b), U(a))
  1978. };
  1979. l = function(a, b) {
  1980. var c, e, f, g, h, l;
  1981. e = a;
  1982. (f = n(a, b)) && (a = f);
  1983. f = s[e];
  1984. b.shiftKey ? f && 0 <= p.call(k, f) || (a = e) : e && 0 <= p.call(k, e) || (a = f);
  1985. (g = C(a)) && r("keyup", g, b);
  1986. if (0 > p.call(k, a)) return !1;
  1987. g = h = 0;
  1988. for (l = k.length; 0 <= l ? h < l : h > l; g = 0 <= l ? ++h : --h)
  1989. if ((c = k[g]) === a || c === f || c === e) {
  1990. k.splice(g,
  1991. 1);
  1992. break
  1993. }
  1994. e = d.length;
  1995. f = [];
  1996. g = 0;
  1997. for (h = d.length; g < h; g++) c = d[g], 0 <= p.call(c.keys, a) && f.push(c);
  1998. g = 0;
  1999. for (h = f.length; g < h; g++) c = f[g], W(c, b, a);
  2000. if (1 < e)
  2001. for (e = 0, g = d.length; e < g; e++) c = d[e], void 0 === c || 0 <= p.call(f, c) || Q(c) || U(c)
  2002. };
  2003. M = function(a, b) {
  2004. var c;
  2005. if (L) k.length && (k = []);
  2006. else if (b || k.length)
  2007. if (c = w(a.keyCode)) return b ? Y(c, a) : l(c, a)
  2008. };
  2009. V = function(a) {
  2010. var b, c, d, e;
  2011. e = [];
  2012. b = c = 0;
  2013. for (d = t.length; 0 <= d ? c < d : c > d; b = 0 <= d ? ++c : --c)
  2014. if (a === t[b]) {
  2015. t.splice(b, 1);
  2016. break
  2017. } else e.push(void 0);
  2018. return e
  2019. };
  2020. aa = function(a) {
  2021. var b, c, d, e, f;
  2022. a.keys.length ||
  2023. H("You're trying to bind a combo with no keys.");
  2024. c = e = 0;
  2025. for (f = a.keys.length; 0 <= f ? e < f : e > f; c = 0 <= f ? ++e : --e) d = a.keys[c], (b = F[d]) && (d = a.keys[c] = b), "meta" === d && a.keys.splice(c, 1, R), "cmd" === d && H('Warning: use the "meta" key rather than "cmd" for Windows compatibility');
  2026. f = a.keys;
  2027. b = 0;
  2028. for (e = f.length; b < e; b++)
  2029. if (d = f[b], 0 > p.call(P, d)) return H('Do not recognize the key "' + d + '"'), !1;
  2030. if (0 <= p.call(a.keys, "meta") || 0 <= p.call(a.keys, "cmd")) {
  2031. b = a.keys.slice();
  2032. e = 0;
  2033. for (f = S.length; e < f; e++) d = S[e], -1 < (c = b.indexOf(d)) && b.splice(c,
  2034. 1);
  2035. 1 < b.length && H("META and CMD key combos cannot have more than 1 non-modifier keys", a, b)
  2036. }
  2037. return !0
  2038. };
  2039. h = function(a) {
  2040. var b;
  2041. if (0 <= p.call(k, "cmd") && "cmd" !== (b = w(a.keyCode)) && "shift" !== b && "alt" !== b && "caps" !== b && "tab" !== b) return M(a, !1)
  2042. };
  2043. window.keypress = {};
  2044. keypress.force_event_defaults = !1;
  2045. keypress.suppress_event_defaults = !1;
  2046. keypress.sequence_delay = 800;
  2047. keypress.get_registered_combos = function() {
  2048. return t
  2049. };
  2050. keypress.reset = function() {
  2051. t = []
  2052. };
  2053. keypress.combo = function(a, b, c) {
  2054. null == c && (c = !1);
  2055. return keypress.register_combo({
  2056. keys: a,
  2057. on_keydown: b,
  2058. prevent_default: c
  2059. })
  2060. };
  2061. keypress.counting_combo = function(a, b, c) {
  2062. null == c && (c = !1);
  2063. return keypress.register_combo({
  2064. keys: a,
  2065. is_counting: !0,
  2066. is_ordered: !0,
  2067. on_keydown: b,
  2068. prevent_default: c
  2069. })
  2070. };
  2071. keypress.sequence_combo = function(a, b, c) {
  2072. null == c && (c = !1);
  2073. return keypress.register_combo({
  2074. keys: a,
  2075. on_keydown: b,
  2076. is_sequence: !0,
  2077. prevent_default: c
  2078. })
  2079. };
  2080. keypress.register_combo = function(a) {
  2081. var b, c;
  2082. "string" === typeof a.keys && (a.keys = a.keys.split(" "));
  2083. for (b in u) ba.call(u, b) && (c = u[b], null == a[b] && (a[b] = c));
  2084. if (aa(a)) return t.push(a), !0
  2085. };
  2086. keypress.register_many = function(a) {
  2087. var b, c, d, e;
  2088. e = [];
  2089. c = 0;
  2090. for (d = a.length; c < d; c++) b = a[c], e.push(keypress.register_combo(b));
  2091. return e
  2092. };
  2093. keypress.unregister_combo = function(a) {
  2094. var b, c, d;
  2095. if (!a) return !1;
  2096. if (a.keys) return V(a);
  2097. d = [];
  2098. b = 0;
  2099. for (c = t.length; b < c; b++)(a = t[b]) && (A(keys, a.keys) ? d.push(V(a)) : d.push(void 0));
  2100. return d
  2101. };
  2102. keypress.unregister_many = function(a) {
  2103. var b, c, d, e;
  2104. e = [];
  2105. c = 0;
  2106. for (d = a.length; c < d; c++) b = a[c], e.push(keypress.unregister_combo(b));
  2107. return e
  2108. };
  2109. keypress.listen = function() {
  2110. return L = !1
  2111. };
  2112. keypress.stop_listening =
  2113. function() {
  2114. return L = !0
  2115. };
  2116. w = function(a) {
  2117. return m[a]
  2118. };
  2119. I = {
  2120. cmd: "metaKey",
  2121. ctrl: "ctrlKey",
  2122. shift: "shiftKey",
  2123. alt: "altKey"
  2124. };
  2125. F = {
  2126. escape: "esc",
  2127. control: "ctrl",
  2128. command: "cmd",
  2129. "break": "pause",
  2130. windows: "cmd",
  2131. option: "alt",
  2132. caps_lock: "caps",
  2133. apostrophe: "'",
  2134. semicolon: ";",
  2135. tilde: "~",
  2136. accent: "`",
  2137. scroll_lock: "scroll",
  2138. num_lock: "num"
  2139. };
  2140. s = {
  2141. "/": "?",
  2142. ".": ">",
  2143. ",": "<",
  2144. "'": '"',
  2145. ";": ":",
  2146. "[": "{",
  2147. "]": "}",
  2148. "\\": "|",
  2149. "`": "~",
  2150. "=": "+",
  2151. "-": "_",
  2152. 1: "!",
  2153. 2: "@",
  2154. 3: "#",
  2155. 4: "$",
  2156. 5: "%",
  2157. 6: "^",
  2158. 7: "&",
  2159. 8: "*",
  2160. 9: "(",
  2161. 0: ")"
  2162. };
  2163. m = {
  2164. 0: "\\",
  2165. 8: "backspace",
  2166. 9: "tab",
  2167. 12: "num",
  2168. 13: "enter",
  2169. 16: "shift",
  2170. 17: "ctrl",
  2171. 18: "alt",
  2172. 19: "pause",
  2173. 20: "caps",
  2174. 27: "escape",
  2175. 32: "space",
  2176. 33: "pageup",
  2177. 34: "pagedown",
  2178. 35: "end",
  2179. 36: "home",
  2180. 37: "left",
  2181. 38: "up",
  2182. 39: "right",
  2183. 40: "down",
  2184. 44: "print",
  2185. 45: "insert",
  2186. 46: "delete",
  2187. 48: "0",
  2188. 49: "1",
  2189. 50: "2",
  2190. 51: "3",
  2191. 52: "4",
  2192. 53: "5",
  2193. 54: "6",
  2194. 55: "7",
  2195. 56: "8",
  2196. 57: "9",
  2197. 65: "a",
  2198. 66: "b",
  2199. 67: "c",
  2200. 68: "d",
  2201. 69: "e",
  2202. 70: "f",
  2203. 71: "g",
  2204. 72: "h",
  2205. 73: "i",
  2206. 74: "j",
  2207. 75: "k",
  2208. 76: "l",
  2209. 77: "m",
  2210. 78: "n",
  2211. 79: "o",
  2212. 80: "p",
  2213. 81: "q",
  2214. 82: "r",
  2215. 83: "s",
  2216. 84: "t",
  2217. 85: "u",
  2218. 86: "v",
  2219. 87: "w",
  2220. 88: "x",
  2221. 89: "y",
  2222. 90: "z",
  2223. 91: "cmd",
  2224. 92: "cmd",
  2225. 93: "cmd",
  2226. 96: "num_0",
  2227. 97: "num_1",
  2228. 98: "num_2",
  2229. 99: "num_3",
  2230. 100: "num_4",
  2231. 101: "num_5",
  2232. 102: "num_6",
  2233. 103: "num_7",
  2234. 104: "num_8",
  2235. 105: "num_9",
  2236. 106: "num_multiply",
  2237. 107: "num_add",
  2238. 108: "num_enter",
  2239. 109: "num_subtract",
  2240. 110: "num_decimal",
  2241. 111: "num_divide",
  2242. 124: "print",
  2243. 144: "num",
  2244. 145: "scroll",
  2245. 186: ";",
  2246. 187: "=",
  2247. 188: ",",
  2248. 189: "-",
  2249. 190: ".",
  2250. 191: "/",
  2251. 192: "`",
  2252. 219: "[",
  2253. 220: "\\",
  2254. 221: "]",
  2255. 222: "'",
  2256. 223: "`",
  2257. 224: "cmd",
  2258. 57392: "ctrl",
  2259. 63289: "num"
  2260. };
  2261. for (b in m) a = m[b], P.push(a);
  2262. for (b in s) a = s[b], P.push(a); - 1 !== navigator.userAgent.indexOf("Mac OS X") && (R = "cmd"); - 1 !== navigator.userAgent.indexOf("Opera") &&
  2263. (m["17"] = "cmd");
  2264. T = function(a) {
  2265. return (document.attachEvent ? "complete" === document.readyState : "loading" !== document.readyState) ? a() : setTimeout(function() {
  2266. return T(a)
  2267. }, 9)
  2268. };
  2269. T(function() {
  2270. var a;
  2271. a = function(a, b, c) {
  2272. if (a.addEventListener) return a.addEventListener(b, c);
  2273. if (a.attachEvent) return a.attachEvent("on" + b, c)
  2274. };
  2275. a(document.body, "keydown", function(a) {
  2276. a = a || window.event;
  2277. M(a, !0);
  2278. return h(a)
  2279. });
  2280. a(document.body, "keyup", function(a) {
  2281. a = a || window.event;
  2282. return M(a, !1)
  2283. });
  2284. return a(window, "blur", function() {
  2285. var a, b, c;
  2286. b =
  2287. 0;
  2288. for (c = k.length; b < c; b++) a = k[b], l(a, {});
  2289. k = [];
  2290. return []
  2291. })
  2292. })
  2293. }).call(this);