Initial system import

This commit is contained in:
2025-12-25 23:08:06 +01:00
commit 4beb5806eb
4623 changed files with 682363 additions and 0 deletions
+15
View File
@@ -0,0 +1,15 @@
export { default as HamalronArmeSheet } from "./sheets/arme-sheet.mjs"
export { default as HamalronArmureSheet } from "./sheets/armure-sheet.mjs"
export { default as HamalronCompetenceSheet } from "./sheets/competence-sheet.mjs"
export { default as HamalronEquipementSheet } from "./sheets/equipement-sheet.mjs"
export { default as HamalronFactionSheet } from "./sheets/faction-sheet.mjs"
export { default as HamalronLangueSheet } from "./sheets/langue-sheet.mjs"
export { default as HamalronPeupleSheet } from "./sheets/peuple-sheet.mjs"
export { default as HamalronRegionSheet } from "./sheets/region-sheet.mjs"
export { default as HamalronPersonnageSheet } from "./sheets/personnage-sheet.mjs"
export { default as HamalronEnemySheet } from "./sheets/enemy-sheet.mjs"
export { default as HamalronSortilegeSheet } from "./sheets/sortilege-sheet.mjs"
export { default as HamalronTarotSheet } from "./sheets/tarot-sheet.mjs"
export { default as HamalronItemSheet } from "./sheets/base-item-sheet.mjs"
export { default as HamalronActorSheet } from "./sheets/base-actor-sheet.mjs"
export { default as HamalronTarotDeckManager } from "./tarot-deck-manager.mjs"
+27
View File
@@ -0,0 +1,27 @@
import HamalronItemSheet from "./base-item-sheet.mjs"
export default class HamalronArmeSheet extends HamalronItemSheet {
/** @override */
static DEFAULT_OPTIONS = {
classes: ["weapon"],
position: {
width: 620,
},
window: {
contentClasses: ["weapon-content"],
},
}
/** @override */
static PARTS = {
main: {
template: "systems/fvtt-hamalron/templates/arme.hbs",
},
}
async _prepareContext() {
const context = await super._prepareContext()
context.enrichedDescription = await foundry.applications.ux.TextEditor.implementation.enrichHTML(this.document.system.description, { async: true })
return context
}
}
@@ -0,0 +1,28 @@
import HamalronItemSheet from "./base-item-sheet.mjs"
export default class HamalronArmureSheet extends HamalronItemSheet {
/** @override */
static DEFAULT_OPTIONS = {
classes: ["armor"],
position: {
width: 500,
},
window: {
contentClasses: ["armor-content"],
},
}
/** @override */
static PARTS = {
main: {
template: "systems/fvtt-hamalron/templates/armure.hbs",
},
}
/** @override */
async _prepareContext() {
const context = await super._prepareContext()
context.enrichedDescription = await foundry.applications.ux.TextEditor.implementation.enrichHTML(this.document.system.description, { async: true })
return context
}
}
@@ -0,0 +1,260 @@
const { HandlebarsApplicationMixin } = foundry.applications.api
export default class HamalronActorSheet extends HandlebarsApplicationMixin(foundry.applications.sheets.ActorSheetV2) {
/**
* Different sheet modes.r
* @enum {number}
*/
static SHEET_MODES = { EDIT: 0, PLAY: 1 }
constructor(options = {}) {
super(options)
this.#dragDrop = this.#createDragDropHandlers()
}
#dragDrop
/** @override */
static DEFAULT_OPTIONS = {
classes: ["fvtt-hamalron", "actor"],
position: {
width: 1400,
height: "auto",
},
form: {
submitOnChange: true,
},
window: {
resizable: true,
},
dragDrop: [{ dragSelector: '[data-drag="true"], .rollable', dropSelector: null }],
actions: {
editImage: HamalronActorSheet.#onEditImage,
toggleSheet: HamalronActorSheet.#onToggleSheet,
edit: HamalronActorSheet.#onItemEdit,
delete: HamalronActorSheet.#onItemDelete,
updateCheckboxArray: HamalronActorSheet.#onUpdateCheckboxArray,
toChat: HamalronActorSheet.#toChat,
},
}
/**
* The current sheet mode.
* @type {number}
*/
_sheetMode = this.constructor.SHEET_MODES.PLAY
/**
* Is the sheet currently in 'Play' mode?
* @type {boolean}
*/
get isPlayMode() {
return this._sheetMode === this.constructor.SHEET_MODES.PLAY
}
/**
* Is the sheet currently in 'Edit' mode?
* @type {boolean}
*/
get isEditMode() {
return this._sheetMode === this.constructor.SHEET_MODES.EDIT
}
/** @override */
async _prepareContext() {
const context = {
fields: this.document.schema.fields,
systemFields: this.document.system.schema.fields,
actor: this.document,
system: this.document.system,
source: this.document.toObject(),
enrichedBackstory: await foundry.applications.ux.TextEditor.implementation.enrichHTML(this.document.system.backstory, { async: true }),
isEditMode: this.isEditMode,
isPlayMode: this.isPlayMode,
isEditable: this.isEditable,
}
return context
}
/** @override */
_onRender(context, options) {
this.#dragDrop.forEach((d) => d.bind(this.element))
// Add listeners to rollable elements
const rollables = this.element.querySelectorAll(".rollable")
rollables.forEach((d) => d.addEventListener("click", this._onRoll.bind(this)))
}
// #region Drag-and-Drop Workflow
/**
* Create drag-and-drop workflow handlers for this Application
* @returns {DragDrop[]} An array of DragDrop handlers
* @private
*/
#createDragDropHandlers() {
return this.options.dragDrop.map((d) => {
d.permissions = {
dragstart: this._canDragStart.bind(this),
drop: this._canDragDrop.bind(this),
}
d.callbacks = {
dragover: this._onDragOver.bind(this),
drop: this._onDrop.bind(this),
}
return new foundry.applications.ux.DragDrop.implementation(d)
})
}
/**
* Callback actions which occur when a dragged element is dropped on a target.
* @param {DragEvent} event The originating DragEvent
* @protected
*/
async _onDrop(event) {
}
/**
* Define whether a user is able to begin a dragstart workflow for a given drag selector
* @param {string} selector The candidate HTML selector for dragging
* @returns {boolean} Can the current user drag this selector?
* @protected
*/
_canDragStart(selector) {
return this.isEditable
}
/**
* Define whether a user is able to conclude a drag-and-drop workflow for a given drop selector
* @param {string} selector The candidate HTML selector for the drop target
* @returns {boolean} Can the current user drop on this selector?
* @protected
*/
_canDragDrop(selector) {
return true //this.isEditable && this.document.isOwner
}
/**
* Callback actions which occur when a dragged element is over a drop target.
* @param {DragEvent} event The originating DragEvent
* @protected
*/
_onDragOver(event) { }
async _onDropItem(item) {
console.log("Dropped item", item)
let itemData = item.toObject()
await this.document.createEmbeddedDocuments("Item", [itemData], { renderSheet: false })
}
// #endregion
// #region Actions
/**
* Handle toggling between Edit and Play mode.
* @param {Event} event The initiating click event.
* @param {HTMLElement} target The current target of the event listener.
*/
static #onToggleSheet(event, target) {
const modes = this.constructor.SHEET_MODES
this._sheetMode = this.isEditMode ? modes.PLAY : modes.EDIT
this.render()
}
/**
* Handle changing a Document's image.
*
* @this HamalronActorSheet
* @param {PointerEvent} event The originating click event
* @param {HTMLElement} target The capturing HTML element which defined a [data-action]
* @returns {Promise}
* @private
*/
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()
}
static #onUpdateCheckboxArray(event, target) {
console.log("Update checkbox array", event, target)
let arrayName = target.dataset.name
let arrayIdx = Number(target.dataset.index)
let dataPath = `system.mortality.${arrayName}`
let tab = foundry.utils.duplicate(this.document.system.mortality[arrayName])
tab[arrayIdx] = target.checked
this.actor.update({ [dataPath]: tab })
}
static async #toChat(event, target) {
const itemUuid = target.getAttribute("data-item-uuid")
const item = fromUuidSync(itemUuid)
if (!item) return
let content = ""
if (item.type === "perk") {
content = await foundry.applications.handlebars.renderTemplate("systems/fvtt-hamalron/templates/chat-perk.hbs", item.toObject())
}
if (item.type === "malefica") {
content = await foundry.applications.handlebars.renderTemplate("systems/fvtt-hamalron/templates/chat-malefica.hbs", item.toObject())
}
if (item.type === "ritual") {
content = await foundry.applications.handlebars.renderTemplate("systems/fvtt-hamalron/templates/chat-ritual.hbs", item.toObject())
}
if (item.type === "species-trait") {
content = await foundry.applications.handlebars.renderTemplate("systems/fvtt-hamalron/templates/chat-trait.hbs", item.toObject())
}
if (item.type === "tarot") {
content = await foundry.applications.handlebars.renderTemplate("systems/fvtt-hamalron/templates/chat-tarot.hbs", item.toObject())
}
const chatData = {
user: game.user.id,
speaker: ChatMessage.getSpeaker({ actor: this.actor }),
content: content,
type: CONST.CHAT_MESSAGE_TYPES.OTHER,
}
ChatMessage.create(chatData, { renderSheet: false })
}
/**
* Edit an existing item within the Actor
* Start with the uuid, if it's not found, fallback to the id (as Embedded item in the actor)
* @this CthulhuEternalCharacterSheet
* @param {PointerEvent} event The originating click event
* @param {HTMLElement} target the capturing HTML element which defined a [data-action]
*/
static async #onItemEdit(event, target) {
const id = target.getAttribute("data-item-id")
const uuid = target.getAttribute("data-item-uuid")
let item
item = await fromUuid(uuid)
if (!item) item = this.document.items.get(id)
if (!item) return
item.sheet.render(true)
}
/**
* Delete an existing talent within the Actor
* Use the uuid to display the talent sheet
* @param {PointerEvent} event The originating click event
* @param {HTMLElement} target the capturing HTML element which defined a [data-action]
*/
static async #onItemDelete(event, target) {
const itemUuid = target.getAttribute("data-item-uuid")
const item = await fromUuid(itemUuid)
await item.deleteDialog()
}
// #endregion
}
@@ -0,0 +1,193 @@
const { HandlebarsApplicationMixin } = foundry.applications.api
export default class HamalronItemSheet extends HandlebarsApplicationMixin(foundry.applications.sheets.ItemSheetV2) {
/**
* Different sheet modes.
* @enum {number}
*/
static SHEET_MODES = { EDIT: 0, PLAY: 1 }
constructor(options = {}) {
super(options)
this.#dragDrop = this.#createDragDropHandlers()
}
#dragDrop
/** @override */
static DEFAULT_OPTIONS = {
classes: ["fvtt-hamalron", "item"],
position: {
width: 600,
height: "auto",
},
form: {
submitOnChange: true,
},
window: {
resizable: true,
},
dragDrop: [{ dragSelector: "[data-drag]", dropSelector: null }],
actions: {
toggleSheet: HamalronItemSheet.#onToggleSheet,
editImage: HamalronItemSheet.#onEditImage,
},
}
/**
* The current sheet mode.
* @type {number}
*/
_sheetMode = this.constructor.SHEET_MODES.PLAY
/**
* Is the sheet currently in 'Play' mode?
* @type {boolean}
*/
get isPlayMode() {
return this._sheetMode === this.constructor.SHEET_MODES.PLAY
}
/**
* Is the sheet currently in 'Edit' mode?
* @type {boolean}
*/
get isEditMode() {
return this._sheetMode === this.constructor.SHEET_MODES.EDIT
}
/** @override */
async _prepareContext() {
const context = {
fields: this.document.schema.fields,
systemFields: this.document.system.schema.fields,
item: this.document,
system: this.document.system,
source: this.document.toObject(),
enrichedDescription: await foundry.applications.ux.TextEditor.implementation.enrichHTML(this.document.system.description, { async: true }),
isEditMode: this.isEditMode,
isPlayMode: this.isPlayMode,
isEditable: this.isEditable,
}
return context
}
/** @override */
_onRender(context, options) {
this.#dragDrop.forEach((d) => d.bind(this.element))
}
// #region Drag-and-Drop Workflow
/**
* Create drag-and-drop workflow handlers for this Application
* @returns {DragDrop[]} An array of DragDrop handlers
* @private
*/
#createDragDropHandlers() {
return this.options.dragDrop.map((d) => {
d.permissions = {
dragstart: this._canDragStart.bind(this),
drop: this._canDragDrop.bind(this),
}
d.callbacks = {
dragstart: this._onDragStart.bind(this),
dragover: this._onDragOver.bind(this),
drop: this._onDrop.bind(this),
}
return new foundry.applications.ux.DragDrop.implementation(d)
})
}
/**
* Define whether a user is able to begin a dragstart workflow for a given drag selector
* @param {string} selector The candidate HTML selector for dragging
* @returns {boolean} Can the current user drag this selector?
* @protected
*/
_canDragStart(selector) {
return this.isEditable
}
/**
* Define whether a user is able to conclude a drag-and-drop workflow for a given drop selector
* @param {string} selector The candidate HTML selector for the drop target
* @returns {boolean} Can the current user drop on this selector?
* @protected
*/
_canDragDrop(selector) {
return this.isEditable && this.document.isOwner
}
/**
* Callback actions which occur at the beginning of a drag start workflow.
* @param {DragEvent} event The originating DragEvent
* @protected
*/
_onDragStart(event) {
const el = event.currentTarget
if ("link" in event.target.dataset) return
// Extract the data you need
let dragData = null
if (!dragData) return
// Set data transfer
event.dataTransfer.setData("text/plain", JSON.stringify(dragData))
}
/**
* Callback actions which occur when a dragged element is over a drop target.
* @param {DragEvent} event The originating DragEvent
* @protected
*/
_onDragOver(event) { }
/**
* Callback actions which occur when a dragged element is dropped on a target.
* @param {DragEvent} event The originating DragEvent
* @protected
*/
async _onDrop(event) { }
// #endregion
// #region Actions
/**
* Handle toggling between Edit and Play mode.
* @param {Event} event The initiating click event.
* @param {HTMLElement} target The current target of the event listener.
*/
static #onToggleSheet(event, target) {
const modes = this.constructor.SHEET_MODES
this._sheetMode = this.isEditMode ? modes.PLAY : modes.EDIT
this.render()
}
/**
* Handle changing a Document's image.
*
* @this CthulhuEternalCharacterSheet
* @param {PointerEvent} event The originating click event
* @param {HTMLElement} target The capturing HTML element which defined a [data-action]
* @returns {Promise}
* @private
*/
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()
}
// #endregion
}
@@ -0,0 +1,28 @@
import HamalronItemSheet from "./base-item-sheet.mjs"
export default class HamalronCompetenceSheet extends HamalronItemSheet {
/** @override */
static DEFAULT_OPTIONS = {
classes: ["perk"],
position: {
width: 600,
},
window: {
contentClasses: ["perk-content"],
},
}
/** @override */
static PARTS = {
main: {
template: "systems/fvtt-hamalron/templates/competence.hbs",
},
}
/** @override */
async _prepareContext() {
const context = await super._prepareContext()
context.enrichedDescription = await foundry.applications.ux.TextEditor.implementation.enrichHTML(this.document.system.description, { async: true })
return context
}
}
+166
View File
@@ -0,0 +1,166 @@
import HamalronActorSheet from "./base-actor-sheet.mjs"
export default class HamalronEnemySheet extends HamalronActorSheet {
/** @override */
static DEFAULT_OPTIONS = {
classes: ["enemy"],
position: {
width: 860,
height: 620,
},
window: {
contentClasses: ["enemy-content"],
},
actions: {
createTrait: HamalronEnemySheet.#onCreateTrait,
createEquipment: HamalronEnemySheet.#onCreateEquipment,
createWeapon: HamalronEnemySheet.#onCreateWeapon,
createMalefica: HamalronEnemySheet.#onCreateMalefica,
}
}
/** @override */
static PARTS = {
main: {
template: "systems/fvtt-hamalron/templates/enemy-main.hbs",
},
tabs: {
template: "templates/generic/tab-navigation.hbs",
},
traits: {
template: "systems/fvtt-hamalron/templates/enemy-trait.hbs",
},
biography: {
template: "systems/fvtt-hamalron/templates/enemy-biography.hbs",
},
}
/** @override */
tabGroups = {
sheet: "traits",
}
/**
* Prepare an array of form header tabs.
* @returns {Record<string, Partial<ApplicationTab>>}
*/
#getTabs() {
const tabs = {
traits: { id: "traits", group: "sheet", icon: "fa-solid fa-shapes", label: "HAMALRON.Label.traits" },
biography: { id: "biography", group: "sheet", icon: "fa-solid fa-book", label: "HAMALRON.Label.biography" },
}
for (const v of Object.values(tabs)) {
v.active = this.tabGroups[v.group] === v.id
v.cssClass = v.active ? "active" : ""
}
return tabs
}
/** @override */
async _prepareContext() {
const context = await super._prepareContext()
context.tabs = this.#getTabs()
return context
}
/** @override */
async _preparePartContext(partId, context) {
const doc = this.document
switch (partId) {
case "main":
break
case "traits":
context.tab = context.tabs.traits
context.traits = doc.itemTypes["species-trait"]
context.traits.sort((a, b) => a.name.localeCompare(b.name))
context.weapons = doc.itemTypes.weapon
context.weapons.sort((a, b) => a.name.localeCompare(b.name))
context.maleficas = doc.itemTypes.malefica
context.maleficas.sort((a, b) => a.name.localeCompare(b.name))
context.equipments = doc.itemTypes.equipment
context.equipments.sort((a, b) => a.name.localeCompare(b.name))
break
case "biography":
context.tab = context.tabs.biography
context.enrichedDescription = await foundry.applications.ux.TextEditor.implementation.enrichHTML(doc.system.description, { async: true })
context.enrichedNotes = await foundry.applications.ux.TextEditor.implementation.enrichHTML(doc.system.notes, { async: true })
break
}
return context
}
/**
* Creates a new attack item directly from the sheet and embeds it into the document.
* @param {Event} event The initiating click event.
* @param {HTMLElement} target The current target of the event listener.
*/
static #onCreateTrait(event, target) {
this.document.createEmbeddedDocuments("Item", [{ name: game.i18n.localize("HAMALRON.Label.newTrait"), type: "species-trait" }])
}
static #onCreateEquipment(event, target) {
this.document.createEmbeddedDocuments("Item", [{ name: game.i18n.localize("HAMALRON.Label.newEquipment"), type: "equipment" }])
}
static #onCreateMalefica(event, target) {
this.document.createEmbeddedDocuments("Item", [{ name: game.i18n.localize("HAMALRON.Label.newMalefica"), type: "malefica" }])
}
static #onCreateWeapon(event, target) {
this.document.createEmbeddedDocuments("Item", [{ name: game.i18n.localize("HAMALRON.Label.newWeapon"), type: "weapon" }])
}
/**
* Handles the roll action triggered by user interaction.
*
* @param {PointerEvent} event The event object representing the user interaction.
* @param {HTMLElement} target The target element that triggered the roll.
*
* @returns {Promise<void>} A promise that resolves when the roll action is complete.
*
* @throws {Error} Throws an error if the roll type is not recognized.
*
* @description This method checks the current mode (edit or not) and determines the type of roll
* (save, resource, or damage) based on the target element's data attributes. It retrieves the
* corresponding value from the document's system and performs the roll.
*/
async _onRoll(event, target) {
const rollType = $(event.currentTarget).data("roll-type")
let item
switch (rollType) {
case "stat":
{
let statId = $(event.currentTarget).data("stat-id");
item = this.actor.system.stats[statId];
await this.document.system.roll(rollType, item)
}
break
case "weapon":
case "damage":
{
let li = $(event.currentTarget).parents(".item");
item = this.actor.items.get(li.data("item-id"));
await this.document.system.roll(rollType, item)
}
break
default:
throw new Error(`Unknown roll type ${rollType}`)
}
}
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)
}
}
}
@@ -0,0 +1,28 @@
import HamalronItemSheet from "./base-item-sheet.mjs"
export default class HamalronEquipementSheet extends HamalronItemSheet {
/** @override */
static DEFAULT_OPTIONS = {
classes: ["equipment"],
position: {
width: 500,
},
window: {
contentClasses: ["equipment-content"],
},
}
/** @override */
static PARTS = {
main: {
template: "systems/fvtt-hamalron/templates/equipement.hbs",
},
}
/** @override */
async _prepareContext() {
const context = await super._prepareContext()
context.enrichedDescription = await foundry.applications.ux.TextEditor.implementation.enrichHTML(this.document.system.description, { async: true })
return context
}
}
@@ -0,0 +1,52 @@
import HamalronItemSheet from "./base-item-sheet.mjs"
export default class HamalronFactionSheet extends HamalronItemSheet {
/** @override */
static DEFAULT_OPTIONS = {
classes: ["faction"],
position: {
width: 620,
},
window: {
contentClasses: ["faction-content"],
},
}
/** @override */
static PARTS = {
tabs: {
template: "templates/generic/tab-navigation.hbs",
},
main: {
template: "systems/fvtt-hamalron/templates/faction.hbs",
},
}
/** @override */
tabGroups = {
sheet: "main",
}
/**
* Prepare an array of form header tabs.
* @returns {Record<string, Partial<ApplicationTab>>}
*/
#getTabs() {
const tabs = {
main: { id: "main", group: "sheet", icon: "fa-solid fa-circle-info", label: "HAMALRON.Label.Details" },
}
for (const v of Object.values(tabs)) {
v.active = this.tabGroups[v.group] === v.id
v.cssClass = v.active ? "active" : ""
}
return tabs
}
/** @override */
async _prepareContext() {
const context = await super._prepareContext()
context.tabs = this.#getTabs()
context.enrichedDescription = await foundry.applications.ux.TextEditor.implementation.enrichHTML(this.document.system.description, { async: true })
return context
}
}
@@ -0,0 +1,52 @@
import HamalronItemSheet from "./base-item-sheet.mjs"
export default class HamalronLangueSheet extends HamalronItemSheet {
/** @override */
static DEFAULT_OPTIONS = {
classes: ["langue"],
position: {
width: 620,
},
window: {
contentClasses: ["langue-content"],
},
}
/** @override */
static PARTS = {
tabs: {
template: "templates/generic/tab-navigation.hbs",
},
main: {
template: "systems/fvtt-hamalron/templates/langue.hbs",
},
}
/** @override */
tabGroups = {
sheet: "main",
}
/**
* Prepare an array of form header tabs.
* @returns {Record<string, Partial<ApplicationTab>>}
*/
#getTabs() {
const tabs = {
main: { id: "main", group: "sheet", icon: "fa-solid fa-circle-info", label: "HAMALRON.Label.Details" },
}
for (const v of Object.values(tabs)) {
v.active = this.tabGroups[v.group] === v.id
v.cssClass = v.active ? "active" : ""
}
return tabs
}
/** @override */
async _prepareContext() {
const context = await super._prepareContext()
context.tabs = this.#getTabs()
context.enrichedDescription = await foundry.applications.ux.TextEditor.implementation.enrichHTML(this.document.system.description, { async: true })
return context
}
}
@@ -0,0 +1,264 @@
import HamalronActorSheet from "./base-actor-sheet.mjs"
export default class HamalronPersonnageSheet extends HamalronActorSheet {
/** @override */
static DEFAULT_OPTIONS = {
classes: ["character"],
position: {
width: 860,
height: 620,
},
window: {
contentClasses: ["character-content"],
},
actions: {
createEquipment: HamalronPersonnageSheet.#onCreateEquipment,
createArmor: HamalronPersonnageSheet.#onCreateArmor,
createWeapon: HamalronPersonnageSheet.#onCreateWeapon,
createDeal: HamalronPersonnageSheet.#onCreateDeal,
createMalefica: HamalronPersonnageSheet.#onCreateMalefica,
createRitual: HamalronPersonnageSheet.#onCreateRitual,
createPerk: HamalronPersonnageSheet.#onCreatePerk,
modifyAmmo: HamalronPersonnageSheet.#onModifyAmmo,
},
}
/** @override */
static PARTS = {
main: {
template: "systems/fvtt-hamalron/templates/personnage-main.hbs",
},
tabs: {
template: "templates/generic/tab-navigation.hbs",
},
status: {
template: "systems/fvtt-hamalron/templates/personnage-status.hbs",
},
maleficas: {
template: "systems/fvtt-hamalron/templates/personnage-sortileges.hbs",
},
equipment: {
template: "systems/fvtt-hamalron/templates/personnage-equipement.hbs",
},
tarot: {
template: "systems/fvtt-hamalron/templates/personnage-tarot.hbs",
},
biography: {
template: "systems/fvtt-hamalron/templates/personnage-biographie.hbs",
},
}
/** @override */
tabGroups = {
sheet: "status",
}
/**
* Prepare an array of form header tabs.
* @returns {Record<string, Partial<ApplicationTab>>}
*/
#getTabs() {
const tabs = {
status: { id: "status", group: "sheet", icon: "fa-solid fa-compass", label: "HAMALRON.Label.status" },
maleficas: { id: "maleficas", group: "sheet", icon: "fa-solid fa-compass", label: "HAMALRON.Label.maleficas" },
equipment: { id: "equipment", group: "sheet", icon: "fa-solid fa-shapes", label: "HAMALRON.Label.equipment" },
tarot: { id: "tarot", group: "sheet", icon: "fa-solid fa-cards", label: "HAMALRON.Label.tarot" },
biography: { id: "biography", group: "sheet", icon: "fa-solid fa-book", label: "HAMALRON.Label.biography" },
}
for (const v of Object.values(tabs)) {
v.active = this.tabGroups[v.group] === v.id
v.cssClass = v.active ? "active" : ""
}
return tabs
}
/** @override */
async _prepareContext() {
const context = await super._prepareContext()
context.tabs = this.#getTabs()
const doc = this.document
context.trait = doc.itemTypes['species-trait']?.[0]
context.upright = doc.itemTypes.tarot.find(t => t.system.orientation === "Upright")
context.downright = doc.itemTypes.tarot.find(t => t.system.orientation === "Downright")
return context
}
/** @override */
async _preparePartContext(partId, context) {
const doc = this.document
context.systemFields = this.document.system.schema.fields
switch (partId) {
case "main":
break
case "status":
context.tab = context.tabs.status
context.perks = doc.itemTypes.perk || []
// Sort the perks by system.role and then by the system.level
context.perks.sort((a, b) => {
if (a.system.role === b.system.role) {
return a.system.level.localeCompare(b.system.level)
}
return a.system.role.localeCompare(b.system.role)
})
break;
case "maleficas":
context.tab = context.tabs.maleficas
context.maleficas = doc.itemTypes.malefica || []
// Sort the maleficas by system.domain and then by the system.level
context.maleficas.sort((a, b) => {
if (a.system.domain === b.system.domain) {
return a.system.level.localeCompare(b.system.level)
}
return a.system.domain.localeCompare(b.system.domain)
})
context.rituals = doc.itemTypes.ritual || []
context.rituals.sort((a, b) => a.name.localeCompare(b.name))
break
case "equipment":
context.tab = context.tabs.equipment
context.weapons = doc.itemTypes.weapon || []
context.weapons.sort((a, b) => a.name.localeCompare(b.name))
context.armors = doc.itemTypes.armor || []
context.armors.sort((a, b) => a.name.localeCompare(b.name))
context.equipments = doc.itemTypes.equipment || []
context.equipments.sort((a, b) => a.name.localeCompare(b.name))
break
case "tarot":
context.tab = context.tabs.tarot
context.tarotCards = doc.itemTypes.tarot || []
context.tarotCards.sort((a, b) => a.name.localeCompare(b.name))
// Enrich descriptions for each tarot card
for (const card of context.tarotCards) {
card.enrichedDescription = await foundry.applications.ux.TextEditor.implementation.enrichHTML(card.system.description, { async: true })
}
break
case "biography":
context.tab = context.tabs.biography
context.deals = doc.itemTypes.deal || []
context.enrichedBackstory = await foundry.applications.ux.TextEditor.implementation.enrichHTML(this.document.system.backstory, { async: true })
context.enrichedAppearance = await foundry.applications.ux.TextEditor.implementation.enrichHTML(this.document.system.appearance, { async: true })
context.enrichedScars = await foundry.applications.ux.TextEditor.implementation.enrichHTML(this.document.system.scars, { async: true })
context.enrichedLikes = await foundry.applications.ux.TextEditor.implementation.enrichHTML(this.document.system.likes, { async: true })
context.enrichedDislikes = await foundry.applications.ux.TextEditor.implementation.enrichHTML(this.document.system.dislikes, { async: true })
context.enrichedFears = await foundry.applications.ux.TextEditor.implementation.enrichHTML(this.document.system.fears, { async: true })
context.enrichedVices = await foundry.applications.ux.TextEditor.implementation.enrichHTML(this.document.system.vices, { async: true })
context.enrichedGoals = await foundry.applications.ux.TextEditor.implementation.enrichHTML(this.document.system.goals, { async: true })
context.enrichedAmbitions = await foundry.applications.ux.TextEditor.implementation.enrichHTML(this.document.system.ambitions, { async: true })
context.enrichedValues = await foundry.applications.ux.TextEditor.implementation.enrichHTML(this.document.system.values, { async: true })
context.enrichedBonds = await foundry.applications.ux.TextEditor.implementation.enrichHTML(this.document.system.bonds, { async: true })
context.enrichedNotes = await foundry.applications.ux.TextEditor.implementation.enrichHTML(this.document.system.notes, { async: true })
break
}
return context
}
static #onCreateEquipment(event, target) {
this.document.createEmbeddedDocuments("Item", [{ name: game.i18n.localize("HAMALRON.Label.newEquipment"), type: "equipment" }])
}
static #onCreateDeal(event, target) {
this.document.createEmbeddedDocuments("Item", [{ name: game.i18n.localize("HAMALRON.Label.newDeal"), type: "deal" }])
}
static #onCreateMalefica(event, target) {
this.document.createEmbeddedDocuments("Item", [{ name: game.i18n.localize("HAMALRON.Label.newMalefica"), type: "malefica" }])
}
static #onCreateRitual(event, target) {
this.document.createEmbeddedDocuments("Item", [{ name: game.i18n.localize("HAMALRON.Label.newRitual"), type: "ritual" }])
}
static #onCreateWeapon(event, target) {
this.document.createEmbeddedDocuments("Item", [{ name: game.i18n.localize("HAMALRON.Label.newWeapon"), type: "weapon" }])
}
static #onCreateArmor(event, target) {
this.document.createEmbeddedDocuments("Item", [{ name: game.i18n.localize("HAMALRON.Label.newArmor"), type: "armor" }])
}
static #onCreatePerk(event, target) {
this.document.createEmbeddedDocuments("Item", [{ name: game.i18n.localize("HAMALRON.Label.newPerk"), type: "perk" }])
}
static async #onModifyAmmo(event, target) {
const quantity = parseInt($(event.target).data("quantity"))
const itemId = $(event.target).data("item-id")
const item = this.document.items.get(itemId)
if (!item) {
console.warn(`HamalronCharacterSheet: Item with ID ${itemId} not found`)
return
}
const currentAmmo = item.system.ammoQuantity || 0
const newAmmo = Math.max(0, currentAmmo + quantity) // Ensure ammo doesn't go below 0
await item.update({ "system.ammoQuantity": newAmmo })
}
/**
* Handles the roll action triggered by user interaction.
*
* @param {PointerEvent} event The event object representing the user interaction.
* @param {HTMLElement} target The target element that triggered the roll.
*
* @returns {Promise<void>} A promise that resolves when the roll action is complete.
*
* @throws {Error} Throws an error if the roll type is not recognized.
*
* @description This method checks the current mode (edit or not) and determines the type of roll
* (save, resource, or damage) based on the target element's data attributes. It retrieves the
* corresponding value from the document's system and performs the roll.
*/
async _onRoll(event, target) {
const rollType = $(event.currentTarget).data("roll-type")
let item
let li
let statKey
switch (rollType) {
case "stat":
statKey = $(event.currentTarget).data("stat-id");
item = this.actor.system.stats[statKey];
break
case "weapon":
case "damage":
li = $(event.currentTarget).parents(".item");
item = this.actor.items.get(li.data("item-id"));
break
default:
throw new Error(`Unknown roll type ${rollType}`)
}
await this.document.system.roll(rollType, item)
}
async _onDrop(event) {
if (!this.isEditable || !this.isEditMode) return
const data = foundry.applications.ux.TextEditor.implementation.getDragEventData(event)
// Handle different data types
if (data.type === "Item") {
const item = await fromUuid(data.uuid)
if (item.type === "tarot") {
// Delete the existing tarot item
const existingTarot = this.document.items.find(i => i.type === "tarot" && i.system.orientation === item.system.orientation)
if (existingTarot) {
await existingTarot.delete()
// Display info message
ui.notifications.info(game.i18n.localize("HAMALRON.Notifications.tarotDeleted") + existingTarot.name)
}
}
if (item.type === "species-trait") {
// Check if the item is already in the actor
const existingTrait = this.document.items.find(i => i.type === "species-trait" && i.name === item.name)
if (existingTrait) {
await existingTrait.delete()
// Display info message
ui.notifications.info(game.i18n.localize("HAMALRON.Notifications.speciesTraitDeleted") + existingTrait.name)
}
}
return super._onDropItem(item)
}
}
}
@@ -0,0 +1,52 @@
import HamalronItemSheet from "./base-item-sheet.mjs"
export default class HamalronPeupleSheet extends HamalronItemSheet {
/** @override */
static DEFAULT_OPTIONS = {
classes: ["peuple"],
position: {
width: 620,
},
window: {
contentClasses: ["peuple-content"],
},
}
/** @override */
static PARTS = {
tabs: {
template: "templates/generic/tab-navigation.hbs",
},
main: {
template: "systems/fvtt-hamalron/templates/peuple.hbs",
},
}
/** @override */
tabGroups = {
sheet: "main",
}
/**
* Prepare an array of form header tabs.
* @returns {Record<string, Partial<ApplicationTab>>}
*/
#getTabs() {
const tabs = {
main: { id: "main", group: "sheet", icon: "fa-solid fa-circle-info", label: "HAMALRON.Label.Details" },
}
for (const v of Object.values(tabs)) {
v.active = this.tabGroups[v.group] === v.id
v.cssClass = v.active ? "active" : ""
}
return tabs
}
/** @override */
async _prepareContext() {
const context = await super._prepareContext()
context.tabs = this.#getTabs()
context.enrichedDescription = await foundry.applications.ux.TextEditor.implementation.enrichHTML(this.document.system.description, { async: true })
return context
}
}
@@ -0,0 +1,52 @@
import HamalronItemSheet from "./base-item-sheet.mjs"
export default class HamalronRegionSheet extends HamalronItemSheet {
/** @override */
static DEFAULT_OPTIONS = {
classes: ["region"],
position: {
width: 620,
},
window: {
contentClasses: ["region-content"],
},
}
/** @override */
static PARTS = {
tabs: {
template: "templates/generic/tab-navigation.hbs",
},
main: {
template: "systems/fvtt-hamalron/templates/region.hbs",
},
}
/** @override */
tabGroups = {
sheet: "main",
}
/**
* Prepare an array of form header tabs.
* @returns {Record<string, Partial<ApplicationTab>>}
*/
#getTabs() {
const tabs = {
main: { id: "main", group: "sheet", icon: "fa-solid fa-circle-info", label: "HAMALRON.Label.Details" },
}
for (const v of Object.values(tabs)) {
v.active = this.tabGroups[v.group] === v.id
v.cssClass = v.active ? "active" : ""
}
return tabs
}
/** @override */
async _prepareContext() {
const context = await super._prepareContext()
context.tabs = this.#getTabs()
context.enrichedDescription = await foundry.applications.ux.TextEditor.implementation.enrichHTML(this.document.system.description, { async: true })
return context
}
}
@@ -0,0 +1,29 @@
import HamalronItemSheet from "./base-item-sheet.mjs"
export default class HamalronSortilegeSheet extends HamalronItemSheet {
/** @override */
static DEFAULT_OPTIONS = {
classes: ["ritual"],
position: {
width: 600,
},
window: {
contentClasses: ["ritual-content"],
},
}
/** @override */
static PARTS = {
main: {
template: "systems/fvtt-hamalron/templates/sortilege.hbs",
},
}
/** @override */
async _prepareContext() {
const context = await super._prepareContext()
context.enrichedDescription = await foundry.applications.ux.TextEditor.implementation.enrichHTML(this.document.system.description, { async: true })
return context
}
}
@@ -0,0 +1,31 @@
import HamalronItemSheet from "./base-item-sheet.mjs"
export default class HamalronTarotSheet extends HamalronItemSheet {
/** @override */
static DEFAULT_OPTIONS = {
classes: ["tarot"],
position: {
width: 800,
height: 800
},
window: {
contentClasses: ["tarot-content"],
},
}
/** @override */
static PARTS = {
main: {
template: "systems/fvtt-hamalron/templates/tarot.hbs",
},
}
/** @override */
async _prepareContext() {
const context = await super._prepareContext()
context.enrichedDescription = await foundry.applications.ux.TextEditor.implementation.enrichHTML(this.document.system.description, { async: true })
context.enrichedPositiveEffect = await foundry.applications.ux.TextEditor.implementation.enrichHTML(this.document.system.positiveEffect, { async: true })
context.enrichedNegativeEffect = await foundry.applications.ux.TextEditor.implementation.enrichHTML(this.document.system.negativeEffect, { async: true })
return context
}
}
+205
View File
@@ -0,0 +1,205 @@
const { HandlebarsApplicationMixin } = foundry.applications.api
export default class HamalronTarotDeckManager extends HandlebarsApplicationMixin(foundry.applications.api.ApplicationV2) {
constructor(options = {}) {
super(options)
this.deck = []
this.drawnCards = []
this.resetDeck()
}
/** @override */
static DEFAULT_OPTIONS = {
id: "tarot-deck-manager",
classes: ["fvtt-hamalron", "tarot-deck-manager"],
tag: "div",
window: {
title: "HAMALRON.TarotDeck.Title",
icon: "fas fa-cards",
resizable: true,
},
position: {
width: 600,
height: 700,
},
actions: {
resetDeck: HamalronTarotDeckManager.#onResetDeck,
drawCard: HamalronTarotDeckManager.#onDrawCard,
drawMultiple: HamalronTarotDeckManager.#onDrawMultiple,
},
}
/** @override */
static PARTS = {
main: {
template: "systems/fvtt-hamalron/templates/tarot-deck-manager.hbs",
},
}
/**
* Reset the deck to a full tarot deck
*/
resetDeck() {
this.deck = []
this.drawnCards = []
// Créer toutes les cartes du jeu de tarot
const items = game.items.filter(i => i.type === "tarot")
if (items.length > 0) {
// Utiliser les items existants
this.deck = items.map(item => ({
id: item.id,
name: item.name,
img: item.img,
symbole: item.system.symbole,
valeur: item.system.valeur,
type: item.system.type,
description: item.system.description,
}))
} else {
ui.notifications.warn("HAMALRON.TarotDeck.NoCardsFound", { localize: true })
}
// Mélanger le deck
this.shuffleDeck()
this.render()
}
/**
* Shuffle the deck using Fisher-Yates algorithm
*/
shuffleDeck() {
for (let i = this.deck.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[this.deck[i], this.deck[j]] = [this.deck[j], this.deck[i]]
}
}
/**
* Draw a card from the deck
* @param {number} count - Number of cards to draw
* @returns {Array} - Drawn cards
*/
drawCards(count = 1) {
if (this.deck.length === 0) {
ui.notifications.warn("HAMALRON.TarotDeck.DeckEmpty", { localize: true })
return []
}
const drawn = []
for (let i = 0; i < count && this.deck.length > 0; i++) {
const card = this.deck.shift()
this.drawnCards.push(card)
drawn.push(card)
}
return drawn
}
/**
* Send drawn cards to chat
* @param {Array} cards - Cards to send to chat
*/
async sendCardsToChat(cards) {
if (cards.length === 0) return
const speaker = ChatMessage.getSpeaker({ alias: "Maître du Jeu" })
for (const card of cards) {
const content = await foundry.applications.handlebars.renderTemplate(
"systems/fvtt-hamalron/templates/chat-tarot-draw.hbs",
{
card: card,
symboleLabel: game.i18n.localize(`HAMALRON.Tarot.FIELDS.symbole.${card.symbole}`),
valeurLabel: game.i18n.localize(`HAMALRON.Tarot.FIELDS.valeur.${card.valeur}`),
typeLabel: game.i18n.localize(`HAMALRON.Tarot.FIELDS.type.${card.type}`),
}
)
await ChatMessage.create({
speaker: speaker,
content: content,
type: CONST.CHAT_MESSAGE_TYPES.OTHER,
})
}
}
/** @override */
async _prepareContext(options) {
const context = await super._prepareContext(options)
context.deckCount = this.deck.length
context.drawnCount = this.drawnCards.length
context.totalCards = this.deck.length + this.drawnCards.length
context.hasCards = this.deck.length > 0
context.drawnCards = this.drawnCards.slice(-5).reverse() // Show last 5 drawn cards
return context
}
/**
* Handle reset deck action
* @param {Event} event
* @param {HTMLElement} target
*/
static async #onResetDeck(event, target) {
const confirmed = await foundry.applications.api.DialogV2.confirm({
window: { title: "HAMALRON.TarotDeck.ResetConfirm" },
content: `<p>${game.i18n.localize("HAMALRON.TarotDeck.ResetWarning")}</p>`,
rejectClose: false,
modal: true,
})
if (confirmed) {
this.resetDeck()
ui.notifications.info("HAMALRON.TarotDeck.DeckReset", { localize: true })
}
}
/**
* Handle draw single card action
* @param {Event} event
* @param {HTMLElement} target
*/
static async #onDrawCard(event, target) {
const cards = this.drawCards(1)
if (cards.length > 0) {
await this.sendCardsToChat(cards)
this.render()
}
}
/**
* Handle draw multiple cards action
* @param {Event} event
* @param {HTMLElement} target
*/
static async #onDrawMultiple(event, target) {
const count = parseInt(target.dataset.count || "1")
const cards = this.drawCards(count)
if (cards.length > 0) {
await this.sendCardsToChat(cards)
this.render()
}
}
/**
* Open the Tarot Deck Manager application
* @returns {HamalronTarotDeckManager}
*/
static openManager() {
if (!game.user.isGM) {
ui.notifications.warn("HAMALRON.TarotDeck.GMOnly", { localize: true })
return
}
// Singleton pattern - reuse existing instance or create new one
if (!HamalronTarotDeckManager._instance) {
HamalronTarotDeckManager._instance = new HamalronTarotDeckManager()
}
HamalronTarotDeckManager._instance.render(true, { focus: true })
return HamalronTarotDeckManager._instance
}
}