Refactor des fiches de creatures
This commit is contained in:
@@ -11,6 +11,7 @@ export class CDEBaseActorSheet extends HandlebarsApplicationMixin(foundry.applic
|
||||
create: CDEBaseActorSheet.#onItemCreate,
|
||||
edit: CDEBaseActorSheet.#onItemEdit,
|
||||
delete: CDEBaseActorSheet.#onItemDelete,
|
||||
editImage: CDEBaseActorSheet.#onEditImage,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -21,7 +22,7 @@ export class CDEBaseActorSheet extends HandlebarsApplicationMixin(foundry.applic
|
||||
}
|
||||
|
||||
async _prepareContext() {
|
||||
const descriptionHTML = await foundry.applications.ux.TextEditor.implementation.enrichHTML(this.document.system.description ?? "", { async: true })
|
||||
const descriptionHTML = await TextEditor.enrichHTML(this.document.system.description ?? "", { async: true })
|
||||
const cssClass = this.options.classes?.join(" ") ?? ""
|
||||
return {
|
||||
actor: this.document,
|
||||
@@ -77,4 +78,19 @@ export class CDEBaseActorSheet extends HandlebarsApplicationMixin(foundry.applic
|
||||
const item = this.document.items.get(itemId)
|
||||
if (item) item.delete()
|
||||
}
|
||||
|
||||
static async #onEditImage(event, target) {
|
||||
const attr = target.dataset.edit
|
||||
const current = foundry.utils.getProperty(this.document, attr)
|
||||
const { img } = this.document.constructor.getDefaultArtwork?.(this.document.toObject()) ?? {}
|
||||
const fp = new FilePicker({
|
||||
current,
|
||||
type: "image",
|
||||
redirectToRoot: img ? [img] : [],
|
||||
callback: (path) => this.document.update({ [attr]: path }),
|
||||
top: this.position.top + 40,
|
||||
left: this.position.left + 10,
|
||||
})
|
||||
return fp.browse()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ export class CDECharacterSheet extends CDEBaseActorSheet {
|
||||
}
|
||||
|
||||
_onRender(context, options) {
|
||||
super._onRender?.(context, options)
|
||||
super._onRender(context, options)
|
||||
this.#bindInitiativeControls()
|
||||
this.#bindPrefs()
|
||||
this.#bindRollButtons()
|
||||
@@ -99,7 +99,7 @@ export class CDECharacterSheet extends CDEBaseActorSheet {
|
||||
<form class="flexcol">
|
||||
<div class="form-group">
|
||||
<label>${game.i18n.localize("CDE.ThrowType")}</label>
|
||||
<select name="choice" value="${current.choice}">
|
||||
<select name="choice">
|
||||
<option value="0"${current.choice === "0" ? " selected" : ""}>0</option>
|
||||
<option value="1"${current.choice === "1" ? " selected" : ""}>1</option>
|
||||
<option value="2"${current.choice === "2" ? " selected" : ""}>2</option>
|
||||
@@ -111,14 +111,18 @@ export class CDECharacterSheet extends CDEBaseActorSheet {
|
||||
<input type="checkbox" name="check" ${current.check ? "checked" : ""}/>
|
||||
</div>
|
||||
</form>`
|
||||
const prefs = await Dialog.prompt({
|
||||
title: game.i18n.localize("CDE.Preferences"),
|
||||
const prefs = await foundry.applications.api.DialogV2.prompt({
|
||||
window: { title: game.i18n.localize("CDE.Preferences") },
|
||||
content: html,
|
||||
label: game.i18n.localize("CDE.Validate"),
|
||||
callback: (dlg) => {
|
||||
const choice = dlg.querySelector("select[name='choice']")?.value ?? "0"
|
||||
const check = dlg.querySelector("input[name='check']")?.checked ?? false
|
||||
return { choice, check }
|
||||
rejectClose: false,
|
||||
ok: {
|
||||
label: game.i18n.localize("CDE.Validate"),
|
||||
callback: (_ev, _btn, dialog) => {
|
||||
const root = dialog.element ?? dialog
|
||||
const choice = root.querySelector("select[name='choice']")?.value ?? "0"
|
||||
const check = root.querySelector("input[name='check']")?.checked ?? false
|
||||
return { choice, check }
|
||||
},
|
||||
},
|
||||
})
|
||||
if (prefs) {
|
||||
@@ -166,7 +170,7 @@ export class CDECharacterSheet extends CDEBaseActorSheet {
|
||||
speaker: ChatMessage.getSpeaker({ actor: this.document }),
|
||||
content,
|
||||
rolls: [roll],
|
||||
rollMode: "roll",
|
||||
rollMode: game.settings.get("core", "rollMode") ?? "roll",
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { rollInitiativeNPC } from "../../initiative.js"
|
||||
import { rollForActor } from "../../rolling.js"
|
||||
import { CDEBaseActorSheet } from "./base.js"
|
||||
|
||||
export class CDENpcSheet extends CDEBaseActorSheet {
|
||||
@@ -15,15 +16,30 @@ export class CDENpcSheet extends CDEBaseActorSheet {
|
||||
async _prepareContext() {
|
||||
const context = await super._prepareContext()
|
||||
context.supernaturals = context.items.filter((item) => item.type === "supernatural")
|
||||
context.spells = context.items.filter((item) => item.type === "spell")
|
||||
context.kungfus = context.items.filter((item) => item.type === "kungfu")
|
||||
context.equipments = context.items.filter((item) => item.type === "item")
|
||||
context.spells = context.items.filter((item) => item.type === "spell")
|
||||
context.kungfus = context.items.filter((item) => item.type === "kungfu")
|
||||
context.weapons = context.items.filter((item) => item.type === "weapon")
|
||||
context.armors = context.items.filter((item) => item.type === "armor")
|
||||
context.equipments = context.items.filter((item) => item.type === "item")
|
||||
return context
|
||||
}
|
||||
|
||||
_onRender(context, options) {
|
||||
super._onRender?.(context, options)
|
||||
super._onRender(context, options)
|
||||
this.#bindInitiativeControls()
|
||||
this.#bindRollButtons()
|
||||
}
|
||||
|
||||
#bindRollButtons() {
|
||||
const cells = this.element?.querySelectorAll(".cde-roll-trigger[data-libel-id]")
|
||||
if (!cells?.length) return
|
||||
cells.forEach((cell) => {
|
||||
cell.addEventListener("click", (event) => {
|
||||
event.preventDefault()
|
||||
const rollKey = cell.dataset.libelId
|
||||
if (rollKey) rollForActor(this.document, rollKey)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
#bindInitiativeControls() {
|
||||
|
||||
@@ -6,7 +6,9 @@ export class CDEBaseItemSheet extends HandlebarsApplicationMixin(foundry.applica
|
||||
position: { width: 520, height: "auto" },
|
||||
window: { resizable: true },
|
||||
form: { submitOnChange: true },
|
||||
actions: {},
|
||||
actions: {
|
||||
editImage: CDEBaseItemSheet.#onEditImage,
|
||||
},
|
||||
}
|
||||
|
||||
tabGroups = { primary: "details" }
|
||||
@@ -17,8 +19,8 @@ export class CDEBaseItemSheet extends HandlebarsApplicationMixin(foundry.applica
|
||||
|
||||
async _prepareContext() {
|
||||
const cssClass = this.options.classes?.join(" ") ?? ""
|
||||
const enrichedDescription = await foundry.applications.ux.TextEditor.implementation.enrichHTML(this.document.system.description ?? "", { async: true })
|
||||
const enrichedNotes = await foundry.applications.ux.TextEditor.implementation.enrichHTML(this.document.system.notes ?? "", { async: true })
|
||||
const enrichedDescription = await TextEditor.enrichHTML(this.document.system.description ?? "", { async: true })
|
||||
const enrichedNotes = await TextEditor.enrichHTML(this.document.system.notes ?? "", { async: true })
|
||||
return {
|
||||
item: this.document,
|
||||
system: this.document.system,
|
||||
@@ -40,4 +42,19 @@ export class CDEBaseItemSheet extends HandlebarsApplicationMixin(foundry.applica
|
||||
this.changeTab(tab, group, { force: true })
|
||||
}
|
||||
}
|
||||
|
||||
static async #onEditImage(event, target) {
|
||||
const attr = target.dataset.edit
|
||||
const current = foundry.utils.getProperty(this.document, attr)
|
||||
const { img } = this.document.constructor.getDefaultArtwork?.(this.document.toObject()) ?? {}
|
||||
const fp = new FilePicker({
|
||||
current,
|
||||
type: "image",
|
||||
redirectToRoot: img ? [img] : [],
|
||||
callback: (path) => this.document.update({ [attr]: path }),
|
||||
top: this.position.top + 40,
|
||||
left: this.position.left + 10,
|
||||
})
|
||||
return fp.browse()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user