Add customizable rolls to items
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { M5Item } from "../items/M5Item"
|
||||
import { M5Attributes, M5ItemMod, M5ModOperation, M5ModType } from "../M5Base"
|
||||
import { M5Attributes, M5ItemMod, M5ModOperation, M5ModType, M5RollTemplate } from "../M5Base"
|
||||
|
||||
export class M5ItemSheet extends ItemSheet {
|
||||
|
||||
@@ -78,6 +78,54 @@ export class M5ItemSheet extends ItemSheet {
|
||||
this.render(false)
|
||||
})
|
||||
|
||||
html.find(".roll-delete").on("click", async (event) => {
|
||||
//console.log("roll-delete", this.item.data.data.rolls.formulas)
|
||||
|
||||
let row = event.target.parentElement
|
||||
let rollIndex = row.dataset["roll"]
|
||||
while (!rollIndex) {
|
||||
row = row.parentElement
|
||||
if (!row)
|
||||
return
|
||||
rollIndex = row.dataset["roll"]
|
||||
}
|
||||
|
||||
const rolls = this.item.data.data.rolls.formulas
|
||||
rolls[rollIndex] = null
|
||||
|
||||
this.item.update({
|
||||
data: {
|
||||
rolls: {
|
||||
formulas: rolls
|
||||
}
|
||||
}
|
||||
})
|
||||
this.render(false)
|
||||
})
|
||||
|
||||
html.find(".roll-create").on("click", async (event) => {
|
||||
const rolls = this.item.data.data.rolls.formulas
|
||||
|
||||
const indeces = Object.keys(rolls).map(index => parseInt(index)).sort().reverse()
|
||||
const index = (indeces.find(index => !!rolls[index.toString()]) ?? -1) + 1
|
||||
console.log("roll-create", rolls, indeces, index)
|
||||
|
||||
rolls[index.toString()] = {
|
||||
formula: "1d6",
|
||||
label: (game as Game).i18n.localize("midgard5.roll"),
|
||||
enabled: true
|
||||
} as M5RollTemplate
|
||||
|
||||
this.item.update({
|
||||
data: {
|
||||
rolls: {
|
||||
formulas: rolls
|
||||
}
|
||||
}
|
||||
})
|
||||
this.render(false)
|
||||
})
|
||||
|
||||
// Drag & Drop
|
||||
if (["item"].includes(this.object.data?.type)) {
|
||||
const itemToItemAssociation = new DragDrop({
|
||||
|
||||
Reference in New Issue
Block a user