Upgrade item sheets

This commit is contained in:
2024-12-03 13:51:38 +01:00
parent df8995f8b7
commit 9775ec9fa1
38 changed files with 1095 additions and 506 deletions

View File

@ -13,8 +13,6 @@ export default class LethalFantasyCharacterSheet extends LethalFantasyActorSheet
contentClasses: ["character-content"],
},
actions: {
deleteVoieMajeure: LethalFantasyCharacterSheet.#onDeleteVoieMajeure,
deleteVoieMineure: LethalFantasyCharacterSheet.#onDeleteVoieMineure,
createEquipment: LethalFantasyCharacterSheet.#onCreateEquipment,
},
}
@ -25,7 +23,7 @@ export default class LethalFantasyCharacterSheet extends LethalFantasyActorSheet
template: "systems/fvtt-lethal-fantasy/templates/character-main.hbs",
},
tabs: {
template: "templates/generic/tab-navigation.hbs",
template: "systems/fvtt-lethal-fantasy/templates/generic/tab-navigation.hbs",
},
items: {
template: "systems/fvtt-lethal-fantasy/templates/character-items.hbs",
@ -46,8 +44,8 @@ export default class LethalFantasyCharacterSheet extends LethalFantasyActorSheet
*/
#getTabs() {
const tabs = {
items: { id: "items", group: "sheet", icon: "fa-solid fa-shapes", label: "TENEBRIS.Character.Label.details" },
biography: { id: "biography", group: "sheet", icon: "fa-solid fa-book", label: "TENEBRIS.Character.Label.biography" },
items: { id: "items", group: "sheet", icon: "fa-solid fa-shapes", label: "LETHALFANTASY.Character.Label.details" },
biography: { id: "biography", group: "sheet", icon: "fa-solid fa-book", label: "LETHALFANTASY.Character.Label.biography" },
}
for (const v of Object.values(tabs)) {
v.active = this.tabGroups[v.group] === v.id
@ -62,105 +60,17 @@ export default class LethalFantasyCharacterSheet extends LethalFantasyActorSheet
context.tabs = this.#getTabs()
context.tooltipsCaracteristiques = {
rob: this._generateTooltip("save", "rob"),
dex: this._generateTooltip("save", "dex"),
int: this._generateTooltip("save", "int"),
per: this._generateTooltip("save", "per"),
vol: this._generateTooltip("save", "vol"),
dmax: this._generateTooltip("other", "dmax"),
}
context.tooltipsRessources = {
san: this._generateTooltip("resource", "san"),
oeil: this._generateTooltip("resource", "oeil"),
verbe: this._generateTooltip("resource", "verbe"),
bourse: this._generateTooltip("resource", "bourse"),
magie: this._generateTooltip("resource", "magie"),
}
context.rollType = {
saveRob: {
action: "roll",
rollType: "save",
rollTarget: "rob",
tooltip: this._generateTooltip("save", "rob"),
},
saveDex: {
action: "roll",
rollType: "save",
rollTarget: "dex",
tooltip: this._generateTooltip("save", "dex"),
},
saveInt: {
action: "roll",
rollType: "save",
rollTarget: "int",
tooltip: this._generateTooltip("save", "int"),
},
savePer: {
action: "roll",
rollType: "save",
rollTarget: "per",
tooltip: this._generateTooltip("save", "per"),
drag: true,
},
saveVol: {
action: "roll",
rollType: "save",
rollTarget: "vol",
tooltip: this._generateTooltip("save", "vol"),
drag: true,
},
resourceSan: {
action: "roll",
rollType: "resource",
rollTarget: "san",
tooltip: this._generateTooltip("resource", "san"),
drag: true,
},
resourceOeil: {
action: "roll",
rollType: "resource",
rollTarget: "oeil",
tooltip: this._generateTooltip("resource", "oeil"),
drag: true,
},
resourceVerbe: {
action: "roll",
rollType: "resource",
rollTarget: "verbe",
tooltip: this._generateTooltip("resource", "verbe"),
drag: true,
},
resourceBourse: {
action: "roll",
rollType: "resource",
rollTarget: "bourse",
tooltip: this._generateTooltip("resource", "bourse"),
drag: true,
},
resourceMagie: {
action: "roll",
rollType: "resource",
rollTarget: "magie",
tooltip: this._generateTooltip("resource", "magie"),
drag: true,
},
}
return context
}
_generateTooltip(type, target) {
if (type === ROLL_TYPE.SAVE) {
const progres = this.document.system.caracteristiques[target].progression.progres
? game.i18n.localize("TENEBRIS.Label.hasProgressed")
: game.i18n.localize("TENEBRIS.Label.noProgress")
return `${game.i18n.localize("TENEBRIS.Label.experience")} : ${this.document.system.caracteristiques[target].progression.experience} <br> ${progres}`
} else if (type === ROLL_TYPE.RESOURCE) {
return `${game.i18n.localize("TENEBRIS.Label.maximum")} : ${this.document.system.ressources[target].max} <br> ${game.i18n.localize("TENEBRIS.Label.experience")} : ${this.document.system.ressources[target].experience}`
} else if (type === "other") {
return `${game.i18n.localize("TENEBRIS.Label.experience")} : ${this.document.system.dmax.experience}`
}
}
/** @override */
@ -172,9 +82,6 @@ export default class LethalFantasyCharacterSheet extends LethalFantasyActorSheet
break
case "items":
context.tab = context.tabs.items
const talents = await this._prepareTalents()
context.talents = talents
context.talentsAppris = talents.filter((talent) => talent.appris)
context.weapons = doc.itemTypes.weapon
context.armors = doc.itemTypes.armor
context.spells = doc.itemTypes.spell
@ -183,40 +90,12 @@ export default class LethalFantasyCharacterSheet extends LethalFantasyActorSheet
case "biography":
context.tab = context.tabs.biography
context.enrichedDescription = await TextEditor.enrichHTML(doc.system.description, { async: true })
context.enrichedLangues = await TextEditor.enrichHTML(doc.system.langues, { async: true })
context.enrichedNotes = await TextEditor.enrichHTML(doc.system.notes, { async: true })
break
}
return context
}
/**
* Prepares the talents for the character sheet.
*
* @returns {Array} An array of talents with their properties.
*/
async _prepareTalents() {
const talents = await Promise.all(
this.document.itemTypes.talent.map(async (talent) => {
const pathName = await talent.system.getPathName()
return {
id: talent.id,
uuid: talent.uuid,
name: talent.name,
img: talent.img,
path: `Obtenu par ${pathName}`,
description: talent.system.improvedDescription,
progression: talent.system.progression,
niveau: talent.system.niveau,
appris: talent.system.appris,
details: talent.system.details,
}
}),
)
talents.sort((a, b) => b.appris - a.appris || a.name.localeCompare(b.name, game.i18n.lang))
return talents
}
// #region Drag-and-Drop Workflow
/**
@ -244,43 +123,6 @@ export default class LethalFantasyCharacterSheet extends LethalFantasyActorSheet
await this.document.addPath(item)
}
// #endregion
// #region Actions
/**
* Suppression de la voie majeure
* @param {Event} event The initiating click event.
* @param {HTMLElement} target The current target of the event listener.
*/
static async #onDeleteVoieMajeure(event, target) {
const proceed = await foundry.applications.api.DialogV2.confirm({
content: game.i18n.localize("TENEBRIS.Dialog.suppressionTalents"),
rejectClose: false,
modal: true,
})
if (!proceed) return
const path = this.document.items.get(this.document.system.voies.majeure.id)
if (!path) return
await this.document.deletePath(path, true)
}
/**
* Suppression de la voie mineure
* @param {Event} event The initiating click event.
* @param {HTMLElement} target The current target of the event listener.
*/
static async #onDeleteVoieMineure(event, target) {
const proceed = await foundry.applications.api.DialogV2.confirm({
content: game.i18n.localize("TENEBRIS.Dialog.suppressionTalents"),
rejectClose: false,
modal: true,
})
if (!proceed) return
const path = this.document.items.get(this.document.system.voies.mineure.id)
if (!path) return
await this.document.deletePath(path, false)
}
/**
* Creates a new attack item directly from the sheet and embeds it into the document.
@ -290,11 +132,11 @@ export default class LethalFantasyCharacterSheet extends LethalFantasyActorSheet
static #onCreateEquipment(event, target) {
// Création d'une armure
if (event.shiftKey) {
this.document.createEmbeddedDocuments("Item", [{ name: game.i18n.localize("TENEBRIS.Label.newArmor"), type: "armor" }])
this.document.createEmbeddedDocuments("Item", [{ name: game.i18n.localize("LETHALFANTASY.Label.newArmor"), type: "armor" }])
}
// Création d'une arme
else {
this.document.createEmbeddedDocuments("Item", [{ name: game.i18n.localize("TENEBRIS.Label.newWeapon"), type: "weapon" }])
this.document.createEmbeddedDocuments("Item", [{ name: game.i18n.localize("LETHALFANTASY.Label.newWeapon"), type: "weapon" }])
}
}

View File

@ -22,7 +22,7 @@ export default class LethalFantasyGiftSheet extends LethalFantasyItemSheet {
/** @override */
async _prepareContext() {
const context = await super._prepareContext()
context.enrichedDescription = await TextEditor.enrichHTML(this.document.system.improvedDescription, { async: true })
context.enrichedDescription = await TextEditor.enrichHTML(this.document.system.description, { async: true })
return context
}
}

View File

@ -0,0 +1,27 @@
import LethalFantasyItemSheet from "./base-item-sheet.mjs"
export default class LethalFantasyShieldSheet extends LethalFantasyItemSheet {
/** @override */
static DEFAULT_OPTIONS = {
classes: ["shield"],
position: {
width: 620,
},
window: {
contentClasses: ["shield-content"],
},
}
/** @override */
static PARTS = {
main: {
template: "systems/fvtt-lethal-fantasy/templates/shield.hbs",
},
}
/** @override */
async _prepareContext() {
const context = await super._prepareContext()
return context
}
}

View File

@ -5,7 +5,7 @@ export default class LethalFantasyWeaponSheet extends LethalFantasyItemSheet {
static DEFAULT_OPTIONS = {
classes: ["weapon"],
position: {
width: 400,
width: 620,
},
window: {
contentClasses: ["weapon-content"],