2020-07-05 21:45:25 +02:00
/ * *
* Extend the base Dialog entity by defining a custom window to perform spell .
* @ extends { Dialog }
* /
2020-07-06 09:03:21 +02:00
import { RdDUtility } from "./rdd-utility.js" ;
2020-07-17 22:04:35 +02:00
import { TMRUtility } from "./tmr-utility.js" ;
2020-11-11 04:31:17 +01:00
import { RdDRollTables } from "./rdd-rolltables.js" ;
2020-11-12 16:35:51 +01:00
import { RdDResolutionTable } from "./rdd-resolution-table.js" ;
2020-07-05 21:45:25 +02:00
2020-11-14 03:16:03 +01:00
const tmrConstants = {
col1 _y : 30 ,
col2 _y : 55 ,
cellw : 55 ,
cellh : 55 ,
gridx : 28 ,
gridy : 28
}
2020-07-05 21:45:25 +02:00
export class RdDTMRDialog extends Dialog {
2020-11-14 03:16:03 +01:00
/* -------------------------------------------- */
2020-11-14 20:46:39 +01:00
constructor ( html , actor , tmrData , viewOnly ) {
2020-11-14 03:16:03 +01:00
const dialogConf = {
title : "Terres Médianes de Rêve" ,
2020-07-05 21:45:25 +02:00
content : html ,
2020-11-14 03:16:03 +01:00
buttons : {
closeButton : { label : "Fermer" , callback : html => this . close ( html ) }
} ,
default : "closeButton"
}
const dialogOptions = {
classes : [ "tmrdialog" ] ,
width : 920 , height : 980 ,
'z-index' : 20
}
2020-07-05 21:45:25 +02:00
super ( dialogConf , dialogOptions ) ;
2020-11-14 03:16:03 +01:00
this . tmrdata = duplicate ( tmrData ) ;
2020-07-14 22:19:29 +02:00
this . actor = actor ;
2020-11-14 20:46:39 +01:00
this . viewOnly = viewOnly
this . nbFatigue = this . viewOnly ? 0 : 1 ; // 1 premier point de fatigue du à la montée
2020-07-21 23:51:24 +02:00
this . rencontresExistantes = duplicate ( this . actor . data . data . reve . rencontre . list ) ;
2020-07-26 18:44:03 +02:00
this . sortReserves = duplicate ( this . actor . data . data . reve . reserve . list ) ;
2020-11-14 03:16:03 +01:00
this . allTokens = [ ]
this . pixiApp = new PIXI . Application ( { width : 720 , height : 860 } ) ;
2020-07-14 22:19:29 +02:00
}
2020-11-14 03:16:03 +01:00
/* -------------------------------------------- */
2020-07-25 10:29:28 +02:00
close ( ) {
2020-11-14 03:16:03 +01:00
this . actor . santeIncDec ( "fatigue" , this . nbFatigue ) . then ( super . close ( ) ) ; // moving 1 cell costs 1 fatigue
2020-07-25 10:29:28 +02:00
}
2020-11-14 03:16:03 +01:00
/* -------------------------------------------- */
2020-07-26 18:44:03 +02:00
displaySortReserve ( ) {
2020-11-14 03:16:03 +01:00
console . debug ( "displaySortReserve" , this . sortReserves ) ;
for ( let sort of this . sortReserves ) {
this . _trackToken ( this . _tokenSortEnReserve ( sort ) ) ;
2020-07-26 18:44:03 +02:00
}
}
2020-11-14 03:16:03 +01:00
/* -------------------------------------------- */
2020-07-21 23:51:24 +02:00
displayPreviousRencontres ( ) {
2020-11-14 03:16:03 +01:00
console . debug ( "displayPreviousRencontres" , this . rencontresExistantes ) ;
2020-07-21 23:51:24 +02:00
for ( let rencontre of this . rencontresExistantes ) {
2020-11-14 03:16:03 +01:00
this . _trackToken ( this . _tokenRencontre ( rencontre ) ) ;
2020-07-21 23:51:24 +02:00
}
}
2020-11-14 03:16:03 +01:00
/* -------------------------------------------- */
2020-07-21 23:51:24 +02:00
updatePreviousRencontres ( ) {
2020-11-14 03:16:03 +01:00
this . _removeTokens ( t => t . rencontre != undefined ) ;
this . rencontresExistantes = duplicate ( this . actor . data . data . reve . rencontre . list ) ;
this . displayPreviousRencontres ( ) ;
2020-07-21 23:51:24 +02:00
}
2020-07-26 18:44:03 +02:00
2020-11-14 03:16:03 +01:00
/* -------------------------------------------- */
2020-07-26 18:44:03 +02:00
updateSortReserve ( ) {
2020-11-14 03:16:03 +01:00
this . _removeTokens ( t => t . sort != undefined ) ;
this . sortReserves = duplicate ( this . actor . data . data . reve . reserve . list ) ;
2020-07-26 18:44:03 +02:00
this . displaySortReserve ( ) ;
}
2020-11-14 03:16:03 +01:00
/* -------------------------------------------- */
2020-07-17 22:04:35 +02:00
async derober ( ) {
2020-11-14 03:16:03 +01:00
await this . actor . addTMRRencontre ( this . currentRencontre ) ;
2020-07-17 22:04:35 +02:00
console . log ( "-> derober" , this . currentRencontre ) ;
2020-11-14 03:16:03 +01:00
this . _tellToGM ( this . actor . name + " s'est dérobé et quitte les TMR." ) ;
2020-07-21 23:51:24 +02:00
this . close ( ) ;
2020-07-14 22:19:29 +02:00
}
2020-11-14 03:16:03 +01:00
/* -------------------------------------------- */
2020-07-14 22:19:29 +02:00
async refouler ( data ) {
2020-11-14 03:16:03 +01:00
this . _tellToGM ( this . actor . name + " a refoulé une rencontre." ) ;
await this . actor . deleteTMRRencontreAtPosition ( ) ; // Remove the stored rencontre if necessary
2020-07-17 22:04:35 +02:00
let result = await this . actor . ajouterRefoulement ( 1 ) ;
2020-07-21 23:51:24 +02:00
this . updatePreviousRencontres ( ) ;
2020-07-14 22:19:29 +02:00
console . log ( "-> refouler" , this . currentRencontre )
2020-07-17 22:04:35 +02:00
this . updateValuesDisplay ( ) ;
2020-07-14 22:19:29 +02:00
}
2020-11-14 03:16:03 +01:00
/* -------------------------------------------- */
async maitriser ( data ) {
this . actor . deleteTMRRencontreAtPosition ( ) ; // Remove the stored rencontre if necessary
2020-07-21 23:51:24 +02:00
this . updatePreviousRencontres ( ) ;
2020-11-14 03:16:03 +01:00
2020-11-12 16:35:51 +01:00
const draconic = this . actor . getBestDraconic ( ) ;
2020-11-16 04:01:36 +01:00
const carac = this . actor . getReveActuel ( ) ;
2020-11-14 03:16:03 +01:00
// TODO: ajouter l'état général?
const etatGeneral = this . actor . data . data . compteurs . etat . value
2020-11-12 16:35:51 +01:00
const difficulte = draconic . data . niveau - this . currentRencontre . force ;
2020-07-21 23:51:24 +02:00
console . log ( "Maitriser" , carac , draconic . data . niveau , this . currentRencontre . force ) ;
2020-11-12 16:35:51 +01:00
2020-11-14 03:16:03 +01:00
let rolled = RdDResolutionTable . roll ( carac , difficulte ) ;
let message = "<br><strong>Test : Rêve actuel / " + draconic . name + " / " + this . currentRencontre . name + "</strong>" + "<br>"
2020-11-16 04:31:53 +01:00
+ RdDResolutionTable . explain ( rolled ) ;
2020-11-14 03:16:03 +01:00
if ( rolled . isEchec ) {
2020-11-16 04:31:53 +01:00
TMRUtility . processRencontreEchec ( this . actor , this . currentRencontre , rolled ) ;
2020-11-14 03:16:03 +01:00
this . _tellToUser ( "Vous avez <strong>échoué</strong> à maîtriser un " + this . currentRencontre . name + " de force " + this . currentRencontre . force
2020-11-16 04:31:53 +01:00
+ "<br>Vous quittez brutalement les Terres Médianes !" + message ) ;
2020-11-14 03:16:03 +01:00
this . close ( ) ;
2020-07-17 22:04:35 +02:00
} else {
2020-11-16 04:31:53 +01:00
TMRUtility . processRencontreReussite ( this . actor , this . currentRencontre , rolled ) ;
2020-11-14 03:16:03 +01:00
this . _tellToUser ( "Vous avez <strong>réussi</strong> à maîtriser un " + this . currentRencontre . name + " de force " + this . currentRencontre . force + message ) ;
2020-07-17 22:04:35 +02:00
}
console . log ( "-> matriser" , this . currentRencontre ) ;
this . updateValuesDisplay ( ) ;
2020-07-14 22:19:29 +02:00
}
2020-11-12 23:35:29 +01:00
2020-11-14 03:16:03 +01:00
_tellToUser ( message ) {
ChatMessage . create ( { title : "TMR" , content : message , user : game . user . _id , whisper : ChatMessage . getWhisperRecipients ( "GM" ) } ) ;
}
/* -------------------------------------------- */
async manageRencontre ( coordTMR , cellDescr ) {
2020-11-14 20:46:39 +01:00
if ( this . viewOnly ) {
return ;
}
2020-11-14 03:16:03 +01:00
this . currentRencontre = undefined ;
2020-11-12 23:35:29 +01:00
let rencontre = this . rencontresExistantes . find ( prev => prev . coord == coordTMR ) ;
2020-11-14 03:16:03 +01:00
let deRencontre = new Roll ( "d7" ) . roll ( ) ;
console . log ( "manageRencontre" , deRencontre , rencontre ) ;
if ( rencontre == undefined ) {
if ( deRencontre . total == 7 ) {
2020-11-16 04:31:53 +01:00
rencontre = await TMRUtility . rencontreTMRRoll ( coordTMR , cellDescr ) ;
2020-11-14 03:16:03 +01:00
}
2020-07-14 22:19:29 +02:00
}
2020-11-12 23:35:29 +01:00
2020-07-14 22:19:29 +02:00
if ( rencontre ) { // Manages it
2020-11-14 03:16:03 +01:00
console . log ( "manageRencontre" , rencontre )
2020-07-21 23:51:24 +02:00
this . currentRencontre = duplicate ( rencontre ) ;
2020-11-16 04:01:36 +01:00
2020-11-14 03:16:03 +01:00
let dialog = new Dialog ( {
title : "Rencontre en TMR!" ,
content : "Vous recontrez un " + rencontre . name + " de force " + rencontre . force + "<br>" ,
buttons : {
derober : { icon : '<i class="fas fa-check"></i>' , label : "Se dérober" , callback : ( ) => this . derober ( ) } ,
refouler : { icon : '<i class="fas fa-check"></i>' , label : "Refouler" , callback : ( ) => this . refouler ( ) } ,
maitiser : { icon : '<i class="fas fa-check"></i>' , label : "Maîtriser" , callback : ( ) => this . maitriser ( ) }
} ,
default : "derober"
} ) ;
2020-11-12 23:35:29 +01:00
dialog . render ( true ) ;
2020-07-14 22:19:29 +02:00
}
}
2020-11-14 03:16:03 +01:00
/* -------------------------------------------- */
performRoll ( html ) {
2020-11-14 20:46:39 +01:00
if ( this . viewOnly ) {
return ;
}
2020-11-14 03:16:03 +01:00
this . actor . performRoll ( this . rollData ) ;
2020-07-05 21:45:25 +02:00
}
2020-11-14 03:16:03 +01:00
/* -------------------------------------------- */
2020-07-17 22:04:35 +02:00
updateValuesDisplay ( ) {
let ptsreve = document . getElementById ( "pointsreve-value" ) ;
ptsreve . innerHTML = this . actor . data . data . reve . reve . value ;
2020-11-14 03:16:03 +01:00
2020-07-17 22:04:35 +02:00
let tmrpos = document . getElementById ( "tmr-pos" ) ;
2020-11-14 03:16:03 +01:00
let tmr = TMRUtility . getTMRDescription ( this . actor . data . data . reve . tmrpos . coord ) ;
console . log ( "updateValuesDisplay" , this . actor . data . data . reve . tmrpos , tmr ) ;
tmrpos . innerHTML = this . actor . data . data . reve . tmrpos . coord + " (" + tmr . label + ")" ;
2020-07-17 22:04:35 +02:00
let etat = document . getElementById ( "etatgeneral-value" ) ;
etat . innerHTML = this . actor . data . data . compteurs . etat . value ;
let refoulement = document . getElementById ( "refoulement-value" ) ;
refoulement . innerHTML = this . actor . data . data . reve . refoulement . value ;
2020-11-14 03:16:03 +01:00
2020-07-17 22:04:35 +02:00
let fatigueItem = document . getElementById ( "fatigue-table" ) ;
2020-11-14 03:16:03 +01:00
fatigueItem . innerHTML = "<table class='table-fatigue'>" + RdDUtility . makeHTMLfatigueMatrix ( this . actor . data . data . sante . fatigue . value , this . actor . data . data . sante . endurance . max ) . html ( ) + "</table>" ;
2020-07-17 22:04:35 +02:00
}
2020-11-14 03:16:03 +01:00
/* -------------------------------------------- */
2020-07-17 22:04:35 +02:00
manageCaseHumideResult ( ) {
2020-11-14 03:16:03 +01:00
if ( this . toclose )
2020-07-17 22:04:35 +02:00
this . close ( ) ;
}
2020-11-12 16:35:51 +01:00
/* -------------------------------------------- */
async manageCaseHumide ( cellDescr ) {
2020-11-14 20:46:39 +01:00
if ( this . viewOnly ) {
return ;
}
2020-11-12 16:35:51 +01:00
if ( cellDescr . type == "lac" || cellDescr . type == "fleuve" || cellDescr . type == "marais" ) {
2020-07-17 22:04:35 +02:00
let draconic = this . actor . getBestDraconic ( ) ;
2020-11-14 03:16:03 +01:00
2020-11-16 04:01:36 +01:00
let carac = this . actor . getReveActuel ( ) ;
2020-11-14 03:16:03 +01:00
// TODO: ajouter l'état général?
const etatGeneral = this . actor . data . data . compteurs . etat . value
let difficulte = draconic . data . niveau - 7 ;
let rolled = RdDResolutionTable . roll ( carac , difficulte ) ;
2020-11-12 16:35:51 +01:00
2020-11-13 15:40:53 +01:00
console . log ( "manageCaseHumide >>" , rolled ) ;
2020-11-12 16:35:51 +01:00
2020-11-14 03:16:03 +01:00
let explication = "" ;
2020-11-13 15:40:53 +01:00
this . toclose = rolled . isEchec ;
if ( rolled . isEchec ) {
2020-11-14 03:16:03 +01:00
explication += "Vous êtes entré sur une case humide, et vous avez <strong>raté</strong> votre maîtrise ! Vous <strong>quittez les Terres Médianes</strong> !"
2020-11-12 16:35:51 +01:00
}
else {
2020-11-14 03:16:03 +01:00
explication += "Vous êtes entré sur une case humide, et vous avez <strong>réussi</strong> votre maîtrise !"
2020-11-12 16:35:51 +01:00
}
2020-11-14 03:16:03 +01:00
explication += "<br><strong>Test : Rêve actuel / " + draconic . name + " / " + cellDescr . type + "</strong>"
2020-11-16 04:32:42 +01:00
+ RdDResolutionTable . explain ( rolled ) ;
2020-11-12 16:35:51 +01:00
if ( rolled . isETotal ) {
2020-11-14 03:16:03 +01:00
let souffle = RdDRollTables . getSouffle ( ) ;
explication += "<br>Vous avez fait un Echec Total. Vous subissez un Souffle de Dragon : " + souffle . name ;
2020-11-12 16:35:51 +01:00
this . actor . createOwnedItem ( souffle ) ;
}
if ( rolled . isPart ) {
2020-11-14 03:16:03 +01:00
explication += "<br>Vous avez fait une Réussite Particulière" ;
explication += RdDResolutionTable . buildXpMessage ( rolled , difficulte )
2020-11-12 16:35:51 +01:00
}
let humideDiag = new Dialog ( {
title : "Case humide" ,
2020-11-14 03:16:03 +01:00
content : explication ,
2020-11-12 16:35:51 +01:00
buttons : {
2020-11-14 03:16:03 +01:00
choice : { icon : '<i class="fas fa-check"></i>' , label : "Fermer" , callback : ( ) => this . manageCaseHumideResult ( ) }
2020-07-25 10:29:28 +02:00
}
2020-07-17 22:04:35 +02:00
}
2020-11-12 16:35:51 +01:00
) ;
2020-07-17 22:04:35 +02:00
humideDiag . render ( true ) ;
}
}
2020-11-14 03:16:03 +01:00
/* -------------------------------------------- */
async declencheSortEnReserve ( coordTMR ) {
2020-11-14 20:46:39 +01:00
if ( this . viewOnly ) {
return ;
}
2020-11-14 03:16:03 +01:00
let sortReserve = this . sortReserves . find ( it => it . coord == coordTMR )
if ( sortReserve != undefined ) {
await this . actor . deleteSortReserve ( sortReserve . coord ) ;
this . updateSortReserve ( ) ;
console . log ( "declencheSortEnReserve" , sortReserve )
const declenchementSort = "Vous avez déclenché le sort <strong>" + sortReserve . sort . name
+ "</strong> en réserve en " + sortReserve . coord + " (" + TMRUtility . getTMRDescription ( sortReserve . coord ) . label
+ ") avec " + sortReserve . sort . ptreve _reel + " points de Rêve" ;
this . _tellToUser ( declenchementSort ) ;
this . close ( ) ;
2020-07-26 18:44:03 +02:00
}
}
2020-11-14 03:16:03 +01:00
/* -------------------------------------------- */
async deplacerDemiReve ( event ) {
2020-11-14 20:46:39 +01:00
if ( this . viewOnly ) {
return ;
}
2020-07-14 22:19:29 +02:00
let origEvent = event . data . originalEvent ;
let myself = event . target . tmrObject ;
2020-11-14 03:16:03 +01:00
let eventCoord = RdDTMRDialog . _computeEventCoord ( origEvent ) ;
let cellx = eventCoord . cellx ;
let celly = eventCoord . celly ;
console . log ( "deplacerDemiReve >>>>" , cellx , celly ) ;
2020-07-17 22:04:35 +02:00
let currentPos = TMRUtility . convertToCellCoord ( myself . actor . data . data . reve . tmrpos . coord ) ;
2020-11-14 03:16:03 +01:00
if ( RdDTMRDialog . _horsDePortee ( currentPos , cellx , celly ) ) {
ui . notifications . error ( "Vous ne pouvez vous déplacer que sur des cases adjacentes à votre position" ) ;
2020-07-14 22:19:29 +02:00
} else {
2020-11-14 03:16:03 +01:00
let coordTMR = TMRUtility . convertToTMRCoord ( cellx , celly ) ;
let cellDescr = TMRUtility . getTMRDescription ( coordTMR ) ;
console . log ( "deplacerDemiReve: TMR column is" , coordTMR , cellx , celly , cellDescr , this ) ;
2020-07-14 22:19:29 +02:00
let tmrPos = duplicate ( myself . actor . data . data . reve . tmrpos ) ;
tmrPos . coord = coordTMR ;
2020-11-14 03:16:03 +01:00
await myself . actor . update ( { "data.reve.tmrpos" : tmrPos } ) ;
myself . _updateDemiReve ( myself ) ;
2020-07-25 10:29:28 +02:00
myself . nbFatigue += 1 ;
2020-11-14 03:16:03 +01:00
myself . updateValuesDisplay ( ) ;
myself . manageRencontre ( coordTMR , cellDescr ) ;
myself . manageCaseHumide ( cellDescr ) ;
await myself . declencheSortEnReserve ( coordTMR ) ;
2020-07-14 22:19:29 +02:00
}
2020-07-05 22:35:18 +02:00
}
2020-11-14 03:16:03 +01:00
/* -------------------------------------------- */
async activateListeners ( html ) {
2020-07-05 21:45:25 +02:00
super . activateListeners ( html ) ;
2020-11-14 03:16:03 +01:00
2020-07-14 22:19:29 +02:00
var row = document . getElementById ( "tmrrow1" ) ;
var cell1 = row . insertCell ( 1 ) ;
2020-11-14 03:16:03 +01:00
cell1 . append ( this . pixiApp . view ) ;
2020-11-14 20:46:39 +01:00
if ( this . viewOnly ) {
html . find ( '#lancer-sort' ) . remove ( ) ;
}
else {
// Roll Sort
html . find ( '#lancer-sort' ) . click ( ( event ) => {
this . actor . rollUnSort ( this . actor . data . data . reve . tmrpos . coord ) ;
} ) ;
}
2020-11-14 03:16:03 +01:00
2020-07-14 22:19:29 +02:00
// load the texture we need
2020-11-14 03:16:03 +01:00
await this . pixiApp . loader
. add ( 'tmr' , 'systems/foundryvtt-reve-de-dragon/styles/ui/tmp_main_r1.webp' )
. add ( 'demi-reve' , "icons/svg/sun.svg" )
. load ( ( loader , resources ) => {
// This creates a texture from a TMR image
const mytmr = new PIXI . Sprite ( resources . tmr . texture ) ;
// Setup the position of the TMR
mytmr . x = 0 ;
mytmr . y = 0 ;
mytmr . width = 720 ;
mytmr . height = 860 ;
// Rotate around the center
mytmr . anchor . x = 0 ;
mytmr . anchor . y = 0 ;
mytmr . interactive = true ;
mytmr . buttonMode = true ;
mytmr . tmrObject = this ;
2020-11-14 20:46:39 +01:00
if ( ! this . viewOnly ) {
mytmr . on ( 'pointerdown' , this . deplacerDemiReve ) ;
}
2020-11-14 03:16:03 +01:00
this . pixiApp . stage . addChild ( mytmr ) ;
this . _addDemiReve ( ) ;
this . displayPreviousRencontres ( ) ;
this . displaySortReserve ( ) ;
} ) ;
2020-11-14 20:46:39 +01:00
if ( this . viewOnly ) {
return ;
}
2020-11-14 03:16:03 +01:00
await this . actor . updatePointsDeReve ( ( this . tmrdata . isRapide ) ? - 2 : - 1 ) ; // 1 point defatigue
2020-07-17 22:04:35 +02:00
this . updateValuesDisplay ( ) ;
let cellDescr = TMRUtility . getTMRDescription ( this . actor . data . data . reve . tmrpos . coord ) ;
2020-11-14 03:16:03 +01:00
this . manageRencontre ( this . actor . data . data . reve . tmrpos . coord , cellDescr ) ;
this . manageCaseHumide ( cellDescr ) ;
}
/* -------------------------------------------- */
static _computeEventCoord ( origEvent ) {
let canvasRect = origEvent . target . getBoundingClientRect ( ) ;
let x = origEvent . clientX - canvasRect . left ;
let y = origEvent . clientY - canvasRect . top ;
let cellx = Math . floor ( x / tmrConstants . cellw ) ; // [From 0 -> 12]
y -= ( cellx % 2 == 0 ) ? tmrConstants . col1 _y : tmrConstants . col2 _y ;
let celly = Math . floor ( y / tmrConstants . cellh ) ; // [From 0 -> 14]
return { cellx , celly } ;
}
static _horsDePortee ( pos , cellx , celly ) {
return Math . abs ( cellx - pos . x ) > 1
|| Math . abs ( celly - pos . y ) > 1
|| ( pos . y == 0 && celly > pos . y && cellx != pos . x && pos . x % 2 == 0 )
|| ( celly == 0 && celly < pos . y && cellx != pos . x && pos . x % 2 == 1 ) ;
}
_tokenRencontre ( rencontre ) {
let sprite = new PIXI . Graphics ( ) ;
sprite . beginFill ( 0x767610 , 0.6 ) ;
sprite . drawCircle ( 0 , 0 , 6 ) ;
sprite . endFill ( ) ;
sprite . decallage = {
x : ( tmrConstants . cellw / 2 ) - 16 ,
y : 16 - ( tmrConstants . cellh / 2 )
} ;
return { sprite : sprite , rencontre : rencontre , coordTMR : ( ) => rencontre . coord } ;
}
_tokenSortEnReserve ( sort ) {
let sprite = new PIXI . Graphics ( ) ;
sprite . beginFill ( 0x101010 , 0.8 ) ;
sprite . drawCircle ( 0 , 0 , 6 ) ;
sprite . endFill ( ) ;
sprite . decallage = {
x : 16 - ( tmrConstants . cellw / 2 ) ,
y : 16 - ( tmrConstants . cellh / 2 )
}
2020-11-14 20:46:39 +01:00
return { sprite : sprite , sort : sort , coordTMR : ( ) => sort . coord }
2020-11-14 03:16:03 +01:00
}
_tokenDemiReve ( ) {
let texture = PIXI . utils . TextureCache [ 'demi-reve' ] ;
let sprite = new PIXI . Sprite ( texture ) ;
sprite . width = tmrConstants . cellw * 0.7 ;
sprite . height = tmrConstants . cellh * 0.7 ;
sprite . anchor . set ( 0.5 ) ;
sprite . tint = 0x00FFEE ;
return { sprite : sprite , actor : this . actor , coordTMR : ( ) => this . actor . data . data . reve . tmrpos . coord }
}
/* -------------------------------------------- */
_addDemiReve ( ) {
this . demiReve = this . _tokenDemiReve ( ) ;
this . _setTokenPosition ( this . demiReve ) ;
this . pixiApp . stage . addChild ( this . demiReve . sprite ) ;
}
_updateDemiReve ( myself ) {
myself . _setTokenPosition ( myself . demiReve ) ;
}
_setTokenPosition ( token ) {
let coordXY = TMRUtility . convertToCellCoord ( token . coordTMR ( ) ) ;
let decallagePairImpair = ( coordXY . x % 2 == 0 ) ? tmrConstants . col1 _y : tmrConstants . col2 _y ;
let dx = ( token . sprite . decallage == undefined ) ? 0 : token . sprite . decallage . x ;
let dy = ( token . sprite . decallage == undefined ) ? 0 : token . sprite . decallage . y ;
token . sprite . x = tmrConstants . gridx + ( coordXY . x * tmrConstants . cellw ) + dx ;
token . sprite . y = tmrConstants . gridy + ( coordXY . y * tmrConstants . cellh ) + dy + decallagePairImpair ;
}
_removeTokens ( filter ) {
const tokensToRemove = this . allTokens . filter ( filter ) ;
for ( let token of tokensToRemove ) {
this . pixiApp . stage . removeChild ( token . sprite ) ;
}
}
_trackToken ( token ) {
this . allTokens . push ( token )
this . _setTokenPosition ( token ) ;
this . pixiApp . stage . addChild ( token . sprite ) ;
2020-07-05 21:45:25 +02:00
}
}
2020-11-14 03:16:03 +01:00