Réduction de l'espace des TMR
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
import { SHOW_DICE } from "./constants.js";
|
||||
import { SHOW_DICE, SYSTEM_RDD } from "./constants.js";
|
||||
import { RollDataAjustements } from "./rolldata-ajustements.js";
|
||||
import { RdDUtility } from "./rdd-utility.js";
|
||||
import { TMRUtility } from "./tmr-utility.js";
|
||||
@ -18,17 +18,40 @@ import { RdDRencontre } from "./item/rencontre.js";
|
||||
import { RdDTimestamp } from "./time/rdd-timestamp.js";
|
||||
import { TYPES } from "./item.js";
|
||||
|
||||
const TMR_DISPLAY_SIZE = {
|
||||
code: 'tmr-display-size',
|
||||
range: {
|
||||
min: 32,
|
||||
max: 128,
|
||||
step: 8,
|
||||
},
|
||||
def: 64,
|
||||
clamp: (size, inc = 0) => Math.max(TMR_DISPLAY_SIZE.range.min, Math.min(size + (inc * TMR_DISPLAY_SIZE.range.step), TMR_DISPLAY_SIZE.range.max)),
|
||||
get: () => TMR_DISPLAY_SIZE.clamp(game.settings.get(SYSTEM_RDD, TMR_DISPLAY_SIZE.code) ?? TMR_DISPLAY_SIZE.def),
|
||||
set: (size) => game.settings.set(SYSTEM_RDD, TMR_DISPLAY_SIZE.code, TMR_DISPLAY_SIZE.clamp(size)),
|
||||
};
|
||||
|
||||
/* -------------------------------------------- */
|
||||
export class RdDTMRDialog extends Dialog {
|
||||
static async init() {
|
||||
game.settings.register(SYSTEM_RDD, TMR_DISPLAY_SIZE.code, {
|
||||
name: 'Taille des cases des TMR',
|
||||
hint: "Taille en pixel des cases des TMR (réglable directement dans la fenêtre des TMR)",
|
||||
scope: "client",
|
||||
config: true,
|
||||
default: TMR_DISPLAY_SIZE.def,
|
||||
type: Number,
|
||||
range: TMR_DISPLAY_SIZE.range
|
||||
})
|
||||
await PixiTMR.init()
|
||||
}
|
||||
|
||||
static async create(actor, tmrData) {
|
||||
let html = await renderTemplate('systems/foundryvtt-reve-de-dragon/templates/dialog-tmr.html', tmrData);
|
||||
|
||||
if (tmrData.mode != 'visu') {
|
||||
// Notification au MJ
|
||||
if (tmrData.mode != 'visu' && !game.user.isGM) {
|
||||
ChatMessage.create({ content: actor.name + " est monté dans les TMR en mode : " + tmrData.mode, whisper: ChatMessage.getWhisperRecipients("GM") });
|
||||
}
|
||||
|
||||
return new RdDTMRDialog(html, actor, tmrData);
|
||||
}
|
||||
|
||||
@ -37,21 +60,16 @@ export class RdDTMRDialog extends Dialog {
|
||||
const dialogConf = {
|
||||
title: "Terres Médianes de Rêve",
|
||||
content: html,
|
||||
buttons: {
|
||||
closeButton: {
|
||||
label: "Fermer", callback: html => this.close()
|
||||
}
|
||||
},
|
||||
default: "closeButton"
|
||||
buttons: {}
|
||||
}
|
||||
|
||||
const dialogOptions = {
|
||||
classes: ["tmrdialog"],
|
||||
width: 920, maxheight: 1024, height: 'fit-content',
|
||||
width: 'fit-content',
|
||||
height: 'fit-content',
|
||||
'max-height': 1024,
|
||||
'z-index': 40
|
||||
}
|
||||
super(dialogConf, dialogOptions);
|
||||
|
||||
this.tmrdata = duplicate(tmrData);
|
||||
this.actor = actor;
|
||||
this.actor.tmrApp = this; // reference this app in the actor structure
|
||||
@ -62,25 +80,97 @@ export class RdDTMRDialog extends Dialog {
|
||||
this.loadCasesSpeciales();
|
||||
this.allTokens = [];
|
||||
this.rencontreState = 'aucune';
|
||||
this.pixiTMR = new PixiTMR(this);
|
||||
|
||||
this.subdialog = undefined
|
||||
|
||||
this.callbacksOnAnimate = [];
|
||||
this.displaySize = undefined
|
||||
if (!this.viewOnly) {
|
||||
this._tellToGM(this.actor.name + " monte dans les terres médianes (" + tmrData.mode + ")");
|
||||
}
|
||||
this.callbacksOnAnimate = [];
|
||||
this.resizePixiTMR(
|
||||
TMR_DISPLAY_SIZE.clamp(game.settings.get(SYSTEM_RDD, TMR_DISPLAY_SIZE.code) ?? TMR_DISPLAY_SIZE.def)
|
||||
)
|
||||
}
|
||||
|
||||
// load the texture we need
|
||||
this.pixiTMR.load((loader, resources) => this.createPixiSprites());
|
||||
resizePixiTMR(displaySize) {
|
||||
if (displaySize != this.displaySize) {
|
||||
if (!this.pixiTMR) {
|
||||
this.pixiTMR = new PixiTMR(this, displaySize);
|
||||
}
|
||||
this.displaySize = displaySize
|
||||
this.pixiTMR.resizeTMR(displaySize);
|
||||
this._removeTokens()
|
||||
this.allTokens = []
|
||||
this.createPixiSprites()
|
||||
this.pixiTMR.loadAnimations();
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async activateListeners(html) {
|
||||
super.activateListeners(html);
|
||||
this.html = html;
|
||||
|
||||
// this.activateTMRSize()
|
||||
this.addTMRMap()
|
||||
this.html.find('div.tmr-size a.tmr-size-zoom-minus*').click(event => {
|
||||
this.$changeTMRSize(-1)
|
||||
});
|
||||
this.html.find('div.tmr-size a.tmr-size-zoom-plus*').click(event => {
|
||||
this.$changeTMRSize(1)
|
||||
});
|
||||
|
||||
|
||||
if (this.viewOnly) {
|
||||
this.html.find('.lancer-sort').remove();
|
||||
this.html.find('.lire-signe-draconique').remove();
|
||||
return;
|
||||
}
|
||||
|
||||
HtmlUtility.showControlWhen(this.html.find(".appliquerFatigue"), ReglesOptionnelles.isUsing("appliquer-fatigue"));
|
||||
HtmlUtility.showControlWhen(this.html.find(".lire-signe-draconique"), this.actor.isResonanceSigneDraconique(this._getCoordActor()));
|
||||
|
||||
this.html.find('form.tmr-dialog *').click(event => this.subdialog?.bringToTop());
|
||||
|
||||
// Roll Sort
|
||||
this.html.find('.lancer-sort').click(event => this.actor.rollUnSort(this._getCoordActor()));
|
||||
this.html.find('.lire-signe-draconique').click(event => this.actor.rollLireSigneDraconique(this._getCoordActor()));
|
||||
|
||||
this.html.find('img.tmr-move').click(event => this.deplacementTMR(this.html.find(event.currentTarget)?.data('move')));
|
||||
|
||||
// Gestion du cout de montée en points de rêve
|
||||
await this.actor.reveActuelIncDec(this.calculCoutMonteeTMR());
|
||||
this.cumulFatigue += this.fatigueParCase;
|
||||
|
||||
// Le reste...
|
||||
this.updateValuesDisplay();
|
||||
}
|
||||
|
||||
async onDeplacement() {
|
||||
await this.manageRencontre(TMRUtility.getTMR(this._getCoordActor()));
|
||||
}
|
||||
|
||||
addTMRMap() {
|
||||
const tmrCell = document.getElementsByClassName("tmr-map")[0];
|
||||
tmrCell.childNodes.forEach(node => tmrCell.removeChild(node))
|
||||
tmrCell.append(this.pixiTMR.view);
|
||||
}
|
||||
|
||||
$changeTMRSize(inc) {
|
||||
let displaySize = TMR_DISPLAY_SIZE.clamp(this.displaySize, inc)
|
||||
if (displaySize != this.displaySize) {
|
||||
game.settings.set(SYSTEM_RDD, TMR_DISPLAY_SIZE.code, TMR_DISPLAY_SIZE.clamp(displaySize))
|
||||
this.resizePixiTMR(displaySize)
|
||||
this.render()
|
||||
}
|
||||
}
|
||||
|
||||
async forceTMRDisplay() {
|
||||
this.bringToTop();
|
||||
if (this.subdialog) {
|
||||
this.bringToTop()
|
||||
if (this.subdialog?.bringToTop) {
|
||||
this.subdialog.bringToTop();
|
||||
}
|
||||
}
|
||||
|
||||
async restoreTMRAfterAction() {
|
||||
this.subdialog = undefined
|
||||
await this.maximize();
|
||||
@ -89,15 +179,15 @@ export class RdDTMRDialog extends Dialog {
|
||||
|
||||
forceTMRContinueAction() {
|
||||
ui.notifications.warn('Vous devez finir votre action avant de continuer dans les TMR');
|
||||
this.subdialog.bringToTop();
|
||||
if (this.subdialog?.bringToTop) {
|
||||
this.subdialog.bringToTop();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
setTMRPendingAction(dialog) {
|
||||
this.subdialog = dialog
|
||||
if (dialog instanceof Application) {
|
||||
dialog.bringToTop();
|
||||
}
|
||||
this.forceTMRDisplay()
|
||||
}
|
||||
|
||||
isDemiReveCache() {
|
||||
@ -129,8 +219,8 @@ export class RdDTMRDialog extends Dialog {
|
||||
/* -------------------------------------------- */
|
||||
createPixiSprites() {
|
||||
this.pixiTMR.setup()
|
||||
this.updateTokens();
|
||||
this.forceDemiRevePositionView();
|
||||
this.updateTokens()
|
||||
this.forceDemiRevePositionView()
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
@ -207,43 +297,6 @@ export class RdDTMRDialog extends Dialog {
|
||||
this.checkQuitterTMR();
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async activateListeners(html) {
|
||||
super.activateListeners(html);
|
||||
this.html = html;
|
||||
|
||||
document.getElementsByClassName("tmr-row")
|
||||
.item(0)
|
||||
.insertCell(0)
|
||||
.append(this.pixiTMR.view);
|
||||
|
||||
if (this.viewOnly) {
|
||||
this.html.find('.lancer-sort').remove();
|
||||
this.html.find('.lire-signe-draconique').remove();
|
||||
return;
|
||||
}
|
||||
|
||||
HtmlUtility.showControlWhen(this.html.find(".appliquerFatigue"), ReglesOptionnelles.isUsing("appliquer-fatigue"));
|
||||
HtmlUtility.showControlWhen(this.html.find(".lire-signe-draconique"), this.actor.isResonanceSigneDraconique(this._getCoordActor()));
|
||||
|
||||
this.html.find('tr.tmr-row *').click(event => this.subdialog?.bringToTop());
|
||||
|
||||
// Roll Sort
|
||||
this.html.find('.lancer-sort').click(event => this.actor.rollUnSort(this._getCoordActor()));
|
||||
this.html.find('.lire-signe-draconique').click(event => this.actor.rollLireSigneDraconique(this._getCoordActor()));
|
||||
|
||||
this.html.find('img.tmr-move').click(event => this.deplacementTMR(this.html.find(event.currentTarget)?.data('move')));
|
||||
|
||||
// Gestion du cout de montée en points de rêve
|
||||
await this.actor.reveActuelIncDec(this.calculCoutMonteeTMR());
|
||||
this.cumulFatigue += this.fatigueParCase;
|
||||
|
||||
// Le reste...
|
||||
this.updateValuesDisplay();
|
||||
let tmr = TMRUtility.getTMR(this._getCoordActor());
|
||||
await this.manageRencontre(tmr);
|
||||
}
|
||||
|
||||
calculCoutMonteeTMR() {
|
||||
return ((this.tmrdata.isRapide && !EffetsDraconiques.isDeplacementAccelere(this.actor)) ? -2 : -1) - this.actor.countMonteeLaborieuse();
|
||||
}
|
||||
@ -281,11 +334,13 @@ export class RdDTMRDialog extends Dialog {
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async close() {
|
||||
|
||||
if (this.subdialog) {
|
||||
return this.forceTMRContinueAction()
|
||||
}
|
||||
|
||||
|
||||
this.descenteTMR = true;
|
||||
this.pixiTMR.close()
|
||||
if (this.actor.tmrApp) {
|
||||
this.actor.tmrApp = undefined; // Cleanup reference
|
||||
if (!this.viewOnly) {
|
||||
@ -919,19 +974,18 @@ export class RdDTMRDialog extends Dialog {
|
||||
if (this.subdialog) {
|
||||
return this.forceTMRContinueAction()
|
||||
}
|
||||
let clickOddq = TMRUtility.computeEventOddq(event);
|
||||
let currentOddq = TMRUtility.coordTMRToOddq(this._getCoordActor());
|
||||
|
||||
let targetCoord = TMRUtility.oddqToCoordTMR(clickOddq);
|
||||
let currentCoord = TMRUtility.oddqToCoordTMR(currentOddq);
|
||||
const currentCoord = this._getCoordActor()
|
||||
const currentOddq = TMRUtility.coordTMRToOddq(currentCoord)
|
||||
const targetOddq = this.pixiTMR.computeEventOddq(event)
|
||||
const targetCoord = TMRUtility.oddqToCoordTMR(targetOddq)
|
||||
|
||||
// Validation de la case de destination (gestion du cas des rencontres qui peuvent téléporter)
|
||||
let deplacementType = this._calculDeplacement(targetCoord, currentCoord, currentOddq, clickOddq);
|
||||
const typeDeplacement = this._calculDeplacement(targetCoord, currentCoord, currentOddq, targetOddq);
|
||||
|
||||
if (this.isDemiReveCache()) {
|
||||
if (this.isTerreAttache(targetCoord)
|
||||
|| this.isConnaissanceFleuve(currentCoord, targetCoord)
|
||||
|| deplacementType == 'changeur') {
|
||||
|| typeDeplacement == 'changeur') {
|
||||
// déplacement possible
|
||||
await this.actor.setTMRVisible(true);
|
||||
this.demiReve = this._tokenDemiReve();
|
||||
@ -946,11 +1000,11 @@ export class RdDTMRDialog extends Dialog {
|
||||
}
|
||||
}
|
||||
|
||||
switch (deplacementType) {
|
||||
switch (typeDeplacement) {
|
||||
case 'normal':
|
||||
case 'changeur':
|
||||
case 'passeur':
|
||||
await this._deplacerDemiReve(targetCoord, deplacementType);
|
||||
await this._deplacerDemiReve(targetCoord, typeDeplacement);
|
||||
break;
|
||||
case 'messager':
|
||||
await this._messagerDemiReve(targetCoord);
|
||||
@ -1070,7 +1124,7 @@ export class RdDTMRDialog extends Dialog {
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
_removeTokens(filter) {
|
||||
_removeTokens(filter = it => true) {
|
||||
this.allTokens.filter(filter).forEach(token => this.pixiTMR.removeToken(token))
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user