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.
 
 
 

52 lines
969 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.active != null)
  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. var nId = nItem.id;
  23. let findItem = items.find(function (item) {
  24. return (item.id == nId);
  25. });
  26. if (findItem) {
  27. $.extend(true, findItem, nItem);
  28. newItems.splice(i, 1);
  29. i--;
  30. nLen--;
  31. }
  32. }
  33. this.items.push.apply(this.items, blueprint.getItems || []);
  34. events.emit('onGetStashItems', this.items);
  35. }
  36. if (blueprint.destroyItems)
  37. events.emit('onDestroyStashItems', blueprint.destroyItems);
  38. }
  39. };
  40. });