Adds mod management (WIP)
This commit is contained in:
@@ -57,9 +57,26 @@ export default class M5CharacterSheet extends ActorSheet {
|
||||
|
||||
const context = this.actor.data
|
||||
const item = context.items.get(itemId)
|
||||
console.log("edit-item", item)
|
||||
item.sheet.render(true)
|
||||
})
|
||||
|
||||
html.find(".item-delete").on("click", async (event) => {
|
||||
let row = event.target.parentElement
|
||||
let itemId = row.dataset["item"]
|
||||
while (!itemId) {
|
||||
row = row.parentElement
|
||||
if (!row)
|
||||
return
|
||||
itemId = row.dataset["item"]
|
||||
}
|
||||
|
||||
const context = this.actor.data
|
||||
const item = context.items.get(itemId)
|
||||
item.delete()
|
||||
this.render(false)
|
||||
})
|
||||
|
||||
html.find(".roll-learned-button").on("click", async (event) => {
|
||||
const row = event.target.parentElement.parentElement
|
||||
let skillId = row.dataset["item"]
|
||||
@@ -193,7 +210,6 @@ export default class M5CharacterSheet extends ActorSheet {
|
||||
if (!data.data)
|
||||
return false
|
||||
|
||||
|
||||
if (data.actorId === this.actor.id)
|
||||
return false
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { M5Item } from "../items/M5Item"
|
||||
import { M5Attributes, M5ItemMod, M5ModOperation, M5ModType } from "../M5Base"
|
||||
|
||||
export class M5ItemSheet extends ItemSheet {
|
||||
|
||||
@@ -41,4 +42,108 @@ export class M5ItemSheet extends ItemSheet {
|
||||
})
|
||||
}
|
||||
|
||||
override activateListeners(html: JQuery) {
|
||||
super.activateListeners(html)
|
||||
|
||||
html.find(".add-mod").on("click", async (event) => {
|
||||
const context = this.object.data
|
||||
const mods = context.data.mods
|
||||
const modIndex = Object.keys(mods).length
|
||||
mods[modIndex.toString()] = {
|
||||
type: M5ModType.ATTRIBUTE,
|
||||
id: M5Attributes.ST,
|
||||
operation: M5ModOperation.ADD,
|
||||
value: 0
|
||||
} as M5ItemMod
|
||||
this.object.update({
|
||||
data: {
|
||||
mods: mods
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
html.find(".item-delete").on("click", async (event) => {
|
||||
let row = event.target.parentElement
|
||||
let itemId = row.dataset["item"]
|
||||
while (!itemId) {
|
||||
row = row.parentElement
|
||||
if (!row)
|
||||
return
|
||||
itemId = row.dataset["item"]
|
||||
}
|
||||
|
||||
const context = this.item.data
|
||||
const item = context.items.get(itemId)
|
||||
item.delete()
|
||||
this.render(false)
|
||||
})
|
||||
|
||||
// Drag & Drop
|
||||
if (["item"].includes(this.object.data?.type)) {
|
||||
const itemToItemAssociation = new DragDrop({
|
||||
dragSelector: ".item",
|
||||
dropSelector: null,
|
||||
permissions: { dragstart: this._canDragStart.bind(this), drop: this._canDragDrop.bind(this) },
|
||||
callbacks: { drop: this._onDropItem.bind(this) },
|
||||
})
|
||||
itemToItemAssociation.bind(html[0])
|
||||
}
|
||||
}
|
||||
|
||||
_canDragStart(selector) {
|
||||
console.log("M5ItemSheet._canDragStart", selector)
|
||||
return this.options.editable && this.object.isOwner
|
||||
}
|
||||
|
||||
_canDragDrop(selector) {
|
||||
console.log("M5ItemSheet._canDragDrop", selector)
|
||||
return true
|
||||
}
|
||||
|
||||
async _onDropItem(event) {
|
||||
let data
|
||||
const obj = this.object
|
||||
const li = event.currentTarget
|
||||
|
||||
try {
|
||||
data = JSON.parse(event.dataTransfer.getData("text/plain"))
|
||||
if (data.type !== "Item")
|
||||
return false
|
||||
} catch (err) {
|
||||
return false
|
||||
}
|
||||
|
||||
// Case 1 - Import from a Compendium pack
|
||||
let itemObject
|
||||
if (data.pack) {
|
||||
const compendiumObject = await (this as any).importItemFromCollection(data.pack, data.id)
|
||||
itemObject = compendiumObject.data
|
||||
}
|
||||
|
||||
// Case 2 - Import from World entity
|
||||
else {
|
||||
const originalItem = await (game as Game).items.get(data.id)
|
||||
itemObject = duplicate(originalItem)
|
||||
if (!itemObject)
|
||||
return
|
||||
}
|
||||
|
||||
if ((itemObject.type === "mod")) {
|
||||
let mods = obj?.data?.data?.mods
|
||||
if (!mods)
|
||||
mods = []
|
||||
|
||||
itemObject.id = randomID()
|
||||
console.log("M5ItemSheet._onDropItem", itemObject)
|
||||
mods.push(itemObject)
|
||||
|
||||
obj.update({
|
||||
data: {
|
||||
mods: mods
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
async _onDragItemStart(event) { }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user