Update sheets and fix basic bugs

This commit is contained in:
2024-12-04 15:16:33 +01:00
parent 1cc3a0bc21
commit eaba806fec
33 changed files with 453 additions and 696 deletions

View File

@ -32,8 +32,7 @@ export default class CthulhuEternalActorSheet extends HandlebarsApplicationMixin
editImage: CthulhuEternalActorSheet.#onEditImage,
toggleSheet: CthulhuEternalActorSheet.#onToggleSheet,
edit: CthulhuEternalActorSheet.#onItemEdit,
delete: CthulhuEternalActorSheet.#onItemDelete,
createSpell: CthulhuEternalActorSheet.#onCreateSpell,
delete: CthulhuEternalActorSheet.#onItemDelete
},
}
@ -109,7 +108,9 @@ export default class CthulhuEternalActorSheet extends HandlebarsApplicationMixin
* @param {DragEvent} event The originating DragEvent
* @protected
*/
async _onDrop(event) {}
async _onDrop(event) {
}
/**
* Define whether a user is able to begin a dragstart workflow for a given drag selector
@ -128,7 +129,7 @@ export default class CthulhuEternalActorSheet extends HandlebarsApplicationMixin
* @protected
*/
_canDragDrop(selector) {
return this.isEditable && this.document.isOwner
return true //this.isEditable && this.document.isOwner
}
/**
@ -203,6 +204,7 @@ export default class CthulhuEternalActorSheet extends HandlebarsApplicationMixin
_onDragOver(event) {}
async _onDropItem(item) {
console.log("Dropped item", item)
let itemData = item.toObject()
await this.document.createEmbeddedDocuments("Item", [itemData], { renderSheet: false })
}
@ -272,20 +274,8 @@ export default class CthulhuEternalActorSheet extends HandlebarsApplicationMixin
*/
static async #onItemDelete(event, target) {
const itemUuid = target.getAttribute("data-item-uuid")
const talent = await fromUuid(itemUuid)
await talent.deleteDialog()
}
/**
* Handles the creation of a new attack item.
*
* @param {Event} event The event that triggered the creation of the attack.
* @param {Object} target The target object where the attack will be created.
* @private
* @static
*/
static #onCreateSpell(event, target) {
const item = this.document.createEmbeddedDocuments("Item", [{ name: "Nouveau sortilège", type: "spell" }])
const item = await fromUuid(itemUuid)
await item.deleteDialog()
}
// #endregion

View File

