Afficher la fatigue avec les compteurs

This commit is contained in:
Vincent Vandemeulebrouck 2020-11-18 20:16:59 +01:00
parent da9fe2f1bb
commit 519f9e89b4
6 changed files with 94 additions and 32 deletions

View File

@ -106,7 +106,11 @@ export class RdDActorSheet extends ActorSheet {
data.difficultesLibres = CONFIG.RDD.difficultesLibres;
// low is normal, this the base used to compute the grid.
data.data.fatigueHTML = "<table class='table-fatigue'>" + RdDUtility.makeHTMLfatigueMatrix( data.data.sante.fatigue.value, data.data.sante.endurance.max ).html() + "</table>";
data.data.fatigue = {
malus: RdDUtility.calculMalusFatigue(data.data.sante.fatigue.value, data.data.sante.endurance.max),
html: "<table class='table-fatigue'>" + RdDUtility.makeHTMLfatigueMatrix( data.data.sante.fatigue.value, data.data.sante.endurance.max ).html() + "</table>"
}
RdDUtility.filterItemsPerTypeForSheet(data );
data.data.sortReserve = data.data.reve.reserve.list;

View File

@ -998,7 +998,10 @@ export class RdDActor extends Actor {
}
let data = {
fatigueHTML:"<table class='table-fatigue'>" + RdDUtility.makeHTMLfatigueMatrix( this.data.data.sante.fatigue.value, this.data.data.sante.endurance.max ).html() + "</table>",
fatigue: {
malus: RdDUtility.calculMalusFatigue(this.data.data.sante.fatigue.value, this.data.data.sante.endurance.max),
html: "<table class='table-fatigue'>" + RdDUtility.makeHTMLfatigueMatrix( this.data.data.sante.fatigue.value, this.data.data.sante.endurance.max ).html() + "</table>"
},
draconic: this.getDraconicList(),
sort: this.getSortList(),
caracReve: this.data.data.carac.reve.value,

View File

@ -31,18 +31,33 @@ const ajustementsConditions = [-10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, +1,
function _buildAllSegmentsFatigue(max) {
const cycle = [5, 2, 4, 1, 3, 0];
let fatigue = [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]];
for (let i = 0; i <= 40; i++) {
for (let i = 0; i <= max; i++) {
const ligneFatigue= duplicate(fatigue[i]);
const caseIncrementee = cycle[i % 6];
ligneFatigue[caseIncrementee]++;
ligneFatigue[caseIncrementee + 6]++;
ligneFatigue.fatigueMax = 2 * (i + 1);
fatigue[i + 1] = ligneFatigue ;
}
return fatigue;
}
function _cumulSegmentsFatigue(matrix) {
let cumulMatrix = [];
for (let line of matrix)
{
let cumul = duplicate(line);
for (let i = 1; i < 12; i++) {
cumul[i] += cumul[i - 1];
}
cumulMatrix.push(cumul);
}
return cumulMatrix;
}
const fatigueMatrix = _buildAllSegmentsFatigue(30);
const cumulFatigueMatrix = _cumulSegmentsFatigue(fatigueMatrix);
const fatigueMalus = [ 0, 0, 0, -1, -1, -1, -2, -3, -4, -5, -6, -7 ]; // Provides the malus for each segment of fatigue
const fatigueLineSize = [ 3, 6, 7, 8, 9, 10, 11, 12];
@ -372,20 +387,24 @@ export class RdDUtility {
data.compteurs.chance.max = data.carac.chance.value;
}
static getSegmentsFatigue(endurance) {
endurance = Math.max(endurance, 1);
endurance = Math.min(endurance, fatigueMatrix.length);
return fatigueMatrix[endurance];
static getSegmentsFatigue(maxEnd) {
maxEnd = Math.max(maxEnd, 1);
maxEnd = Math.min(maxEnd, fatigueMatrix.length);
return fatigueMatrix[maxEnd];
}
static cumulSegments(segments) {
let cumuls = [segments[0]];
for (let i = 1; i < 12; i++) {
cumuls[i] = segments[i] + cumuls[i - 1];
static calculMalusFatigue(fatigue, maxEnd)
{
maxEnd = Math.max(maxEnd, 1);
maxEnd = Math.min(maxEnd, cumulFatigueMatrix.length);
let segments = cumulFatigueMatrix[maxEnd];
for (let i=0; i<12; i++) {
if (fatigue <= segments[i]) {
return fatigueMalus[i]
}
return cumuls;
}
return -7;
}
/* -------------------------------------------- */
// Build the nice (?) html table used to manage fatigue.
// max should be the endurance max value

View File

@ -871,3 +871,34 @@ background: rgba(0, 0, 0, 0.5);
position: relative;
bottom: 6px;
}
/* Tooltip container */
.tooltip {
position: relative;
display: inline-block;
border-bottom: 1px dotted black; /* If you want dots under the hoverable text */
}
/* Tooltip text */
.tooltip .tooltiptext {
visibility: hidden;
width: 360px;
text-align: center;
padding: 5px 0;
border-radius: 6px;
/* Position the tooltip text */
position: absolute;
z-index: 1;
left: -100%;
/* Fade in tooltip */
opacity: 0;
transition: opacity 0.3s;
}
/* Show the tooltip text when you mouse over the tooltip container */
.tooltip:hover .tooltiptext {
visibility: visible;
opacity: 1;
}

View File

@ -17,6 +17,10 @@
<span>Endurance <a id="endurance-plus">+</a> / <a id="endurance-moins">-</a></span>
<input class="resource-content" type="text" name="data.sante.endurance.value" value="{{data.sante.endurance.value}}" data-dtype="Number"/>/{{data.sante.endurance.max}}
</div>
<div>
<span>Fatigue <a id="fatigue-plus">+</a> / <a id="fatigue-moins">-</a></span>
<input class="resource-content" id="fatigue-value" type="text" name="data.sante.fatigue.value" value="{{data.sante.fatigue.value}}" data-dtype="Number" />/{{data.sante.fatigue.max}}
</div>
<div>
<span>Sonné :</span>
<input class="resource-content" type="checkbox" name="data.sante.sonne.value" value="{{data.sante.sonne.value}}" {{#if data.sante.sonne.value}}checked{{/if}} />
@ -27,8 +31,9 @@
</div>
</div>
<div class="flex-group-center flex-fatigue">
Fatigue <a id="fatigue-plus">+</a> / <a id="fatigue-moins">-</a>
<span>{{{data.fatigueHTML}}}</span>
<div class="tooltip">Malus de fatigue : {{data.fatigue.malus}}
<span class="tooltiptext">{{{data.fatigue.html}}}</span>
</div>
</div>
</div>
<div class="flexrow flex-wound">

View File

@ -25,7 +25,7 @@
</div>
<div class="flex-group-center flex-fatigue">
Fatigue
<span id="fatigue-table">{{{fatigueHTML}}}</span>
<span id="fatigue-table">{{{fatigue.html}}}</span>
</div>
</td>
</tr>