Rename data to formData

This commit is contained in:
Vincent Vandemeulebrouck 2021-03-16 22:56:57 +01:00
parent 830f4fde9a
commit 10ddcf031e
9 changed files with 160 additions and 152 deletions

View File

@ -26,40 +26,40 @@ export class RdDActorCreatureSheet extends RdDActorSheet {
/* -------------------------------------------- */
getData() {
let data = super.getData();
console.log("Creature : ", data);
let formData = super.getDData();
console.log("Creature : ", formData);
data.itemsByType = {};
for (const item of data.items) {
let list = data.itemsByType[item.type];
formData.itemsByType = {};
for (const item of formData.items) {
let list = formData.itemsByType[item.type];
if (!list) {
list = [];
data.itemsByType[item.type] = list;
formData.itemsByType[item.type] = list;
}
list.push(item);
}
// Compute current carac sum
let sum = 0;
Object.values(data.data.carac).forEach(carac => { if (!carac.derivee) { sum += parseInt(carac.value) } });
data.data.caracSum = sum;
Object.values(formData.data.carac).forEach(carac => { if (!carac.derivee) { sum += parseInt(carac.value) } });
formData.data.caracSum = sum;
data.data.carac.taille.isTaille = true; // To avoid button link;
data.data.blessures.resume = this.actor.computeResumeBlessure(data.data.blessures);
formData.data.carac.taille.isTaille = true; // To avoid button link;
formData.data.blessures.resume = this.actor.computeResumeBlessure(formData.data.blessures);
data.data.isGM = game.user.isGM;
formData.data.isGM = game.user.isGM;
data.data.competencecreature = data.itemsByType["competencecreature"];
formData.data.competencecreature = formData.itemsByType["competencecreature"];
this.actor.computeEncombrementTotalEtMalusArmure();
RdDUtility.filterItemsPerTypeForSheet(data);
RdDUtility.buildArbreDeConteneur(this, data);
data.data.encTotal = this.actor.encTotal;
data.data.isGM = game.user.isGM;
RdDUtility.filterItemsPerTypeForSheet(formData);
RdDUtility.buildArbreDeConteneur(this, formData);
formData.data.encTotal = this.actor.encTotal;
formData.data.isGM = game.user.isGM;
console.log("Creature : ", this.objetVersConteneur, data);
console.log("Creature : ", this.objetVersConteneur, formData);
return data;
return formData;
}
/* -------------------------------------------- */

View File

@ -30,23 +30,23 @@ export class RdDActorEntiteSheet extends ActorSheet {
/* -------------------------------------------- */
getData() {
let data = super.getData();
let formData = super.getData();
data.itemsByType = {};
for (const item of data.items) {
let list = data.itemsByType[item.type];
formData.itemsByType = {};
for (const item of formData.items) {
let list = formData.itemsByType[item.type];
if (!list) {
list = [];
data.itemsByType[item.type] = list;
formData.itemsByType[item.type] = list;
}
list.push(item);
}
data.data.carac.taille.isTaille = true; // To avoid button link;
data.data.competencecreature = data.itemsByType["competencecreature"];
data.data.isGM = game.user.isGM;
formData.data.carac.taille.isTaille = true; // To avoid button link;
formData.data.competencecreature = formData.itemsByType["competencecreature"];
formData.data.isGM = game.user.isGM;
return data;
return formData;
}
/* -------------------------------------------- */

View File

@ -32,113 +32,114 @@ export class RdDActorSheet extends ActorSheet {
/* -------------------------------------------- */
getData() {
let data = super.getData();
if (data.actor.type == 'creature' || data.actor.type == 'humanoide') return data; // Shortcut
let formData = super.getData();
data.data.editCaracComp = this.options.editCaracComp;
data.data.showCompNiveauBase = this.options.showCompNiveauBase;
data.data.montrerArchetype = this.options.montrerArchetype;
if (formData.actor.type == 'creature' || formData.actor.type == 'humanoide') return formData; // Shortcut
data.itemsByType = Misc.classify(data.items);
formData.data.editCaracComp = this.options.editCaracComp;
formData.data.showCompNiveauBase = this.options.showCompNiveauBase;
formData.data.montrerArchetype = this.options.montrerArchetype;
formData.itemsByType = Misc.classify(formData.items);
// Competence per category
data.data.comptageArchetype = RdDUtility.getLimitesArchetypes();
data.data.competenceXPTotal = 0;
data.competenceByCategory = Misc.classify(
data.itemsByType.competence,
formData.data.comptageArchetype = RdDUtility.getLimitesArchetypes();
formData.data.competenceXPTotal = 0;
formData.competenceByCategory = Misc.classify(
formData.itemsByType.competence,
item => item.data.categorie,
item => {
let archetypeKey = (item.data.niveau_archetype < 0) ? 0 : item.data.niveau_archetype;
if (data.data.comptageArchetype[archetypeKey] == undefined) {
data.data.comptageArchetype[archetypeKey] = { "niveau": archetypeKey, "nombreMax": 0, "nombre": 0 };
if (formData.data.comptageArchetype[archetypeKey] == undefined) {
formData.data.comptageArchetype[archetypeKey] = { "niveau": archetypeKey, "nombreMax": 0, "nombre": 0 };
}
data.data.comptageArchetype[archetypeKey].nombre = (data.data.comptageArchetype[archetypeKey]?.nombre ?? 0) + 1; //Comptage archetype
formData.data.comptageArchetype[archetypeKey].nombre = (formData.data.comptageArchetype[archetypeKey]?.nombre ?? 0) + 1; //Comptage archetype
item.data.xpNext = RdDItemCompetence.getCompetenceNextXp(item.data.niveau);
item.data.isLevelUp = item.data.xp >= item.data.xpNext; // Flag de niveau à MAJ
//this.actor.checkCompetenceXP(item.name); // Petite vérification experience
item.data.showCompetence = !data.data.showCompNiveauBase || (Number(item.data.niveau) != Number(RdDItemCompetence.getLevelCategory(item.data.categorie)));
item.data.showCompetence = !formData.data.showCompNiveauBase || (Number(item.data.niveau) != Number(RdDItemCompetence.getLevelCategory(item.data.categorie)));
// Ignorer les compétences 'troncs' à ce stade
data.data.competenceXPTotal += RdDItemCompetence.computeCompetenceXPCost(item);
formData.data.competenceXPTotal += RdDItemCompetence.computeCompetenceXPCost(item);
return item;
});
data.data.competenceXPTotal -= RdDItemCompetence.computeEconomieCompetenceTroncXP(data.itemsByType.competence);
formData.data.competenceXPTotal -= RdDItemCompetence.computeEconomieCompetenceTroncXP(formData.itemsByType.competence);
// Compute current carac sum
let sum = 0;
for (let caracName in data.data.carac) {
let currentCarac = data.data.carac[caracName];
for (let caracName in formData.data.carac) {
let currentCarac = formData.data.carac[caracName];
if (!currentCarac.derivee) {
sum += parseInt(currentCarac.value);
}
currentCarac.xpNext = RdDUtility.getCaracNextXp(currentCarac.value);
currentCarac.isLevelUp = (currentCarac.xp >= currentCarac.xpNext);
}
sum += (data.data.beaute >= 0) ? (data.data.beaute - 10) : 0;
data.data.caracSum = sum;
sum += (formData.data.beaute >= 0) ? (formData.data.beaute - 10) : 0;
formData.data.caracSum = sum;
// Force empty arme, at least for Esquive
if (data.itemsByType.arme == undefined) data.itemsByType.arme = [];
for (const arme of data.itemsByType.arme) {
if (formData.itemsByType.arme == undefined) formData.itemsByType.arme = [];
for (const arme of formData.itemsByType.arme) {
arme.data.niveau = 0; // Per default, TODO to be fixed
for (const melee of data.competenceByCategory.melee) {
for (const melee of formData.competenceByCategory.melee) {
if (melee.name == arme.data.competence)
arme.data.niveau = melee.data.niveau
}
for (const tir of data.competenceByCategory.tir) {
for (const tir of formData.competenceByCategory.tir) {
if (tir.name == arme.data.competence)
arme.data.niveau = tir.data.niveau
}
for (const lancer of data.competenceByCategory.lancer) {
for (const lancer of formData.competenceByCategory.lancer) {
if (lancer.name == arme.data.competence)
arme.data.niveau = lancer.data.niveau
}
}
// To avoid armour and so on...
data.data.combat = duplicate(RdDUtility.checkNull(data.itemsByType['arme']));
data.data.combat = RdDCombatManager.finalizeArmeList(data.data.combat, data.itemsByType.competence, data.data.carac);
formData.data.combat = duplicate(RdDUtility.checkNull(formData.itemsByType['arme']));
formData.data.combat = RdDCombatManager.finalizeArmeList(formData.data.combat, formData.itemsByType.competence, formData.data.carac);
data.esquive = { name: "Esquive", niveau: data.competenceByCategory?.melee.find(it => it.name == 'Esquive')?.data.niveau ?? -6 };
let corpsACorps = data.competenceByCategory?.melee.find(it => it.name == 'Corps à corps');
formData.esquive = { name: "Esquive", niveau: formData.competenceByCategory?.melee.find(it => it.name == 'Esquive')?.data.niveau ?? -6 };
let corpsACorps = formData.competenceByCategory?.melee.find(it => it.name == 'Corps à corps');
if (corpsACorps) {
let cc_init = RdDCombatManager.calculInitiative(corpsACorps.data.niveau, data.data.carac['melee'].value);
data.data.combat.push(RdDItemArme.mainsNues({ niveau: corpsACorps.data.niveau, initiative: cc_init }));
let cc_init = RdDCombatManager.calculInitiative(corpsACorps.data.niveau, formData.data.carac['melee'].value);
formData.data.combat.push(RdDItemArme.mainsNues({ niveau: corpsACorps.data.niveau, initiative: cc_init }));
}
this.armesList = duplicate(data.data.combat);
this.armesList = duplicate(formData.data.combat);
data.data.carac.taille.isTaille = true; // To avoid button link;
data.data.compteurs.chance.isChance = true;
data.data.blessures.resume = this.actor.computeResumeBlessure(data.data.blessures);
formData.data.carac.taille.isTaille = true; // To avoid button link;
formData.data.compteurs.chance.isChance = true;
formData.data.blessures.resume = this.actor.computeResumeBlessure(formData.data.blessures);
// Mise à jour de l'encombrement total et du prix de l'équipement
this.actor.computeEncombrementTotalEtMalusArmure();
this.actor.computePrixTotalEquipement();
// Common data
data.data.competenceByCategory = data.competenceByCategory;
data.data.encTotal = this.actor.encTotal;
data.data.prixTotalEquipement = this.actor.prixTotalEquipement;
data.data.surprise = RdDBonus.find(this.actor.getSurprise(false)).descr;
data.data.isGM = game.user.isGM;
data.ajustementsConditions = CONFIG.RDD.ajustementsConditions;
data.difficultesLibres = CONFIG.RDD.difficultesLibres;
formData.data.competenceByCategory = formData.competenceByCategory;
formData.data.encTotal = this.actor.encTotal;
formData.data.prixTotalEquipement = this.actor.prixTotalEquipement;
formData.data.surprise = RdDBonus.find(this.actor.getSurprise(false)).descr;
formData.data.isGM = game.user.isGM;
formData.ajustementsConditions = CONFIG.RDD.ajustementsConditions;
formData.difficultesLibres = CONFIG.RDD.difficultesLibres;
// low is normal, this the base used to compute the grid.
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>"
formData.data.fatigue = {
malus: RdDUtility.calculMalusFatigue(formData.data.sante.fatigue.value, formData.data.sante.endurance.max),
html: "<table class='table-fatigue'>" + RdDUtility.makeHTMLfatigueMatrix(formData.data.sante.fatigue.value, formData.data.sante.endurance.max).html() + "</table>"
}
RdDUtility.filterItemsPerTypeForSheet(data);
data.data.sortReserve = data.data.reve.reserve.list;
data.data.rencontres = duplicate(data.data.reve.rencontre.list);
data.data.caseSpeciales = data.itemsByType['casetmr'];
RdDUtility.buildArbreDeConteneur(this, data);
data.data.surEncombrementMessage = (data.data.compteurs.surenc.value < 0) ? "Sur-Encombrement!" : "";
data.data.vehiculesList = this.actor.buildVehiculesList();
data.data.monturesList = this.actor.buildMonturesList();
data.data.suivantsList = this.actor.buildSuivantsList();
return data;
RdDUtility.filterItemsPerTypeForSheet(formData);
formData.data.sortReserve = formData.data.reve.reserve.list;
formData.data.rencontres = duplicate(formData.data.reve.rencontre.list);
formData.data.caseSpeciales = formData.itemsByType['casetmr'];
RdDUtility.buildArbreDeConteneur(this, formData);
formData.data.surEncombrementMessage = (formData.data.compteurs.surenc.value < 0) ? "Sur-Encombrement!" : "";
formData.data.vehiculesList = this.actor.buildVehiculesList();
formData.data.monturesList = this.actor.buildMonturesList();
formData.data.suivantsList = this.actor.buildSuivantsList();
return formData;
}
/* -------------------------------------------- */

View File

@ -34,20 +34,20 @@ export class RdDActorVehiculeSheet extends ActorSheet {
/* -------------------------------------------- */
getData() {
let data = super.getData();
let formData = super.getData();
data.itemsByType = Misc.classify(data.items);
formData.itemsByType = Misc.classify(formData.items);
RdDUtility.filterItemsPerTypeForSheet(data);
RdDUtility.buildArbreDeConteneur(this, data);
RdDUtility.filterItemsPerTypeForSheet(formData);
RdDUtility.buildArbreDeConteneur(this, formData);
this.actor.computeEncombrementTotalEtMalusArmure();
data.data.isGM = game.user.isGM;
data.data.surEncombrementMessage = (this.encTotal > data.capacite_encombrement) ? "Sur-Encombrement!" : "";
formData.data.isGM = game.user.isGM;
formData.data.surEncombrementMessage = (this.encTotal > formData.capacite_encombrement) ? "Sur-Encombrement!" : "";
console.log("DATA", data);
console.log("DATA", formData);
return data;
return formData;
}
/* -------------------------------------------- */

View File

@ -47,26 +47,26 @@ export class RdDItemSheet extends ItemSheet {
/* -------------------------------------------- */
async getData() {
let data = super.getData();
data.categorieCompetences = RdDItemCompetence.getCategorieCompetences();
if ( data.item.type == 'tache' || data.item.type == 'livre' || data.item.type == 'meditation' || data.item.type == 'oeuvre') {
data.caracList = duplicate(game.system.model.Actor.personnage.carac);
data.competences = await RdDUtility.loadCompendiumNames( 'foundryvtt-reve-de-dragon.competences' );
let formData = super.getData();
formData.categorieCompetences = RdDItemCompetence.getCategorieCompetences();
if ( formData.item.type == 'tache' || formData.item.type == 'livre' || formData.item.type == 'meditation' || formData.item.type == 'oeuvre') {
formData.caracList = duplicate(game.system.model.Actor.personnage.carac);
formData.competences = await RdDUtility.loadCompendiumNames( 'foundryvtt-reve-de-dragon.competences' );
}
if (data.item.type == 'arme') {
data.competences = await RdDUtility.loadCompendium( 'foundryvtt-reve-de-dragon.competences', it => RdDItemCompetence.isCompetenceArme(it));
if (formData.item.type == 'arme') {
formData.competences = await RdDUtility.loadCompendium( 'foundryvtt-reve-de-dragon.competences', it => RdDItemCompetence.isCompetenceArme(it));
}
if ( data.item.type == 'recettealchimique' ) {
RdDAlchimie.processManipulation(data.item, this.actor && this.actor._id );
if ( formData.item.type == 'recettealchimique' ) {
RdDAlchimie.processManipulation(formData.item, this.actor && this.actor._id );
}
if ( this.actor ) {
data.isOwned = true;
data.actorId = this.actor._id;
formData.isOwned = true;
formData.actorId = this.actor._id;
}
data.bonusCaseList = RdDItemSort.getBonusCaseList(data, true);
data.isGM = game.user.isGM; // Pour verrouiller certaines éditions
formData.bonusCaseList = RdDItemSort.getBonusCaseList(formData, true);
formData.isGM = game.user.isGM; // Pour verrouiller certaines éditions
return data;
return formData;
}
/* -------------------------------------------- */

View File

@ -211,7 +211,7 @@ export class RdDCalendrier extends Application {
}
/* -------------------------------------------- */
fillCalendrierData(data = {}) {
fillCalendrierData(formData = {}) {
let moisKey = heuresList[this.calendrier.moisRdD];
let heureKey = heuresList[this.calendrier.heureRdD];
@ -219,18 +219,18 @@ export class RdDCalendrier extends Application {
const heure = heuresDef[heureKey];
//console.log(moisKey, heureKey);
data.heureKey = heureKey;
data.moisKey = moisKey;
data.jourMois = this.calendrier.jour + 1;
data.nomMois = mois.label; // heures et mois nommés identiques
data.iconMois = dossierIconesHeures + mois.icon;
data.nomHeure = heure.label;
data.iconHeure = dossierIconesHeures + heure.icon;
data.nomSaison = saisonsDef[mois.saison].label;
data.heureRdD = this.calendrier.heureRdD;
data.minutesRelative = this.calendrier.minutesRelative;
data.isGM = game.user.isGM;
return data;
formData.heureKey = heureKey;
formData.moisKey = moisKey;
formData.jourMois = this.calendrier.jour + 1;
formData.nomMois = mois.label; // heures et mois nommés identiques
formData.iconMois = dossierIconesHeures + mois.icon;
formData.nomHeure = heure.label;
formData.iconHeure = dossierIconesHeures + heure.icon;
formData.nomSaison = saisonsDef[mois.saison].label;
formData.heureRdD = this.calendrier.heureRdD;
formData.minutesRelative = this.calendrier.minutesRelative;
formData.isGM = game.user.isGM;
return formData;
}
/* -------------------------------------------- */
@ -301,12 +301,12 @@ export class RdDCalendrier extends Application {
/* -------------------------------------------- */
getData() {
let data = super.getData();
let formData = super.getData();
this.fillCalendrierData(data);
this.fillCalendrierData(formData);
this.setPos(this.calendrierPos);
return data;
return formData;
}
/* -------------------------------------------- */

View File

@ -279,32 +279,39 @@ export class RdDUtility {
}
/* -------------------------------------------- */
static filterItemsPerTypeForSheet(data) {
data.data.materiel = this.checkNull(data.itemsByType['objet']);
data.data.conteneurs = this.checkNull(data.itemsByType['conteneur']);
data.data.armes = this.checkNull(data.itemsByType['arme']);
data.data.armures = this.checkNull(data.itemsByType['armure']);
data.data.livres = this.checkNull(data.itemsByType['livre']);
data.data.potions = this.checkNull(data.itemsByType['potion']);
data.data.ingredients = this.checkNull(data.itemsByType['ingredient']);
data.data.munitions = this.checkNull(data.itemsByType['munition']);
data.data.herbes = this.checkNull(data.itemsByType['herbe']);
data.data.sorts = this.checkNull(data.itemsByType['sort']);
data.data.queues = this.checkNull(data.itemsByType['queue']);
data.data.souffles = this.checkNull(data.itemsByType['souffle']);
data.data.ombres = this.checkNull(data.itemsByType['ombre']);
data.data.tetes = this.checkNull(data.itemsByType['tete']);
data.data.taches = this.checkNull(data.itemsByType['tache']);
data.data.monnaie = this.checkNull(data.itemsByType['monnaie']);
data.data.meditations = this.checkNull(data.itemsByType['meditation']);
data.data.chants = this.checkNull(data.itemsByType['chant']);
data.data.danses = this.checkNull(data.itemsByType['danse']);
data.data.musiques = this.checkNull(data.itemsByType['musique']);
data.data.oeuvres = this.checkNull(data.itemsByType['oeuvre']);
data.data.jeux = this.checkNull(data.itemsByType['jeu']);
data.data.recettescuisine = this.checkNull(data.itemsByType['recettecuisine']);
data.data.recettesAlchimiques = this.checkNull(data.itemsByType['recettealchimique']);
data.data.objets = data.data.conteneurs.concat(data.data.materiel).concat(data.data.armes).concat(data.data.armures).concat(data.data.munitions).concat(data.data.livres).concat(data.data.potions).concat(data.data.herbes).concat(data.data.ingredients);
static filterItemsPerTypeForSheet(formData) {
formData.data.materiel = this.checkNull(formData.itemsByType['objet']);
formData.data.conteneurs = this.checkNull(formData.itemsByType['conteneur']);
formData.data.armes = this.checkNull(formData.itemsByType['arme']);
formData.data.armures = this.checkNull(formData.itemsByType['armure']);
formData.data.livres = this.checkNull(formData.itemsByType['livre']);
formData.data.potions = this.checkNull(formData.itemsByType['potion']);
formData.data.ingredients = this.checkNull(formData.itemsByType['ingredient']);
formData.data.munitions = this.checkNull(formData.itemsByType['munition']);
formData.data.herbes = this.checkNull(formData.itemsByType['herbe']);
formData.data.sorts = this.checkNull(formData.itemsByType['sort']);
formData.data.queues = this.checkNull(formData.itemsByType['queue']);
formData.data.souffles = this.checkNull(formData.itemsByType['souffle']);
formData.data.ombres = this.checkNull(formData.itemsByType['ombre']);
formData.data.tetes = this.checkNull(formData.itemsByType['tete']);
formData.data.taches = this.checkNull(formData.itemsByType['tache']);
formData.data.monnaie = this.checkNull(formData.itemsByType['monnaie']);
formData.data.meditations = this.checkNull(formData.itemsByType['meditation']);
formData.data.chants = this.checkNull(formData.itemsByType['chant']);
formData.data.danses = this.checkNull(formData.itemsByType['danse']);
formData.data.musiques = this.checkNull(formData.itemsByType['musique']);
formData.data.oeuvres = this.checkNull(formData.itemsByType['oeuvre']);
formData.data.jeux = this.checkNull(formData.itemsByType['jeu']);
formData.data.recettescuisine = this.checkNull(formData.itemsByType['recettecuisine']);
formData.data.recettesAlchimiques = this.checkNull(formData.itemsByType['recettealchimique']);
formData.data.objets = formData.data.conteneurs.concat(formData.data.materiel)
.concat(formData.data.armes)
.concat(formData.data.armures)
.concat(formData.data.munitions)
.concat(formData.data.livres)
.concat(formData.data.potions)
.concat(formData.data.herbes)
.concat(formData.data.ingredients);
}
/* -------------------------------------------- */

View File

@ -50,14 +50,14 @@ export class ReglesOptionelles extends FormApplication {
}
getData() {
let data = super.getData();
data.regles = listeReglesOptionelles.map(it => {
let formData = super.getData();
formData.regles = listeReglesOptionelles.map(it => {
let r = duplicate(it);
r.id = ReglesOptionelles._getIdRegle(r.name);
r.active = ReglesOptionelles.isUsing(r.name);
return r;
})
return data;
return formData;
}
static isUsing(name) {

View File

@ -103,9 +103,9 @@ class StatusEffectsSettings extends FormApplication {
}
getData() {
let data = super.getData();
data.effects = CONFIG.RDD.allEffects;
return data;
let formData = super.getData();
formData.effects = CONFIG.RDD.allEffects;
return formData;
}
activateListeners(html) {