@ -19,22 +19,25 @@ export default class CthulhuEternalProtagonistSheet extends CthulhuEternalActorS
/** @override */
static PARTS = {
main: {
template: "systems/fvtt-cthulhu-eternal/templates/character-main.hbs",
template: "systems/fvtt-cthulhu-eternal/templates/protagonist-main.hbs",
},
tabs: {
template: "systems/fvtt-cthulhu-eternal/templates/generic/tab-navigation.hbs",
template: "templates/generic/tab-navigation.hbs",
},
items: {
template: "systems/fvtt-cthulhu-eternal/templates/character-items.hbs",
skills: {
template: "systems/fvtt-cthulhu-eternal/templates/protagonist-skills.hbs",
},
equipment: {
template: "systems/fvtt-cthulhu-eternal/templates/protagonist-equipment.hbs",
},
biography: {
template: "systems/fvtt-cthulhu-eternal/templates/character-biography.hbs",
template: "systems/fvtt-cthulhu-eternal/templates/protagonist-biography.hbs",
},
}
/** @override */
tabGroups = {
sheet: "items",
sheet: "skills",
}
/**
@ -43,8 +46,9 @@ export default class CthulhuEternalProtagonistSheet extends CthulhuEternalActorS
*/
#getTabs() {
const tabs = {
items: { id: "items", group: "sheet", icon: "fa-solid fa-shapes", label: "CTHULHUETERNAL.Character.Label.details" },
biography: { id: "biography", group: "sheet", icon: "fa-solid fa-book", label: "CTHULHUETERNAL.Character.Label.biography" },
skills: { id: "skills", group: "sheet", icon: "fa-solid fa-shapes", label: "CTHULHUETERNAL.Label.skills" },
equipment: { id: "equipment", group: "sheet", icon: "fa-solid fa-shapes", label: "CTHULHUETERNAL.Label.equipment" },
biography: { id: "biography", group: "sheet", icon: "fa-solid fa-book", label: "CTHULHUETERNAL.Label.biography" },
}
for (const v of Object.values(tabs)) {
v.active = this.tabGroups[v.group] === v.id
@ -58,13 +62,25 @@ export default class CthulhuEternalProtagonistSheet extends CthulhuEternalActorS
const context = await super._prepareContext()
context.tabs = this.#getTabs()
context.tooltipsCaracteristiques = {
context.tooltipsCharacteristic = {
str: game.i18n.localize("CTHULHUETERNAL.Characteristic.Str"),
dex: game.i18n.localize("CTHULHUETERNAL.Characteristic.Dex"),
con: game.i18n.localize("CTHULHUETERNAL.Characteristic.Con"),
int: game.i18n.localize("CTHULHUETERNAL.Characteristic.Int"),
pow: game.i18n.localize("CTHULHUETERNAL.Characteristic.Pow"),
cha: game.i18n.localize("CTHULHUETERNAL.Characteristic.Cha")
}
context.tooltipsRessources = {
}
context.rollType = {
str: "characteristic",
dex: "characteristic",
con: "characteristic",
int: "characteristic",
pow: "characteristic",
cha: "characteristic"
}
return context
}
@ -77,14 +93,16 @@ export default class CthulhuEternalProtagonistSheet extends CthulhuEternalActorS
const doc = this.document
switch (partId) {
case "main":
context.enrichedBiens = await TextEditor.enrichHTML(doc.system.biens, { async: true })
break
case "items":
context.tab = context.tabs.items
case "skills":
context.tab = context.tabs.skills
context.skills = doc.itemTypes.skill
break
case "equipment":
context.tab = context.tabs.equipment
context.weapons = doc.itemTypes.weapon
context.armors = doc.itemTypes.armor
context.spells = doc.itemTypes.spell
context.hasSpells = context.spells.length > 0
context.gears = doc.itemTypes.gear
break
case "biography":
context.tab = context.tabs.biography
@ -95,34 +113,6 @@ export default class CthulhuEternalProtagonistSheet extends CthulhuEternalActorS
return context
}
// #region Drag-and-Drop Workflow
/**
* Callback actions which occur when a dragged element is dropped on a target.
* @param {DragEvent} event The originating DragEvent
* @protected
*/
async _onDrop(event) {
if (!this.isEditable || !this.isEditMode) return
const data = TextEditor.getDragEventData(event)
// Handle different data types
switch (data.type) {
case "Item":
const item = await fromUuid(data.uuid)
if (!["path", "weapon", "armor", "spell"].includes(item.type)) return
if (item.type === "path") return this.#onDropPathItem(item)
if (item.type === "weapon") return super._onDropItem(item)
if (item.type === "armor") return this._onDropItem(item)
if (item.type === "spell") return this._onDropItem(item)
}
}
async #onDropPathItem(item) {
await this.document.addPath(item)
}
/**
* Creates a new attack item directly from the sheet and embeds it into the document.
* @param {Event} event The initiating click event.
@ -169,5 +159,18 @@ export default class CthulhuEternalProtagonistSheet extends CthulhuEternalActorS
}
await this.document.system.roll(rollType, rollTarget)
}
async _onDrop(event) {
if (!this.isEditable || !this.isEditMode) return
const data = TextEditor.getDragEventData(event)
// Handle different data types
switch (data.type) {
case "Item":
const item = await fromUuid(data.uuid)
return super._onDropItem(item)
}
}
// #endregion
}