68b3079da8
Corrections majeures : - HamalronTirageTarot extends Roll (évaluation des jets fonctionnelle) - Correction du nom de classe Langue (HamalronFaction -> HamalronLangue) - Création du template tab-navigation.hbs manquant - Type acteur 'character' -> 'personnage' dans _preCreate Types d'items corrigés (anglais -> français) : - weapon -> arme, armor -> armure, equipment -> equipement - Suppression des types inexistants (deal, malefica, ritual, perk) Modèles : - cost -> cout (armure, equipement) - Tarot : default -> initial - Sortilege : LOCALIZATION_PREFIXES corrigé - Constantes CHOICE_ADVANTAGES_DISADVANTAGES et ATTACK_MODIFIERS ajoutées - ATTACK_MODIFIERS supprimé (plus utilisé) Templates alignés sur les modèles réels : - enemy-trait : suppression champs manquants (trauma, stats, domain...) - personnage-equipement : champs alignés sur arme/armure/equipement - personnage-sortileges : suppression domain/level/rituals - enemy-main : suppression stats et flavorText - base-actor : suppression mortality, toChat limité aux tarots Jets de compétence : - Égalité = réussite (>= au lieu de >, conforme aux règles p.155) - Comparaison robuste des cartes de succès (via String()) Le Mat : - Les autres joueurs peuvent renouveler leur main (règle p.151) findTarotItem : recherche dans game.items puis compendiums await manquants ajoutés sur saveDeckState() AGENTS.md créé
234 lines
6.8 KiB
JavaScript
234 lines
6.8 KiB
JavaScript
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,
|
|
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(),
|
|
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 async #toChat(event, target) {
|
|
const itemUuid = target.getAttribute("data-item-uuid")
|
|
const item = fromUuidSync(itemUuid)
|
|
if (!item) return
|
|
if (item.type !== "tarot") return
|
|
const content = await foundry.applications.handlebars.renderTemplate("systems/fvtt-hamalron/templates/chat-tarot.hbs", item.toObject())
|
|
const actor = this.actor || this.document?.parent
|
|
ChatMessage.create({
|
|
user: game.user.id,
|
|
speaker: ChatMessage.getSpeaker({ actor }),
|
|
content,
|
|
type: CONST.CHAT_MESSAGE_TYPES.OTHER,
|
|
}, { 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
|
|
}
|