You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

113 line
1.8 KiB

  1. /* global _, scale, scaleMult, isMobile */
  2. window.scale = 40;
  3. window.scaleMult = 5;
  4. window.isMobile = /Mobi|Android/i.test(navigator.userAgent);
  5. //eslint-disable-next-line no-extend-native
  6. Array.prototype.firstIndex = function (callback, thisArg) {
  7. let T = thisArg;
  8. let O = Object(this);
  9. let len = O.length >>> 0;
  10. let k = 0;
  11. while (k < len) {
  12. let kValue;
  13. if (k in O) {
  14. kValue = O[k];
  15. if (callback.call(T, kValue, k, O))
  16. return k;
  17. }
  18. k++;
  19. }
  20. return -1;
  21. };
  22. //eslint-disable-next-line no-extend-native
  23. Array.prototype.spliceWhere = function (callback, thisArg) {
  24. let T = thisArg;
  25. let O = Object(this);
  26. let len = O.length >>> 0;
  27. let k = 0;
  28. while (k < len) {
  29. let kValue;
  30. if (k in O) {
  31. kValue = O[k];
  32. if (callback.call(T, kValue, k, O)) {
  33. O.splice(k, 1);
  34. k--;
  35. }
  36. }
  37. k++;
  38. }
  39. };
  40. //eslint-disable-next-line no-extend-native
  41. Array.prototype.spliceFirstWhere = function (callback, thisArg) {
  42. let T = thisArg;
  43. let O = Object(this);
  44. let len = O.length >>> 0;
  45. let k = 0;
  46. while (k < len) {
  47. let kValue;
  48. if (k in O) {
  49. kValue = O[k];
  50. if (callback.call(T, kValue, k, O)) {
  51. O.splice(k, 1);
  52. return kValue;
  53. }
  54. }
  55. k++;
  56. }
  57. };
  58. //eslint-disable-next-line no-extend-native
  59. Object.defineProperty(Object.prototype, 'has', {
  60. enumerable: false,
  61. value: function (prop) {
  62. //eslint-disable-next-line no-undefined
  63. return (this.hasOwnProperty(prop) && this[prop] !== undefined && this[prop] !== null);
  64. }
  65. });
  66. window._ = {
  67. get2dArray: function (w, h, def) {
  68. def = def || 0;
  69. let result = [];
  70. for (let i = 0; i < w; i++) {
  71. let inner = [];
  72. for (let j = 0; j < h; j++) {
  73. if (def === 'array')
  74. inner.push([]);
  75. else
  76. inner.push(def);
  77. }
  78. result.push(inner);
  79. }
  80. return result;
  81. }
  82. };
  83. define([
  84. ], function (
  85. ) {
  86. return window._;
  87. });