Rewrote how item drag and drop works. Need to update charId's to keep up.
This commit is contained in:
@@ -174,71 +174,93 @@ Template.inventoryItem.helpers({
|
||||
|
||||
Template.layout.events({
|
||||
"dragstart .inventoryItem": function(event, instance){
|
||||
event.originalEvent.dataTransfer.setData("dicecloud-id/items", this._id);
|
||||
Session.set("inventory.dragItemId", this._id);
|
||||
Session.set("inventory.dragItemOriginalContainer", this.container);
|
||||
Session.set("inventory.dragItemOriginalCharacter", this.charId);
|
||||
},
|
||||
"dragover .itemContainer, dragenter .itemContainer":
|
||||
function(event, instance){
|
||||
if (_.contains(event.originalEvent.dataTransfer.types, "dicecloud-id/items")){
|
||||
event.preventDefault();
|
||||
}
|
||||
},
|
||||
"dragover .equipmentContainer, dragenter .equipmentContainer":
|
||||
function(event, instance){
|
||||
if (_.contains(event.originalEvent.dataTransfer.types, "dicecloud-id/items")){
|
||||
event.preventDefault();
|
||||
}
|
||||
},
|
||||
"dragover .carriedContainer, dragenter .carriedContainer":
|
||||
function(event, instance){
|
||||
if (_.contains(event.originalEvent.dataTransfer.types, "dicecloud-id/items")){
|
||||
event.preventDefault();
|
||||
}
|
||||
},
|
||||
"dragover .characterRepresentative, dragenter .characterRepresentative":
|
||||
function(event, instance){
|
||||
if (_.contains(event.originalEvent.dataTransfer.types, "dicecloud-id/items")){
|
||||
event.preventDefault();
|
||||
}
|
||||
},
|
||||
"dragend .inventoryItem": function(event, instance){
|
||||
resetInvetorySession(); //this is a valid drop zone
|
||||
Session.set("inventory.dragItemId", null);
|
||||
},
|
||||
"dragover .itemContainer": function(event, instance){
|
||||
event.preventDefault();
|
||||
},
|
||||
"dragover .equipmentContainer": function(event, instance){
|
||||
event.preventDefault();
|
||||
},
|
||||
"dragover .carriedContainer": function(event, instance){
|
||||
event.preventDefault();
|
||||
},
|
||||
"drop .itemContainer": function(event, instacne){
|
||||
var item = Items.findOne(Session.get("inventory.dragItemId"));
|
||||
"drop .itemContainer": function(event, instance){
|
||||
var itemId = event.originalEvent.dataTransfer.getData("dicecloud-id/items");
|
||||
if (event.ctrlKey){
|
||||
//split the stack to the container
|
||||
GlobalUI.showDialog({
|
||||
template: "splitStackDialog",
|
||||
data: {
|
||||
id: item._id,
|
||||
id: itemId,
|
||||
parentCollection: "Containers",
|
||||
parentId: this._id,
|
||||
},
|
||||
});
|
||||
} else {
|
||||
//move item to the container
|
||||
item.moveToContainer(this._id);
|
||||
Meteor.call("moveItemToContainer", itemId, this._id);
|
||||
}
|
||||
resetInvetorySession();
|
||||
Session.set("inventory.dragItemId", null);
|
||||
},
|
||||
"drop .equipmentContainer": function(event, instance){
|
||||
var charId = Session.get("inventory.dragItemOriginalCharacter");
|
||||
var item = Items.findOne(Session.get("inventory.dragItemId"));
|
||||
item.equip(charId);
|
||||
resetInvetorySession();
|
||||
var itemId = event.originalEvent.dataTransfer.getData("dicecloud-id/items");
|
||||
Meteor.call("equipItem", itemId, this._id);
|
||||
Session.set("inventory.dragItemId", null);
|
||||
},
|
||||
"drop .carriedContainer": function(event, instance){
|
||||
var charId = Session.get("inventory.dragItemOriginalCharacter");
|
||||
var item = Items.findOne(Session.get("inventory.dragItemId"));
|
||||
var itemId = event.originalEvent.dataTransfer.getData("dicecloud-id/items");
|
||||
if (event.ctrlKey){
|
||||
//split the stack to the container
|
||||
GlobalUI.showDialog({
|
||||
template: "splitStackDialog",
|
||||
data: {
|
||||
id: item._id,
|
||||
id: itemId,
|
||||
parentCollection: "Characters",
|
||||
parentId: this._id,
|
||||
},
|
||||
});
|
||||
} else {
|
||||
//move item to the character
|
||||
item.moveToCharacter(this._id);
|
||||
Meteor.call("moveItemToCharacter", itemId, this._id);
|
||||
}
|
||||
resetInvetorySession();
|
||||
Session.set("inventory.dragItemId", null);
|
||||
},
|
||||
"drop .characterRepresentative": function(event, instance) {
|
||||
var itemId = event.originalEvent.dataTransfer.getData("dicecloud-id/items");
|
||||
if (event.ctrlKey){
|
||||
//split the stack to the container
|
||||
GlobalUI.showDialog({
|
||||
template: "splitStackDialog",
|
||||
data: {
|
||||
id: itemId,
|
||||
parentCollection: "Characters",
|
||||
parentId: this._id,
|
||||
},
|
||||
});
|
||||
} else {
|
||||
//move item to the character
|
||||
Meteor.call("moveItemToCharacter", itemId, this._id);
|
||||
}
|
||||
Session.set("inventory.dragItemId", null);
|
||||
},
|
||||
});
|
||||
|
||||
var resetInvetorySession = function(){
|
||||
_.defer(function(){
|
||||
Session.set("inventory.dragItemId", null);
|
||||
Session.set("inventory.dragItemOriginalContainer", null);
|
||||
Session.set("inventory.dragItemOriginalCharacter", null);
|
||||
});
|
||||
};
|
||||
|
||||
@@ -81,13 +81,10 @@ Template.itemEdit.events({
|
||||
},
|
||||
"change #equippedInput": function(event){
|
||||
var equipped = Template.instance().find("#equippedInput").checked;
|
||||
var item = Items.findOne(this._id);
|
||||
if (item){
|
||||
if (equipped){
|
||||
item.equip();
|
||||
} else {
|
||||
item.unequip();
|
||||
}
|
||||
if (equipped){
|
||||
Meteor.call("equipItem", this._id, this.charId);
|
||||
} else {
|
||||
Meteor.call("unequipItem", this._id, this.charId);
|
||||
}
|
||||
},
|
||||
"change #attunementCheckbox": function(event){
|
||||
@@ -107,7 +104,6 @@ Template.containerDropdown.events({
|
||||
var detail = event.originalEvent.detail;
|
||||
if (!detail.isSelected) return;
|
||||
var containerId = detail.item.getAttribute("name");
|
||||
var item = Items.findOne(Template.currentData()._id);
|
||||
item.moveToContainer(containerId);
|
||||
Meteor.call("moveItemToContainer", Template.currentData()._id, containerId);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -7,13 +7,12 @@ Template.splitStackDialog.helpers({
|
||||
|
||||
Template.splitStackDialog.events({
|
||||
"tap #moveButton": function(event, instance){
|
||||
var item = Items.findOne(this.id);
|
||||
if (item){
|
||||
item.splitToParent(
|
||||
{collection: this.parentCollection , id: this.parentId},
|
||||
+instance.find("#quantityInput").value
|
||||
);
|
||||
}
|
||||
Meteor.call(
|
||||
"splitItemToParent",
|
||||
this.id,
|
||||
+instance.find("#quantityInput").value,
|
||||
{collection: this.parentCollection , id: this.parentId}
|
||||
);
|
||||
},
|
||||
"tap #oneButton":function(event, instance){
|
||||
instance.find("#quantityInput").value = 1;
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
{{#if characters.count}}
|
||||
<div>
|
||||
{{#each characters}}
|
||||
<div class="singleLineItem">{{name}}</div>
|
||||
<div class="singleLineItem characterRepresentative">{{name}}</div>
|
||||
{{/each}}
|
||||
</div>
|
||||
{{/if}}
|
||||
|
||||
Reference in New Issue
Block a user