A pixel art painter geared specifically at NES pixel art. Includes export for .chr binary file as well as palette and namespace data.
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

86 linhas
2.0KB

  1. const utils = {
  2. isInt:function(v){
  3. if (isNaN(v)){
  4. return false;
  5. }
  6. var x = parseFloat(v);
  7. return (x | 0) === x;
  8. },
  9. isElement:function(el){
  10. // Code based on...
  11. // https://stackoverflow.com/questions/384286/javascript-isdom-how-do-you-check-if-a-javascript-object-is-a-dom-object
  12. try {
  13. // Using W3 DOM2 (works for FF, Opera and Chrome)
  14. return el instanceof HTMLElement;
  15. } catch(e) {
  16. // Browsers not supporting W3 DOM2 don't have HTMLElement and
  17. // an exception is thrown and we end up here. Testing some
  18. // properties that all elements have (works on IE7)
  19. return (typeof(el) === "object") &&
  20. (el.nodeType === 1) &&
  21. (typeof(el.style) === "object") &&
  22. (typeof(el.ownerDocument) === "object");
  23. }
  24. },
  25. range:function(a, b, step){
  26. var arr = [];
  27. if (!isNaN(a) && !isNaN(b)){
  28. if (a == b || step < 0){
  29. arr.push(a);
  30. } else {
  31. if (a < b){
  32. for (var i=a; i <= b; i+=step)
  33. arr.push(i);
  34. } else {
  35. for (var i=a; i >= b; i-=step)
  36. arr.push(i);
  37. }
  38. }
  39. }
  40. return arr;
  41. },
  42. debounce:function(func, delay, scope){
  43. var timeout = null;
  44. return function(){
  45. //var context = this;
  46. var context = scope || this;
  47. var args = arguments;
  48. clearTimeout(timeout);
  49. timeout = setTimeout(function(){
  50. func.apply(context, args);
  51. }, delay);
  52. };
  53. },
  54. throttle:function(func, threshold, scope){
  55. threshold || (threshold = 250);
  56. var lst = 0;
  57. var timer;
  58. return function(){
  59. var context = scope || this;
  60. var args = arguments;
  61. var now = Date.now();
  62. if (now < lst + threshold){
  63. clearTimeout(timer);
  64. timer = setTimeout(function(){
  65. lst = now;
  66. func.apply(context, args);
  67. }, threshold);
  68. } else {
  69. lst = now;
  70. func.apply(context, args);
  71. }
  72. };
  73. }
  74. };
  75. Object.freeze(utils);
  76. export default utils;