Advertisement
nPhoenix

Slot UI

Aug 10th, 2019
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Game.Overworld.slotOnDragEnd = function (slot, index) {
  2.     var width = this.database.interface.party.slots.size.width,
  3.         height = this.database.interface.party.slots.size.height;
  4.  
  5.     // cacheia posição
  6.     var slotPosition = _.clone({
  7.         x: slot.sprite.getCenter().x,
  8.         y: slot.sprite.getCenter().y
  9.     });
  10.  
  11.     for (let i = 0; i < 6; i ++) {
  12.  
  13.         // se for ele mesmo, vai pro próximo
  14.         if (i == index)
  15.             continue;
  16.  
  17.         // pegar posição do "mouse" (na vdd o centro da sprite slot)
  18.         if (slotPosition.x >= this.slots[i].sprite.x && slotPosition.x <= this.slots[i].sprite.x + width &&
  19.            slotPosition.y >= this.slots[i].sprite.y && slotPosition.y <= this.slots[i].sprite.y + height) {
  20.            
  21.             // se slot estiver vazia, manda de volta pro local de origem
  22.             if (this.slots[i].isEmpty) {
  23.                 slot.sprite.x = this.database.interface.party.slots.positions[index].x;
  24.                 slot.sprite.y = this.database.interface.party.slots.positions[index].y;
  25.                 this.elementsFollowSlot(slot);
  26.             } else {
  27.                 // criando novo objeto dos monstros do jogador
  28.                 var new_order = _.clone(this.Data.CurrentMonsters);
  29.  
  30.                 // trocando monstros de lugar na variável
  31.                 this.Data.CurrentMonsters["monster" + index] = new_order["monster" + i];
  32.                 this.Data.CurrentMonsters["monster" + i] = new_order["monster" + index];
  33.  
  34.                 // enviar requisição ao servidor de mudança
  35.                 this.requestChangePartyPosition(index, i);
  36.  
  37.                 //this.changeSlotElements(index);
  38.                 //this.changeSlotElements(i);
  39.  
  40.                 console.log(this.Data.CurrentMonsters);
  41.  
  42.                 // false = não destruir background
  43.                 this.clearPartyInterface(false);
  44.  
  45.                 // redesenha slots
  46.                 this.appendPartySlots();
  47.                 this.appendSlotElements();
  48.             };
  49.             break;
  50.         } else {
  51.             // se não "colidir" com nenhuma slot: manda de volta pro local de origem
  52.             slot.sprite.x = this.database.interface.party.slots.positions[index].x;
  53.             slot.sprite.y = this.database.interface.party.slots.positions[index].y;
  54.             this.elementsFollowSlot(slot);
  55.         };
  56.     };
  57. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement