Add customizable rolls to items

This commit is contained in:
mstein
2022-07-23 18:50:08 +02:00
parent 58ed9d7d74
commit b3e2771e91
24 changed files with 361 additions and 155 deletions
+49 -1
View File
@@ -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({