Gestion correcte de l'editeur de blessures

This commit is contained in:
sladecraven 2020-07-27 16:27:41 +02:00
parent c1a6ee1e92
commit 77f5fe0a21
6 changed files with 161 additions and 92 deletions

View File

@ -12,8 +12,8 @@ export class RdDActorSheet extends ActorSheet {
return mergeObject(super.defaultOptions, { return mergeObject(super.defaultOptions, {
classes: ["rdd", "sheet", "actor"], classes: ["rdd", "sheet", "actor"],
template: "systems/foundryvtt-reve-de-dragon/templates/actor-sheet.html", template: "systems/foundryvtt-reve-de-dragon/templates/actor-sheet.html",
width: 600, width: 640,
height: 600, height: 720,
tabs: [{navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "description"}], tabs: [{navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "description"}],
dragDrop: [{dragSelector: ".item-list .item", dropSelector: null}] dragDrop: [{dragSelector: ".item-list .item", dropSelector: null}]
}); });
@ -80,9 +80,9 @@ export class RdDActorSheet extends ActorSheet {
} }
data.data.carac.taille.isTaille = true; // To avoid button link; data.data.carac.taille.isTaille = true; // To avoid button link;
data.data.nbLegeres = RdDUtility.computeNbBlessures(data.data.blessures, "legeres" ); data.data.nbLegeres = this.actor.GetNumberBlessures(data.data.blessures.legeres.liste );
data.data.nbGraves = RdDUtility.computeNbBlessures(data.data.blessures, "graves" ); data.data.nbGraves = this.actor.GetNumberBlessures(data.data.blessures.graves.liste );
data.data.nbCritiques = RdDUtility.computeNbBlessures(data.data.blessures, "critiques" ); data.data.nbCritiques = this.actor.GetNumberBlessures(data.data.blessures.critiques.liste );
// low is normal, this the base used to compute the grid. // 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.fatigueHTML = "<table class='table-fatigue'>" + RdDUtility.makeHTMLfatigueMatrix( data.data.sante.fatigue.value, data.data.sante.endurance.max ).html() + "</table>";
@ -98,8 +98,6 @@ export class RdDActorSheet extends ActorSheet {
data.data.ombres = this._checkNull(data.itemsByType['ombre']); data.data.ombres = this._checkNull(data.itemsByType['ombre']);
data.data.tetes = this._checkNull(data.itemsByType['tete']); data.data.tetes = this._checkNull(data.itemsByType['tete']);
data.data.competenceByCategory = data.competenceByCategory; data.data.competenceByCategory = data.competenceByCategory;
//data.data.armes = data.itemsByType.arme;
//console.log(">>>>> data update");
return data; return data;
} }
@ -127,12 +125,27 @@ export class RdDActorSheet extends ActorSheet {
li.slideUp(200, () => this.render(false)); li.slideUp(200, () => this.render(false));
}); });
// Equip Inventory Item // Blessure control
html.find('.blessure-legere-control').click(ev => { html.find('.blessure-control').click(ev => {
let index = event.currentTarget.attributes['data-blessure-index'].value; const li = $(ev.currentTarget).parents(".item");
let active = event.currentTarget.attributes['data-blessure-active'].value; let btype = li.data("blessure-type");
this.actor.manageBlessureLegere(index, active); let index = li.data('blessure-index');
this.render(true); let active = $(ev.currentTarget).data('blessure-active');
//console.log(btype, index, active);
this.actor.manageBlessureFromSheet(btype, index, active).then( this.render(true) );
});
// Blessure data
html.find('.blessures-soins').change(ev => {
const li = $(ev.currentTarget).parents(".item");
let btype = li.data('blessure-type');
let index = li.data('blessure-index');
let psoins = li.find('input[name=premiers_soins]').val();
let pcomplets = li.find('input[name=soins_complets]').val();
let jours = li.find('input[name=jours]').val();
let loc = li.find('input[name=localisation]').val();
//console.log(btype, index, psoins, pcomplets, jours, loc);
this.actor.setDataBlessureFromSheet(btype, index, psoins, pcomplets, jours, loc).then( this.render(true) );
}); });
// Equip Inventory Item // Equip Inventory Item
@ -172,7 +185,7 @@ export class RdDActorSheet extends ActorSheet {
// Display info about queue // Display info about queue
html.find('.queuesouffle-label a').click((event) => { html.find('.queuesouffle-label a').click((event) => {
let myID = event.currentTarget.attributes['data-id'].value; let myID = event.currentTarget.attributes['data-item-id'].value;
const item = this.actor.getOwnedItem(myID); const item = this.actor.getOwnedItem(myID);
item.sheet.render(true); item.sheet.render(true);
}); });

View File

@ -389,6 +389,15 @@ export class RdDActor extends Actor {
} }
} }
/* -------------------------------------------- */
GetNumberBlessures( blessuresListe )
{
let nbB = 0;
for ( let b of blessuresListe) {
nbB += ( b.active) ? 1 : 0;
}
return nbB;
}
/* -------------------------------------------- */ /* -------------------------------------------- */
async santeIncDec(name, inc ) { async santeIncDec(name, inc ) {
const sante = duplicate(this.data.data.sante); const sante = duplicate(this.data.data.sante);
@ -413,9 +422,11 @@ export class RdDActor extends Actor {
if ( data.value < 0 ) data.value = 0; // Security if ( data.value < 0 ) data.value = 0; // Security
let blessures = this.data.data.blessures; let blessures = this.data.data.blessures;
let maxEnd = Math.floor( data.max / blessures.graves.nombre); let nbGraves = this.GetNumberBlessures(blessures.graves.liste);
let nbCritiques = this.GetNumberBlessures(blessures.critiques.liste);
let maxEnd = Math.floor( data.max / nbGraves);
if (data.value > maxEnd ) data.value = maxEnd; if (data.value > maxEnd ) data.value = maxEnd;
if ( blessures.critiques.nombre > 0 && data.value > 1) data.value = 1; if ( nbCritiques > 0 && data.value > 1) data.value = 1;
if (lastValue - data.value > 1) this.testSiSonne(sante, data); // Peut-être sonné si 2 points d'endurance perdus d'un coup if (lastValue - data.value > 1) this.testSiSonne(sante, data); // Peut-être sonné si 2 points d'endurance perdus d'un coup
} }
@ -429,12 +440,29 @@ export class RdDActor extends Actor {
await this.update( {"data.sante": sante } ); await this.update( {"data.sante": sante } );
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
async manageBlessureLegere( index ) { async manageBlessureFromSheet( bType, index, active ) {
let legeres = duplicate(this.data.data.blessures.legeres); let bList = duplicate(this.data.data.blessures);
let blessure = legeres.liste[index]; let blessure = bList[bType+"s"].liste[index];
blessure.active = !blessure.active; blessure.active = !blessure.active;
console.log("Blessure update", index, blessure ); if ( !blessure.active ) {
await this.update( { "data.blessures.legeres": legeres } ); blessure.premiers_soins = 0;
blessure.soins_complets = 0;
blessure.jours = 0;
blessure.localisation = "";
}
//console.log("Blessure update", bType, index, blessure, bList );
await this.update( { 'data.blessures': bList } );
}
/* -------------------------------------------- */
async setDataBlessureFromSheet( bType, index, psoins, pcomplets, jours, loc) {
let bList = duplicate(this.data.data.blessures);
let blessure = bList[bType+"s"].liste[index];
blessure.premiers_soins = psoins;
blessure.soins_complets = pcomplets;
blessure.jours = jours;
blessure.localisation = loc;
await this.update( { 'data.blessures': bList } );
} }
/* -------------------------------------------- */ /* -------------------------------------------- */

View File

@ -365,18 +365,6 @@ export class RdDUtility {
return result; return result;
} }
/* -------------------------------------------- */
static computeNbBlessures( blessures, name)
{
let bless = blessures[name];
console.log(blessures, name, bless);
let nbBlessures = 0;
for (let k=0; k<bless.liste.length; k++) {
if (bless.liste[k].active) nbBlessures++;
}
return nbBlessures;
}
/* -------------------------------------------- */ /* -------------------------------------------- */
static currentFatigueMalus( value, max) static currentFatigueMalus( value, max)
{ {

View File

@ -17,18 +17,18 @@
--major-button-color: #dadada; --major-button-color: #dadada;
--tab-header-font-family: GoudyAcc; --tab-header-font-family: GoudyAcc;
--tab-header-font-size: 16px; --tab-header-font-size: 14px;
--tab-header-font-weight: 700; --tab-header-font-weight: 700;
--tab-header-color: #403f3e; --tab-header-color: #403f3e;
--tab-header-color-active: #4a0404; --tab-header-color-active: #4a0404;
--actor-input-font-family: GoudyAcc; --actor-input-font-family: GoudyAcc;
--actor-input-font-size: 14px; --actor-input-font-size: 12px;
--actor-input-font-weight: 500; --actor-input-font-weight: 500;
--actor-input-color: black; --actor-input-color: black;
--actor-label-font-family: GoudyAcc; --actor-label-font-family: GoudyAcc;
--actor-label-font-size: 16px; --actor-label-font-size: 12px;
--actor-label-font-weight: 700; --actor-label-font-weight: 700;
--actor-label-color: #464331c4; --actor-label-color: #464331c4;
@ -321,8 +321,18 @@ button {
flex-grow: 0; flex-grow: 0;
margin-right: 4px; margin-right: 4px;
} }
.competence-column {
flex-direction: column;
align-content: flex-start;
justify-content: flex-start;
flex-grow: 0;
flex-basis: 1;
}
.competence-header { .competence-header {
align-content: flex-start; align-content: flex-start;
justify-content: flex-start;
font-weight: bold;
flex-grow: 0;
} }
.competence-label { .competence-label {
flex-grow: 2; flex-grow: 2;
@ -339,6 +349,14 @@ button {
margin-right: 4px; margin-right: 4px;
margin-left: 4px; margin-left: 4px;
} }
.blessures-title {
font-weight: bold;
}
.blessure-data {
flex-direction: row;
align-content: flex-start;
justify-content: flex-start;
}
.blessures-soins { .blessures-soins {
flex-grow: 0; flex-grow: 0;
flex-basis: 32px; flex-basis: 32px;

View File

@ -2,7 +2,7 @@
"name": "foundryvtt-reve-de-dragon", "name": "foundryvtt-reve-de-dragon",
"title": "Rêve de Dragon", "title": "Rêve de Dragon",
"description": "L'implémentation de Rêve de Dragon pour FoundryVTT", "description": "L'implémentation de Rêve de Dragon pour FoundryVTT",
"version": "0.8.1", "version": "0.8.2",
"minimumCoreVersion": "0.6.0", "minimumCoreVersion": "0.6.0",
"compatibleCoreVersion": "0.6.2", "compatibleCoreVersion": "0.6.2",
"templateVersion": 20, "templateVersion": 20,

View File

@ -99,7 +99,7 @@
{{!-- Compétences Tab --}} {{!-- Compétences Tab --}}
<div class="tab competences" data-group="primary" data-tab="competences"> <div class="tab competences" data-group="primary" data-tab="competences">
<div class="grid grid-2col"> <div class="grid grid-2col">
<div class="flex-group-left flexcol"> <div class="flex-group-left flexcol competence-column">
<header class="competence-header flexrow"> <header class="competence-header flexrow">
<span class="competence-title">Compétences de base</span> <span class="competence-title">Compétences de base</span>
</header> </header>
@ -118,7 +118,7 @@
{{/each}} {{/each}}
</ol> </ol>
<header class="competences-header flexrow"> <header class="competence-header flexrow">
<span class="competence-title">Compétences Particulières</span> <span class="competence-title">Compétences Particulières</span>
</header> </header>
<ol class="item-list"> <ol class="item-list">
@ -135,10 +135,27 @@
</li> </li>
{{/each}} {{/each}}
</ol> </ol>
<header class="competence-header flexrow">
<span class="competence-title">Compétences Spécialisées</span>
</header>
<ol class="item-list">
{{#each data.competenceByCategory.specialisee as |comp key|}}
<li class="item flexrow" data-item-id="{{comp._id}}">
<img class="sheet-competence-img" src="{{comp.img}}"/>
<span class="competence-label" name="data.competenceByCategory.specialisee[{{key}}].name"><a>{{comp.name}}</a></span>
<input class="competence-value" type="text" name="data.competenceByCategory.specialisee[{{key}}].data.niveau" compname="{{comp.name}}" value="{{numberFormat comp.data.niveau decimals=0 sign=true}}" data-dtype="number"/>
<input class="competence-xp" type="text" name="data.competenceByCategory.specialisee[{{key}}].data.xp" compname="{{comp.name}}" value="{{comp.data.xp}}" data-dtype="number"/>
<div class="item-controls">
<a class="item-control item-edit" title="Edit Item"><i class="fas fa-edit"></i></a>
<a class="item-control item-delete" title="Delete Item"><i class="fas fa-trash"></i></a>
</div>
</li>
{{/each}}
</ol>
</div> </div>
<div class="flex-group-left flexcol"> <div class="flex-group-left flexcol competence-column">
<header class="competences-header flexrow"> <header class="competence-header flexrow">
<span class="competence-title">Compétences De Mêlée</span> <span class="competence-title">Compétences De Mêlée</span>
</header> </header>
<ol class="item-list"> <ol class="item-list">
@ -156,7 +173,7 @@
{{/each}} {{/each}}
</ol> </ol>
<header class="competences-header flexrow"> <header class="competence-header flexrow">
<span class="competence-title">Compétences De Tir</span> <span class="competence-title">Compétences De Tir</span>
</header> </header>
<ol class="item-list"> <ol class="item-list">
@ -174,7 +191,7 @@
{{/each}} {{/each}}
</ol> </ol>
<header class="competences-header flexrow"> <header class="competence-header flexrow">
<span class="competence-title">Compétences De Lancer</span> <span class="competence-title">Compétences De Lancer</span>
</header> </header>
<ol class="item-list"> <ol class="item-list">
@ -192,24 +209,6 @@
{{/each}} {{/each}}
</ol> </ol>
<header class="competences-header flexrow">
<span class="competence-title">Compétences Spécialisées</span>
</header>
<ol class="item-list">
{{#each data.competenceByCategory.specialisee as |comp key|}}
<li class="item flexrow" data-item-id="{{comp._id}}">
<img class="sheet-competence-img" src="{{comp.img}}"/>
<span class="competence-label" name="data.competenceByCategory.specialisee[{{key}}].name"><a>{{comp.name}}</a></span>
<input class="competence-value" type="text" name="data.competenceByCategory.specialisee[{{key}}].data.niveau" compname="{{comp.name}}" value="{{numberFormat comp.data.niveau decimals=0 sign=true}}" data-dtype="number"/>
<input class="competence-xp" type="text" name="data.competenceByCategory.specialisee[{{key}}].data.xp" compname="{{comp.name}}" value="{{comp.data.xp}}" data-dtype="number"/>
<div class="item-controls">
<a class="item-control item-edit" title="Edit Item"><i class="fas fa-edit"></i></a>
<a class="item-control item-delete" title="Delete Item"><i class="fas fa-trash"></i></a>
</div>
</li>
{{/each}}
</ol>
<header class="competence-header flexrow"> <header class="competence-header flexrow">
<span class="competence-title">Connaissances</span> <span class="competence-title">Connaissances</span>
</header> </header>
@ -228,7 +227,7 @@
{{/each}} {{/each}}
</ol> </ol>
<header class="competences-header flexrow"> <header class="competence-header flexrow">
<span class="competence-title">Draconic</span> <span class="competence-title">Draconic</span>
</header> </header>
<ol class="item-list"> <ol class="item-list">
@ -245,6 +244,8 @@
</li> </li>
{{/each}} {{/each}}
</ol> </ol>
<div></div>
<div></div>
</div> </div>
</div> </div>
</div> </div>
@ -270,31 +271,40 @@
{{!-- blessures Tab --}} {{!-- blessures Tab --}}
<div class="tab blessures" data-group="primary" data-tab="blessures" style="height:200px"> <div class="tab blessures" data-group="primary" data-tab="blessures" style="height:200px">
<span>Blessures Légeres :</span> <span class="blessures-title">Blessures Légeres :</span>
<div class="flexcol"> <div class="blessure-data">
{{#each data.blessures.legeres.liste as |bless key|}} {{#each data.blessures.legeres.liste as |bless key|}}
<li class="item flexrow" data-attribute={{key}}> <li class="item flexrow blessure-data" data-blessure-type="legere" data-attribute={{key}} data-blessure-index="{{key}}">
<a class="item-control blessure-legere-control" title="Blessure Légère" data-blessure-index="{{key}}" data-blessure-active="{{bless.active}}">{{#if bless.active}}<i class="fas fa-circle"></i>{{else}}<i class="fas fa-genderless"></i>{{/if}}</a> <a class="item-control blessure-control" title="Blessure Légère" data-blessure-active="{{bless.active}}">{{#if bless.active}}<i class="fas fa-circle"></i>{{else}}<i class="fas fa-genderless"></i>{{/if}}</a>
Premiers soins <input class="blessures-soins" type="text" name="data.blessures.legeres.liste[{{key}}].premiers_soins" data-dtype="number" value="{{bless.premiers_soins}}"/> - Premiers soins <input class="blessures-soins" type="text" name='premiers_soins' data-dtype="number" value="{{this.premiers_soins}}"/> -
Soins complets <input class="blessures-soins" type="text" name="data.blessures.legeres.liste[{{key}}].soins_complets" data-dtype="number" value="{{bless.soins_complets}}"/> - Soins complets <input class="blessures-soins" type="text" name='soins_complets' data-dtype="number" value="{{this.soins_complets}}"/> -
Jours <input class="blessures-soins" type="text" name="data.blessures.legeres.liste[{{key}}].jours" data-dtype="number" value="{{bless.jours}}"/> - Jours <input class="blessures-soins" type="text" name='jours' data-dtype="number" value="{{this.jours}}"/> -
Loc. <input class="blessures-loc" type="text" name="data.blessures.legeres.liste[{{key}}].localisation" data-dtype="String" value="{{bless.localisation}}"/> Loc. <input class="blessures-soins" type="text" name='localisation' data-dtype="String" value="{{this.localisation}}"/>
</li> </li>
{{/each}} {{/each}}
</div> </div>
<span>Blessures Graves :</span> <span class="blessures-title">Blessures Graves :</span>
<div> <div>
{{#each data.blessures.graves.liste as |bless key|}} {{#each data.blessures.graves.liste as |bless key|}}
<li class="item flexrow" data-attribute={{key}}> <li class="item flexrow" data-blessure-type="grave" data-attribute={{key}} data-blessure-index="{{key}}" >
<span> {{#if bless.active}}<i class="fas fa-circle"></i>{{else}}<i class="fas fa-genderless"></i>{{/if}}</a> Premiers soins : {{bless.premiers_soins}} - Soins complets : {{bless.soins_complets}} - Nombre de jours : {{bless.jours}} - Localisation : {{bless.localisation}}</span> <a class="item-control blessure-control" title="Blessure Grave" data-blessure-active="{{bless.active}}">{{#if bless.active}}<i class="fas fa-circle"></i>{{else}}<i class="fas fa-genderless"></i>{{/if}}</a>
Premiers soins <input class="blessures-soins" type="text" name="premiers_soins" data-dtype="number" value="{{bless.premiers_soins}}"/> -
Soins complets <input class="blessures-soins" type="text" name="soins_complets" data-dtype="number" value="{{bless.soins_complets}}"/> -
Jours <input class="blessures-soins" type="text" name="jours" data-dtype="number" value="{{bless.jours}}"/> -
Loc. <input class="blessures-soins" type="text" name="localisation" data-dtype="String" value="{{bless.localisation}}"/>
</li> </li>
{{/each}} {{/each}}
</div> </div>
<span>Blessure Critique :</span> <span class="blessures-title">Blessure Critique :</span>
<div> <div>
{{#each data.blessures.critiques.liste as |bless key|}} {{#each data.blessures.critiques.liste as |bless key|}}
<li class="item flexrow" data-attribute={{key}}> <li class="item flexrow" data-blessure-type="critique" data-attribute={{key}} data-blessure-index="{{key}}" >
<span> {{#if bless.active}}<i class="fas fa-circle"></i>{{else}}<i class="fas fa-genderless"></i>{{/if}}</a> Premiers soins : {{bless.premiers_soins}} - Soins complets : {{bless.soins_complets}} - Nombre de jours : {{bless.jours}} - Localisation : {{bless.localisation}}</span> <a class="item-control blessure-control" title="Blessure Critique" data-blessure-active="{{bless.active}}">{{#if bless.active}}<i class="fas fa-circle"></i>{{else}}<i class="fas fa-genderless"></i>{{/if}}</a>
Premiers soins <input class="blessures-soins" type="text" name="premiers_soins" data-dtype="number" value="{{bless.premiers_soins}}"/> -
Soins complets <input class="blessures-soins" type="text" name="soins_complets" data-dtype="number" value="{{bless.soins_complets}}"/> -
Jours <input class="blessures-soins" type="text" name="jours" data-dtype="number" value="{{bless.jours}}"/> -
Loc. <input class="blessures-soins" type="text" name="localisation" data-dtype="String" value="{{bless.localisation}}"/>
</li>
</li> </li>
{{/each}} {{/each}}
</div> </div>
@ -362,32 +372,44 @@
<div> <div>
<span><strong>Queues:</strong></span> <span><strong>Queues:</strong></span>
{{#each data.queues as |queue key|}} {{#each data.queues as |queue key|}}
<li class="item flexrow" data-attribute={{key}}> <li class="item flexrow" data-attribute={{key}} data-item-id="{{queue._id}}">
<span class="queuesouffle-label"> <a data-id="{{queue._id}}">{{queue.name}}</a></span> <span class="queuesouffle-label"> <a data-item-id="{{queue._id}}">{{queue.name}}</a></span>
<div class="item-controls">
<a class="item-control item-delete" title="Delete Item"><i class="fas fa-trash"></i></a>
</div>
</li> </li>
{{/each}} {{/each}}
</div> </div>
<div> <div>
<span><strong>Souffles:</strong></span> <span><strong>Souffles:</strong></span>
{{#each data.souffles as |souffle key|}} {{#each data.souffles as |souffle key|}}
<li class="item flexrow" data-attribute={{key}}> <li class="item flexrow" data-attribute={{key}} data-item-id="{{queue._id}}">
<span class="queuesouffle-label"> <a data-id="{{souffle._id}}">{{souffle.name}}</a></span> <span class="queuesouffle-label"> <a data-item-id="{{souffle._id}}">{{souffle.name}}</a></span>
<div class="item-controls">
<a class="item-control item-delete" title="Delete Item"><i class="fas fa-trash"></i></a>
</div>
</li> </li>
{{/each}} {{/each}}
</div> </div>
<div> <div>
<span><strong>Tetes:</strong></span> <span><strong>Tetes:</strong></span>
{{#each data.tetes as |tete key|}} {{#each data.tetes as |tete key|}}
<li class="item flexrow" data-attribute={{key}}> <li class="item flexrow" data-attribute={{key}} data-item-id="{{queue._id}}">
<span class="queuesouffle-label"> <a data-id="{{tete._id}}">{{tete.name}}</a></span> <span class="queuesouffle-label"> <a data-item-id="{{tete._id}}">{{tete.name}}</a></span>
<div class="item-controls">
<a class="item-control item-delete" title="Delete Item"><i class="fas fa-trash"></i></a>
</div>
</li> </li>
{{/each}} {{/each}}
</div> </div>
<div> <div>
<span><strong>Ombres de Thanatos:</strong></span> <span><strong>Ombres de Thanatos:</strong></span>
{{#each data.ombres as |ombre key|}} {{#each data.ombres as |ombre key|}}
<li class="item flexrow" data-attribute={{key}}> <li class="item flexrow" data-attribute={{key}} data-item-id="{{queue._id}}">
<span class="queuesouffle-label"> <a data-id="{{ombre._id}}">{{ombre.name}}</a></span> <span class="queuesouffle-label"> <a data-item-id="{{ombre._id}}">{{ombre.name}}</a></span>
<div class="item-controls">
<a class="item-control item-delete" title="Delete Item"><i class="fas fa-trash"></i></a>
</div>
</li> </li>
{{/each}} {{/each}}
</div> </div>