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, {
classes: ["rdd", "sheet", "actor"],
template: "systems/foundryvtt-reve-de-dragon/templates/actor-sheet.html",
width: 600,
height: 600,
width: 640,
height: 720,
tabs: [{navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "description"}],
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.nbLegeres = RdDUtility.computeNbBlessures(data.data.blessures, "legeres" );
data.data.nbGraves = RdDUtility.computeNbBlessures(data.data.blessures, "graves" );
data.data.nbCritiques = RdDUtility.computeNbBlessures(data.data.blessures, "critiques" );
data.data.nbLegeres = this.actor.GetNumberBlessures(data.data.blessures.legeres.liste );
data.data.nbGraves = this.actor.GetNumberBlessures(data.data.blessures.graves.liste );
data.data.nbCritiques = this.actor.GetNumberBlessures(data.data.blessures.critiques.liste );
// 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>";
@ -98,8 +98,6 @@ export class RdDActorSheet extends ActorSheet {
data.data.ombres = this._checkNull(data.itemsByType['ombre']);
data.data.tetes = this._checkNull(data.itemsByType['tete']);
data.data.competenceByCategory = data.competenceByCategory;
//data.data.armes = data.itemsByType.arme;
//console.log(">>>>> data update");
return data;
}
@ -127,12 +125,27 @@ export class RdDActorSheet extends ActorSheet {
li.slideUp(200, () => this.render(false));
});
// Equip Inventory Item
html.find('.blessure-legere-control').click(ev => {
let index = event.currentTarget.attributes['data-blessure-index'].value;
let active = event.currentTarget.attributes['data-blessure-active'].value;
this.actor.manageBlessureLegere(index, active);
this.render(true);
// Blessure control
html.find('.blessure-control').click(ev => {
const li = $(ev.currentTarget).parents(".item");
let btype = li.data("blessure-type");
let index = li.data('blessure-index');
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
@ -172,7 +185,7 @@ export class RdDActorSheet extends ActorSheet {
// Display info about queue
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);
item.sheet.render(true);
});

View File

@ -388,7 +388,16 @@ export class RdDActor extends Actor {
// TODO : Output to chat
}
}
/* -------------------------------------------- */
GetNumberBlessures( blessuresListe )
{
let nbB = 0;
for ( let b of blessuresListe) {
nbB += ( b.active) ? 1 : 0;
}
return nbB;
}
/* -------------------------------------------- */
async santeIncDec(name, inc ) {
const sante = duplicate(this.data.data.sante);
@ -412,10 +421,12 @@ export class RdDActor extends Actor {
}
if ( data.value < 0 ) data.value = 0; // Security
let blessures = this.data.data.blessures;
let maxEnd = Math.floor( data.max / blessures.graves.nombre);
let blessures = this.data.data.blessures;
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 ( 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
}
@ -429,14 +440,31 @@ export class RdDActor extends Actor {
await this.update( {"data.sante": sante } );
}
/* -------------------------------------------- */
async manageBlessureLegere( index ) {
let legeres = duplicate(this.data.data.blessures.legeres);
let blessure = legeres.liste[index];
async manageBlessureFromSheet( bType, index, active ) {
let bList = duplicate(this.data.data.blessures);
let blessure = bList[bType+"s"].liste[index];
blessure.active = !blessure.active;
console.log("Blessure update", index, blessure );
await this.update( { "data.blessures.legeres": legeres } );
if ( !blessure.active ) {
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 } );
}
/* -------------------------------------------- */
manageBlessures( blessuresData )
{

View File

@ -365,18 +365,6 @@ export class RdDUtility {
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)
{

View File

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

View File

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

View File

@ -99,7 +99,7 @@
{{!-- Compétences Tab --}}
<div class="tab competences" data-group="primary" data-tab="competences">
<div class="grid grid-2col">
<div class="flex-group-left flexcol">
<div class="flex-group-left flexcol competence-column">
<header class="competence-header flexrow">
<span class="competence-title">Compétences de base</span>
</header>
@ -118,7 +118,7 @@
{{/each}}
</ol>
<header class="competences-header flexrow">
<header class="competence-header flexrow">
<span class="competence-title">Compétences Particulières</span>
</header>
<ol class="item-list">
@ -134,11 +134,28 @@
</div>
</li>
{{/each}}
</ol>
</div>
</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 class="flex-group-left flexcol">
<header class="competences-header flexrow">
<div class="flex-group-left flexcol competence-column">
<header class="competence-header flexrow">
<span class="competence-title">Compétences De Mêlée</span>
</header>
<ol class="item-list">
@ -156,7 +173,7 @@
{{/each}}
</ol>
<header class="competences-header flexrow">
<header class="competence-header flexrow">
<span class="competence-title">Compétences De Tir</span>
</header>
<ol class="item-list">
@ -174,7 +191,7 @@
{{/each}}
</ol>
<header class="competences-header flexrow">
<header class="competence-header flexrow">
<span class="competence-title">Compétences De Lancer</span>
</header>
<ol class="item-list">
@ -192,24 +209,6 @@
{{/each}}
</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">
<span class="competence-title">Connaissances</span>
</header>
@ -228,7 +227,7 @@
{{/each}}
</ol>
<header class="competences-header flexrow">
<header class="competence-header flexrow">
<span class="competence-title">Draconic</span>
</header>
<ol class="item-list">
@ -244,7 +243,9 @@
</div>
</li>
{{/each}}
</ol>
</ol>
<div></div>
<div></div>
</div>
</div>
</div>
@ -270,31 +271,40 @@
{{!-- blessures Tab --}}
<div class="tab blessures" data-group="primary" data-tab="blessures" style="height:200px">
<span>Blessures Légeres :</span>
<div class="flexcol">
<span class="blessures-title">Blessures Légeres :</span>
<div class="blessure-data">
{{#each data.blessures.legeres.liste as |bless key|}}
<li class="item flexrow" data-attribute={{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>
Premiers soins <input class="blessures-soins" type="text" name="data.blessures.legeres.liste[{{key}}].premiers_soins" data-dtype="number" value="{{bless.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}}"/> -
Jours <input class="blessures-soins" type="text" name="data.blessures.legeres.liste[{{key}}].jours" data-dtype="number" value="{{bless.jours}}"/> -
Loc. <input class="blessures-loc" type="text" name="data.blessures.legeres.liste[{{key}}].localisation" data-dtype="String" value="{{bless.localisation}}"/>
<li class="item flexrow blessure-data" data-blessure-type="legere" data-attribute={{key}} data-blessure-index="{{key}}">
<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='premiers_soins' data-dtype="number" value="{{this.premiers_soins}}"/> -
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='jours' data-dtype="number" value="{{this.jours}}"/> -
Loc. <input class="blessures-soins" type="text" name='localisation' data-dtype="String" value="{{this.localisation}}"/>
</li>
{{/each}}
</div>
<span>Blessures Graves :</span>
<div>
<span class="blessures-title">Blessures Graves :</span>
<div>
{{#each data.blessures.graves.liste as |bless key|}}
<li class="item flexrow" data-attribute={{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>
<li class="item flexrow" data-blessure-type="grave" data-attribute={{key}} data-blessure-index="{{key}}" >
<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>
{{/each}}
</div>
<span>Blessure Critique :</span>
<div>
<span class="blessures-title">Blessure Critique :</span>
<div>
{{#each data.blessures.critiques.liste as |bless key|}}
<li class="item flexrow" data-attribute={{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>
<li class="item flexrow" data-blessure-type="critique" data-attribute={{key}} data-blessure-index="{{key}}" >
<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>
{{/each}}
</div>
@ -362,32 +372,44 @@
<div>
<span><strong>Queues:</strong></span>
{{#each data.queues as |queue key|}}
<li class="item flexrow" data-attribute={{key}}>
<span class="queuesouffle-label"> <a data-id="{{queue._id}}">{{queue.name}}</a></span>
<li class="item flexrow" data-attribute={{key}} data-item-id="{{queue._id}}">
<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>
{{/each}}
</div>
<div>
<span><strong>Souffles:</strong></span>
{{#each data.souffles as |souffle key|}}
<li class="item flexrow" data-attribute={{key}}>
<span class="queuesouffle-label"> <a data-id="{{souffle._id}}">{{souffle.name}}</a></span>
<li class="item flexrow" data-attribute={{key}} data-item-id="{{queue._id}}">
<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>
{{/each}}
</div>
<div>
<span><strong>Tetes:</strong></span>
{{#each data.tetes as |tete key|}}
<li class="item flexrow" data-attribute={{key}}>
<span class="queuesouffle-label"> <a data-id="{{tete._id}}">{{tete.name}}</a></span>
<li class="item flexrow" data-attribute={{key}} data-item-id="{{queue._id}}">
<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>
{{/each}}
</div>
<div>
<span><strong>Ombres de Thanatos:</strong></span>
{{#each data.ombres as |ombre key|}}
<li class="item flexrow" data-attribute={{key}}>
<span class="queuesouffle-label"> <a data-id="{{ombre._id}}">{{ombre.name}}</a></span>
<li class="item flexrow" data-attribute={{key}} data-item-id="{{queue._id}}">
<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>
{{/each}}
</div>