Fixed inventory swap bug
This commit is contained in:
parent
09d28e146c
commit
43317fd3da
@ -253,36 +253,38 @@ export class AnimeNotifier {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the slot has an item and is therefore draggable
|
element.addEventListener("dragstart", e => {
|
||||||
if(element.draggable) {
|
if(!element.draggable) {
|
||||||
element.addEventListener("dragstart", e => {
|
return
|
||||||
let element = e.target as HTMLElement
|
}
|
||||||
e.dataTransfer.setData("text", element.dataset.index)
|
|
||||||
}, false)
|
|
||||||
|
|
||||||
element.addEventListener("dblclick", e => {
|
e.dataTransfer.setData("text", element.dataset.index)
|
||||||
let itemName = element.title
|
}, false)
|
||||||
|
|
||||||
if(element.dataset.consumable !== "true") {
|
element.addEventListener("dblclick", e => {
|
||||||
return this.statusMessage.showError(itemName + " is not a consumable item.")
|
if(!element.draggable) {
|
||||||
}
|
return
|
||||||
|
}
|
||||||
let apiEndpoint = this.findAPIEndpoint(element)
|
|
||||||
|
let itemName = element.title
|
||||||
this.post(apiEndpoint + "/use/" + element.dataset.index, "")
|
|
||||||
.then(() => this.reloadContent())
|
if(element.dataset.consumable !== "true") {
|
||||||
.then(() => this.statusMessage.showInfo(`You used ${itemName}.`))
|
return this.statusMessage.showError(itemName + " is not a consumable item.")
|
||||||
.catch(err => this.statusMessage.showError(err))
|
}
|
||||||
}, false)
|
|
||||||
}
|
let apiEndpoint = this.findAPIEndpoint(element)
|
||||||
|
|
||||||
|
this.post(apiEndpoint + "/use/" + element.dataset.index, "")
|
||||||
|
.then(() => this.reloadContent())
|
||||||
|
.then(() => this.statusMessage.showInfo(`You used ${itemName}.`))
|
||||||
|
.catch(err => this.statusMessage.showError(err))
|
||||||
|
}, false)
|
||||||
|
|
||||||
element.addEventListener("dragenter", e => {
|
element.addEventListener("dragenter", e => {
|
||||||
let element = e.target as HTMLElement
|
|
||||||
element.classList.add("drag-enter")
|
element.classList.add("drag-enter")
|
||||||
}, false)
|
}, false)
|
||||||
|
|
||||||
element.addEventListener("dragleave", e => {
|
element.addEventListener("dragleave", e => {
|
||||||
let element = e.target as HTMLElement
|
|
||||||
element.classList.remove("drag-enter")
|
element.classList.remove("drag-enter")
|
||||||
}, false)
|
}, false)
|
||||||
|
|
||||||
@ -291,15 +293,23 @@ export class AnimeNotifier {
|
|||||||
}, false)
|
}, false)
|
||||||
|
|
||||||
element.addEventListener("drop", e => {
|
element.addEventListener("drop", e => {
|
||||||
let inventory = e.toElement.parentElement
|
|
||||||
let fromIndex = e.dataTransfer.getData("text")
|
|
||||||
let fromElement = inventory.childNodes[fromIndex] as HTMLElement
|
|
||||||
let toElement = e.toElement as HTMLElement
|
let toElement = e.toElement as HTMLElement
|
||||||
let toIndex = toElement.dataset.index
|
toElement.classList.remove("drag-enter")
|
||||||
|
|
||||||
e.stopPropagation()
|
e.stopPropagation()
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
|
|
||||||
|
let inventory = e.toElement.parentElement
|
||||||
|
let fromIndex = e.dataTransfer.getData("text")
|
||||||
|
|
||||||
|
if(!fromIndex) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
let fromElement = inventory.childNodes[fromIndex] as HTMLElement
|
||||||
|
|
||||||
|
let toIndex = toElement.dataset.index
|
||||||
|
|
||||||
if(fromElement === toElement || fromIndex === toIndex) {
|
if(fromElement === toElement || fromIndex === toIndex) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -311,7 +321,6 @@ export class AnimeNotifier {
|
|||||||
.catch(err => this.statusMessage.showError(err))
|
.catch(err => this.statusMessage.showError(err))
|
||||||
|
|
||||||
// Swap in UI
|
// Swap in UI
|
||||||
toElement.classList.remove("drag-enter")
|
|
||||||
swapElements(fromElement, toElement)
|
swapElements(fromElement, toElement)
|
||||||
|
|
||||||
fromElement.dataset.index = toIndex
|
fromElement.dataset.index = toIndex
|
||||||
|
Loading…
Reference in New Issue
Block a user