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.
 
 
 

47 lines
1.0 KiB

  1. define([
  2. '../misc/fileLister'
  3. ], function(
  4. fileLister
  5. ) {
  6. var onReady = null;
  7. var components = {
  8. components: {},
  9. waiting: null,
  10. init: function(callback) {
  11. onReady = callback;
  12. this.getComponentNames();
  13. },
  14. getComponentNames: function() {
  15. this.waiting = fileLister.getFolder('./components/');
  16. this.waiting = this.waiting.filter(w => (
  17. (w.indexOf('components') == -1) &&
  18. (w.indexOf('cpnBase') == -1) &&
  19. (w.indexOf('projectile') == -1)
  20. ));
  21. this.onGetComponentNames();
  22. },
  23. onGetComponentNames: function() {
  24. for (var i = 0; i < this.waiting.length; i++) {
  25. var name = this.waiting[i];
  26. this.getComponent(name);
  27. }
  28. },
  29. getComponent: function(name) {
  30. require([ './components/' + name ], this.onGetComponent.bind(this));
  31. },
  32. onGetComponent: function(template) {
  33. this.waiting.spliceWhere(w => w == template.type + '.js');
  34. this.components[template.type] = template;
  35. if (this.waiting.length == 0) {
  36. delete this.waiting;
  37. onReady();
  38. }
  39. }
  40. };
  41. return components;
  42. });