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.
 
 
 

67 lines
1.1 KiB

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