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.
 
 
 

50 lines
930 B

  1. define([
  2. 'js/system/events'
  3. ], function (
  4. events
  5. ) {
  6. return {
  7. type: 'stash',
  8. active: false,
  9. items: null,
  10. init: function () {
  11. events.emit('onGetStashItems', this.items);
  12. },
  13. extend: function (blueprint) {
  14. if (blueprint.has('active'))
  15. this.active = blueprint.active;
  16. if (blueprint.getItems) {
  17. let items = this.items;
  18. let newItems = blueprint.getItems || [];
  19. let nLen = newItems.length;
  20. for (let i = 0; i < nLen; i++) {
  21. let nItem = newItems[i];
  22. let nId = nItem.id;
  23. let findItem = items.find(f => f.id === nId);
  24. if (findItem) {
  25. $.extend(true, findItem, nItem);
  26. newItems.splice(i, 1);
  27. i--;
  28. nLen--;
  29. }
  30. }
  31. this.items.push.apply(this.items, blueprint.getItems || []);
  32. events.emit('onGetStashItems', this.items);
  33. }
  34. if (blueprint.destroyItems)
  35. events.emit('onDestroyStashItems', blueprint.destroyItems);
  36. }
  37. };
  38. });