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.
 
 
 

74 lines
1.2 KiB

  1. define([
  2. 'js/system/events'
  3. ], function (
  4. events
  5. ) {
  6. let resources = {
  7. spriteNames: [
  8. 'charas',
  9. 'tiles',
  10. 'walls',
  11. 'mobs',
  12. 'bosses',
  13. 'animBigObjects',
  14. 'bigObjects',
  15. 'objects',
  16. 'characters',
  17. 'attacks',
  18. 'ui',
  19. 'abilityIcons',
  20. 'uiIcons',
  21. 'items',
  22. 'materials',
  23. 'questItems',
  24. 'auras',
  25. 'sprites',
  26. 'animChar',
  27. 'animMob',
  28. 'animBoss',
  29. 'white',
  30. 'ray',
  31. 'consumables',
  32. 'images/skins/0001.png',
  33. 'images/skins/0010.png'
  34. ],
  35. sprites: {},
  36. ready: false,
  37. init: function (list) {
  38. list.forEach(function (l) {
  39. this.spriteNames.push(l);
  40. }, this);
  41. this.spriteNames.forEach(function (s) {
  42. let sprite = {
  43. image: (new Image()),
  44. ready: false
  45. };
  46. sprite.image.src = s.indexOf('png') > -1 ? s : 'images/' + s + '.png';
  47. sprite.image.onload = this.onSprite.bind(this, sprite);
  48. this.sprites[s] = sprite;
  49. }, this);
  50. },
  51. onSprite: function (sprite) {
  52. sprite.ready = true;
  53. let readyCount = 0;
  54. for (let s in this.sprites) {
  55. if (this.sprites[s].ready)
  56. readyCount++;
  57. }
  58. if (readyCount == this.spriteNames.length)
  59. this.onReady();
  60. },
  61. onReady: function () {
  62. this.ready = true;
  63. events.emit('onResourcesLoaded');
  64. }
  65. };
  66. return resources;
  67. });