2023-05-12 22:56:45 +02:00
|
|
|
import { TYPES } from "../item.js";
|
2021-02-12 01:16:02 +01:00
|
|
|
import { TMRUtility } from "../tmr-utility.js";
|
2021-02-11 02:48:27 +01:00
|
|
|
import { PixiTMR } from "./pixi-tmr.js";
|
|
|
|
|
|
|
|
const registeredEffects = [
|
|
|
|
]
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Définition des informations d'une "draconique" (queue, ombre, tête, souffle) qui influence les TMR
|
|
|
|
*/
|
2021-02-28 01:50:15 +01:00
|
|
|
export class Draconique {
|
2023-11-15 22:14:00 +01:00
|
|
|
static init() {
|
|
|
|
}
|
|
|
|
|
2023-05-12 22:56:45 +02:00
|
|
|
static isCaseTMR(item) { return item.type == TYPES.casetmr; }
|
|
|
|
static isQueueDragon(item) { return item.isQueueDragon(); }
|
2023-10-20 22:18:37 +02:00
|
|
|
static isSouffleDragon(item) { return item.type == TYPES.souffle; }
|
2023-05-12 22:56:45 +02:00
|
|
|
static isTeteDragon(item) { return item.type == TYPES.tete; }
|
2022-09-07 18:47:56 +02:00
|
|
|
static isQueueSouffle(item) { return Draconique.isQueueDragon(item) || Draconique.isSouffleDragon(item); }
|
2021-02-11 02:48:27 +01:00
|
|
|
|
2023-12-09 01:04:33 +01:00
|
|
|
static register(draconique, code = undefined) {
|
|
|
|
registeredEffects[code ?? draconique.code()] = draconique;
|
2021-02-11 02:48:27 +01:00
|
|
|
if (draconique.img()) {
|
|
|
|
PixiTMR.register(draconique.code(), draconique.img())
|
|
|
|
}
|
|
|
|
return draconique;
|
|
|
|
}
|
|
|
|
|
|
|
|
static all() {
|
|
|
|
return Object.values(registeredEffects);
|
|
|
|
}
|
2021-02-28 01:50:15 +01:00
|
|
|
|
2021-02-11 02:48:27 +01:00
|
|
|
static get(code) {
|
|
|
|
return registeredEffects[code];
|
|
|
|
}
|
|
|
|
|
2023-11-15 22:14:00 +01:00
|
|
|
tmrLabel(linkData) { return TMRUtility.getTMRLabel(linkData.system.coord); }
|
|
|
|
|
2021-02-11 02:48:27 +01:00
|
|
|
/**
|
|
|
|
* @param item un Item quelconque
|
|
|
|
* @returns true si l'item correspond
|
|
|
|
*/
|
|
|
|
match(item) {
|
2022-09-07 18:47:56 +02:00
|
|
|
return Draconique.isQueueDragon(item) || Draconique.isSouffleDragon(item) || Draconique.isTeteDragon(item);
|
2021-02-11 02:48:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @returns un message à afficher si la draconique doit être gérée manuellement.
|
|
|
|
*/
|
|
|
|
manualMessage() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Méthode responsable de gérer une draconique (par exemple, ajouter des casetmr pour la fermeture des cités).
|
|
|
|
* @param actor auquel la draconique est ajoutée
|
|
|
|
*/
|
2021-02-12 01:16:02 +01:00
|
|
|
async onActorCreateOwned(actor, item) {
|
2021-02-11 02:48:27 +01:00
|
|
|
return false;
|
|
|
|
}
|
2021-02-12 18:31:49 +01:00
|
|
|
|
2021-02-12 01:16:02 +01:00
|
|
|
async onActorDeleteOwned(actor, item) {
|
2021-02-28 01:50:15 +01:00
|
|
|
this.deleteCasesTmr(actor, item);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
async onActorDeleteCaseTmr(actor, casetmr) {
|
2021-02-11 02:48:27 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* @return le code interne utilisé pour les casetmr correpondant
|
|
|
|
*/
|
|
|
|
code() { return undefined }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {*} linkData données associées au token pixi (une casetmr, un sort en réserve, une rencontre en attente)
|
|
|
|
* @returns un tooltip à afficher au dessus du token
|
|
|
|
*/
|
|
|
|
tooltip(linkData) { return undefined }
|
2021-02-28 01:50:15 +01:00
|
|
|
|
2021-02-11 02:48:27 +01:00
|
|
|
/**
|
|
|
|
* @param {*} img l'url du fichier image à utiliser pour le token. Si indéfini (et si createSprite n'est pas surchargé),
|
|
|
|
* un disque est utilisé.
|
2023-10-20 22:18:37 +02:00
|
|
|
*/
|
2021-02-11 02:48:27 +01:00
|
|
|
img() { return undefined }
|
|
|
|
|
|
|
|
/**
|
2023-10-20 22:18:37 +02:00
|
|
|
* factory d'élément graphique PIXI correspondant à l'objet draconique
|
2021-02-11 02:48:27 +01:00
|
|
|
* @param {*} pixiTMR instance de PixiTMR qui gère les tooltips, les méthodes de création de sprite standard, les clicks.
|
2023-10-20 22:18:37 +02:00
|
|
|
*/
|
2021-02-11 02:48:27 +01:00
|
|
|
token(pixiTMR, linkData, coordTMR, type = undefined) {
|
2023-11-10 03:39:35 +01:00
|
|
|
const tooltip = this.tooltip(linkData);
|
2023-12-09 01:04:33 +01:00
|
|
|
return this._createToken(pixiTMR, linkData, coordTMR, type, tooltip);
|
|
|
|
}
|
|
|
|
|
|
|
|
tokens(pixiTMR, linkData, coordTMR, type = undefined) {
|
|
|
|
const tooltip = this.tooltip(linkData);
|
|
|
|
return [this._createToken(pixiTMR, linkData, coordTMR, type, tooltip)];
|
|
|
|
}
|
|
|
|
|
|
|
|
_createToken(pixiTMR, linkData, coordTMR, type, tooltip) {
|
2021-02-11 02:48:27 +01:00
|
|
|
const token = {
|
2021-02-12 18:31:49 +01:00
|
|
|
sprite: this.createSprite(pixiTMR),
|
2023-11-10 03:39:35 +01:00
|
|
|
coordTMR: coordTMR,
|
|
|
|
tooltip: tooltip
|
2021-02-11 02:48:27 +01:00
|
|
|
};
|
|
|
|
token[type ?? this.code()] = linkData;
|
|
|
|
return token;
|
|
|
|
}
|
2022-06-25 17:49:19 +02:00
|
|
|
|
2021-02-11 02:48:27 +01:00
|
|
|
/**
|
|
|
|
* factory d'élément graphique PIXI correpsondant à l'objet draconique
|
|
|
|
* @param {*} pixiTMR instance de PixiTMR qui gère les tooltips, les méthodes de création de sprite standard, les clicks.
|
|
|
|
*/
|
2021-02-12 18:31:49 +01:00
|
|
|
createSprite(pixiTMR) {
|
2021-02-11 02:48:27 +01:00
|
|
|
if (this.img()) {
|
2023-11-15 22:14:00 +01:00
|
|
|
return pixiTMR.sprite(this.code())
|
2021-02-11 02:48:27 +01:00
|
|
|
}
|
2021-02-28 01:50:15 +01:00
|
|
|
else {
|
2021-02-11 02:48:27 +01:00
|
|
|
return pixiTMR.circle()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
2021-03-29 23:41:08 +02:00
|
|
|
* @param {*} item un item à tester
|
2021-02-11 02:48:27 +01:00
|
|
|
* @param {*} coord les coordonnées d'une case. Si undefined toute case du type correspondra,
|
|
|
|
*/
|
2021-03-29 23:41:08 +02:00
|
|
|
isCase(item, coord = undefined) {
|
2022-06-12 12:14:55 +02:00
|
|
|
return Draconique.isCaseTMR(item) && item.system.specific == this.code() && (coord ? item.system.coord == coord : true);
|
2021-02-11 02:48:27 +01:00
|
|
|
}
|
2023-10-20 22:18:37 +02:00
|
|
|
|
2021-02-12 01:16:02 +01:00
|
|
|
find(list, coord = undefined) {
|
2022-06-12 12:14:55 +02:00
|
|
|
return list.find(c => this.isCase(c, coord));
|
2021-02-12 01:16:02 +01:00
|
|
|
}
|
2023-10-20 22:18:37 +02:00
|
|
|
|
2021-02-28 01:50:15 +01:00
|
|
|
async createCaseTmr(actor, label, tmr, sourceId = undefined) {
|
2021-03-29 23:41:08 +02:00
|
|
|
const casetmrData = {
|
2023-11-15 22:14:00 +01:00
|
|
|
name: label,
|
|
|
|
type: 'casetmr',
|
|
|
|
img: this.img(),
|
2022-06-12 12:14:55 +02:00
|
|
|
system: { coord: tmr.coord, specific: this.code(), sourceid: sourceId }
|
2021-03-29 23:41:08 +02:00
|
|
|
};
|
|
|
|
await actor.createEmbeddedDocuments('Item', [casetmrData]);
|
2021-02-11 02:48:27 +01:00
|
|
|
}
|
2023-10-20 22:18:37 +02:00
|
|
|
|
2021-02-28 01:50:15 +01:00
|
|
|
async deleteCasesTmr(actor, draconique) {
|
2022-06-12 12:14:55 +02:00
|
|
|
let caseTmrs = actor.items.filter(it => this.isCaseForSource(it, draconique));
|
2021-03-29 23:41:08 +02:00
|
|
|
await actor.deleteEmbeddedDocuments('Item', caseTmrs.map(it => it.id));
|
|
|
|
}
|
2023-10-20 22:18:37 +02:00
|
|
|
|
2021-03-29 23:41:08 +02:00
|
|
|
isCaseForSource(item, draconique) {
|
2022-06-12 12:14:55 +02:00
|
|
|
return Draconique.isCaseTMR(item) && item.system.specific == this.code() && item.system.sourceid == draconique.id;
|
2021-02-28 01:50:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
async onVisiteSupprimer(actor, tmr, onRemoveToken) {
|
2022-06-12 12:14:55 +02:00
|
|
|
let existants = actor.items.filter(it => this.isCase(it, tmr.coord));
|
2021-03-29 23:41:08 +02:00
|
|
|
await actor.deleteEmbeddedDocuments('Item', existants.map(it => it.id));
|
2021-02-28 01:50:15 +01:00
|
|
|
for (let casetmr of existants) {
|
|
|
|
onRemoveToken(tmr, casetmr);
|
|
|
|
}
|
|
|
|
}
|
2021-02-11 02:48:27 +01:00
|
|
|
}
|