Merge branch 'working' into 'master'

Afficher la fatigue avec les compteurs

See merge request LeRatierBretonnien/foundryvtt-reve-de-dragon!24
This commit is contained in:
Leratier Bretonnien 2020-11-18 22:48:07 +00:00
commit 1f855fbb44
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

@ -8,27 +8,32 @@
<h1 class="charname"><input name="name" type="text" value="{{actor.name}}" placeholder="Name"/></h1>
</div>
<div class="flexrow">
<div class="flex-group-center flex-hp">
<div>
<span>Vie <a id="vie-plus">+</a> / <a id="vie-moins">-</a></span>
<input class="resource-content" type="text" name="data.sante.vie.value" value="{{data.sante.vie.value}}" data-dtype="Number"/>/{{data.sante.vie.max}}
</div>
<div>
<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>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}} />
</div>
<div>
<div class="flex-group-center flex-hp">
<div>
<span>Vie <a id="vie-plus">+</a> / <a id="vie-moins">-</a></span>
<input class="resource-content" type="text" name="data.sante.vie.value" value="{{data.sante.vie.value}}" data-dtype="Number"/>/{{data.sante.vie.max}}
</div>
<div>
<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}} />
</div>
<div>
<span><span class="ptreve-actuel"><a>Rêve</a></span> <a id="ptreve-actuel-plus">+</a> / <a id="ptreve-actuel-moins">-</a></span>
<input class="resource-content" id="pointsreve-value" type="text" name="data.reve.reve.value" value="{{data.reve.reve.value}}" data-dtype="Number" />/{{data.reve.seuil.value}}
</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>
<div class="flex-group-center flex-fatigue">
<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>