From e54de9f080e32c0bad4c5fd12f298107ebf9c3ac Mon Sep 17 00:00:00 2001 From: sladecraven Date: Sun, 10 Jan 2021 22:12:07 +0100 Subject: [PATCH] Ajout acteur de type vehicule/maison --- module/actor-humanoide-sheet.js | 184 ------------------------- module/actor-vehicule-sheet.js | 111 +++++++++++++++ module/actor.js | 29 ++-- module/rdd-main.js | 8 +- module/rdd-utility.js | 9 +- system.json | 4 +- template.json | 17 ++- templates/actor-vehicule-sheet.html | 119 ++++++++++++++++ templates/enum-categorie-vehicule.html | 7 + 9 files changed, 285 insertions(+), 203 deletions(-) delete mode 100644 module/actor-humanoide-sheet.js create mode 100644 module/actor-vehicule-sheet.js create mode 100644 templates/actor-vehicule-sheet.html create mode 100644 templates/enum-categorie-vehicule.html diff --git a/module/actor-humanoide-sheet.js b/module/actor-humanoide-sheet.js deleted file mode 100644 index 657834e6..00000000 --- a/module/actor-humanoide-sheet.js +++ /dev/null @@ -1,184 +0,0 @@ -/** - * Extend the basic ActorSheet with some very simple modifications - * @extends {ActorSheet} - */ - -import { HtmlUtility } from "./html-utility.js"; -import { RdDUtility } from "./rdd-utility.js"; - -/* -------------------------------------------- */ -export class RdDActorHumanoideSheet extends ActorSheet { - - /** @override */ - static get defaultOptions() { - return mergeObject(super.defaultOptions, { - classes: ["rdd", "sheet", "actor"], - template: "systems/foundryvtt-reve-de-dragon/templates/actor-humanoide-sheet.html", - width: 640, - height: 720, - tabs: [{navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "carac"}], - dragDrop: [{dragSelector: ".item-list .item", dropSelector: null}] - }); - } - - /* -------------------------------------------- */ - getData() { - let data = super.getData(); - - data.itemsByType = {}; - for (const item of data.items) { - let list = data.itemsByType[item.type]; - if (!list) { - list = []; - data.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; - - data.data.carac.taille.isTaille = true; // To avoid button link; - data.data.carac.chance.isChance = true; // Ajouter chance actuelle et utiliser; - data.data.blessures.resume = this.actor.computeResumeBlessure(data.data.blessures); - - data.data.competencecreature = data.itemsByType["competencecreature"]; - data.data.isGM = game.user.isGM; - data.data.compteurs.ethylisme.nom = RdDUtility.getNomEthylisme(data.data.compteurs.ethylisme.value); - - RdDUtility.filterItemsPerTypeForSheet(data ); - RdDUtility.buildArbreDeConteneur( this, data ); - - return data; - } - - /* -------------------------------------------- */ - async _onDrop(event) { - await RdDUtility.processItemDropEvent(this.actor, event); - super._onDrop(event); - } - - /* -------------------------------------------- */ - /** @override */ - activateListeners(html) { - super.activateListeners(html); - - HtmlUtility._showControlWhen($(".gm-only"), game.user.isGM); - - // Everything below here is only needed if the sheet is editable - if (!this.options.editable) return; - - // Update Inventory Item - html.find('.item-edit').click(ev => { - const li = $(ev.currentTarget).parents(".item"); - const item = this.actor.getOwnedItem(li.data("itemId")); - item.sheet.render(true); - }); - - // Delete Inventory Item - html.find('.item-delete').click(ev => { - const li = $(ev.currentTarget).parents(".item"); - this.actor.deleteOwnedItem(li.data("itemId")); - li.slideUp(200, () => this.render(false)); - }); - - // 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) ); - }); - - // Roll Carac - html.find('.carac-label a').click((event) => { - let caracName = event.currentTarget.attributes.name.value; - this.actor.rollCarac( caracName.toLowerCase() ); - }); - - // On competence change - html.find('.creature-carac').change((event) => { - let compName = event.currentTarget.attributes.compname.value; - this.actor.updateCreatureCompetence( compName, "carac_value", parseInt(event.target.value) ); - } ); - html.find('.creature-niveau').change((event) => { - let compName = event.currentTarget.attributes.compname.value; - this.actor.updateCreatureCompetence( compName, "niveau", parseInt(event.target.value) ); - } ); - html.find('.creature-dommages').change((event) => { - let compName = event.currentTarget.attributes.compname.value; - this.actor.updateCreatureCompetence( compName, "dommages", parseInt(event.target.value) ); - } ); - - // Roll Skill - html.find('.competence-label a').click((event) => { - let compName = event.currentTarget.text; - this.actor.rollCompetence( compName ); - }); - - html.find('#vie-plus').click((event) => { - this.actor.santeIncDec("vie", 1); - this.render(true); - }); - html.find('#vie-moins').click((event) => { - this.actor.santeIncDec("vie", -1); - this.render(true); - }); - html.find('#endurance-plus').click((event) => { - this.actor.santeIncDec("endurance", 1); - this.render(true); - }); - html.find('#endurance-moins').click((event) => { - this.actor.santeIncDec("endurance", -1); - this.render(true); - }); - - html.find('#encaisser-direct').click(ev => { - this.actor.encaisser() - }); - - html.find('#remise-a-neuf').click(ev => { - if (game.user.isGM) { - this.actor.remiseANeuf(); - } - }); - } - - - /* -------------------------------------------- */ - - /** @override */ - setPosition(options={}) { - const position = super.setPosition(options); - const sheetBody = this.element.find(".sheet-body"); - const bodyHeight = position.height - 192; - sheetBody.css("height", bodyHeight); - return position; - } - - - /* -------------------------------------------- */ - - /** @override */ - _updateObject(event, formData) { - // Update the Actor - return this.object.update(formData); - } -} diff --git a/module/actor-vehicule-sheet.js b/module/actor-vehicule-sheet.js new file mode 100644 index 00000000..b33c2d74 --- /dev/null +++ b/module/actor-vehicule-sheet.js @@ -0,0 +1,111 @@ +/** + * Extend the basic ActorSheet with some very simple modifications + * @extends {ActorSheet} + */ + +import { RdDUtility } from "./rdd-utility.js"; +import { HtmlUtility } from "./html-utility.js"; +import { RdDItem } from "./item.js"; + +/* -------------------------------------------- */ +export class RdDActorVehiculeSheet extends ActorSheet { + + /** @override */ + static get defaultOptions() { + RdDUtility.initAfficheContenu(); + + return mergeObject(super.defaultOptions, { + classes: ["rdd", "sheet", "actor"], + template: "systems/foundryvtt-reve-de-dragon/templates/actor-vehicule-sheet.html", + width: 640, + height: 720, + tabs: [{navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "carac"}], + dragDrop: [{dragSelector: ".item-list .item", dropSelector: null}] + }); + } + + /* -------------------------------------------- */ + _checkNull(items) { + if (items && items.length) { + return items; + } + return []; + } + + /* -------------------------------------------- */ + getData() { + let data = super.getData(); + + data.itemsByType = RdDItem.buildItemsClassification(data.items); + + RdDUtility.filterItemsPerTypeForSheet(data); + RdDUtility.buildArbreDeConteneur(this, data); + + this.actor.computeEncombrementTotalEtMalusArmure(); + data.data.isGM = game.user.isGM; + data.data.surEncombrementMessage = (this.encTotal > data.capacite_encombrement) ? "Sur-Encombrement!" : ""; + + console.log("DATA", data); + + return data; + } + + /* -------------------------------------------- */ + async _onDrop(event) { + let toSuper = await RdDUtility.processItemDropEvent(this, event); + if ( toSuper) { + super._onDrop(event); + } + } + + /* -------------------------------------------- */ + /** @override */ + activateListeners(html) { + super.activateListeners(html); + + HtmlUtility._showControlWhen($(".gm-only"), game.user.isGM); + + // Everything below here is only needed if the sheet is editable + if (!this.options.editable) return; + + // Update Inventory Item + html.find('.item-edit').click(ev => { + const li = $(ev.currentTarget).parents(".item"); + const item = this.actor.getOwnedItem(li.data("itemId")); + item.sheet.render(true); + }); + + // Delete Inventory Item + html.find('.item-delete').click(ev => { + const li = $(ev.currentTarget).parents(".item"); + this.actor.deleteOwnedItem(li.data("itemId")); + li.slideUp(200, () => this.render(false)); + }); + + // Display info about queue + html.find('.conteneur-name a').click((event) => { + let myID = event.currentTarget.attributes['data-item-id'].value; + RdDUtility.toggleAfficheContenu(myID); + this.render(true); + }); + + } + + /* -------------------------------------------- */ + /** @override */ + setPosition(options={}) { + const position = super.setPosition(options); + const sheetBody = this.element.find(".sheet-body"); + const bodyHeight = position.height - 192; + sheetBody.css("height", bodyHeight); + return position; + } + + + /* -------------------------------------------- */ + /** @override */ + _updateObject(event, formData) { + // Update the Actor + return this.object.update(formData); + } +} diff --git a/module/actor.js b/module/actor.js index a5d2272b..11e03da1 100644 --- a/module/actor.js +++ b/module/actor.js @@ -53,7 +53,7 @@ export class RdDActor extends Actor { return actor; } - let compendiumName = ""; + let compendiumName; if (data.type == "personnage") { compendiumName = "foundryvtt-reve-de-dragon.competences"; } else if (data.type == "creature") { @@ -61,7 +61,9 @@ export class RdDActor extends Actor { } else if (data.type == "entite") { compendiumName = "foundryvtt-reve-de-dragon.competences-entites"; } - data.items = RdDUtility.loadCompendium(compendiumName); + if ( compendiumName ) { + data.items = RdDUtility.loadCompendium(compendiumName); + } // Ajout monnaie if (data.type == "personnage") { await RdDActor.ajouterMonnaie(data.items); @@ -90,6 +92,7 @@ export class RdDActor extends Actor { // things organized. if (actorData.type === 'personnage') this._prepareCharacterData(actorData); if (actorData.type === 'creature') this.prepareCreatureData(actorData); + if (actorData.type === 'vehicule') this.prepareVehiculeData(actorData); } /* -------------------------------------------- */ @@ -98,6 +101,11 @@ export class RdDActor extends Actor { this.computeEtatGeneral(); } + /* -------------------------------------------- */ + prepareVehiculeData( actorData ) { + this.computeEncombrementTotalEtMalusArmure(); + } + /* -------------------------------------------- */ /** * Prepare Character type specific data @@ -758,7 +766,6 @@ export class RdDActor extends Actor { itemsList.push( {id: itemId, conteneurId: undefined }); // Init list sourceActor.buildSubConteneurObjetList( itemId, itemsList ); // Get itemId list - let conteneurMap = {}; for (let item of itemsList) { let copyItem = sourceActor.data.items.find( subItem => subItem._id == item.id ); @@ -784,14 +791,20 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ detectSurEncombrement( ) { - let diffEnc = Number(this.encTotal) - Number(this.data.data.attributs.encombrement.value); + let maxEnc = 0; + if ( this.data.type == 'vehicule') + maxEnc = this.data.data.capacite_encombrement; + else + maxEnc = this.data.data.attributs.encombrement.value; + let diffEnc = Number(this.encTotal) - Number(maxEnc); return Math.max(0, Math.ceil(diffEnc)); } /* -------------------------------------------- */ async computeEncombrementTotalEtMalusArmure() { let encTotal = 0; - let malusArmureData = (this.data.data.attributs.malusarmure) ? duplicate(this.data.data.attributs.malusarmure) : {}; + + let malusArmureData = (this.data.data.attributs && this.data.data.attributs.malusarmure) ? duplicate(this.data.data.attributs.malusarmure) : {}; let newMalusArmure = 0; for (const item of this.data.items) { if (item.type == 'armure' && item.data.equipe) { // Armure équipée, intégration du malus armure total @@ -811,10 +824,10 @@ export class RdDActor extends Actor { } // Mise à jour valeur totale et états this.encTotal = encTotal; - //console.log("Enco total : ", this.encTotal); + console.log("Enco total : ", this.encTotal); this.detectSurEncombrement(); // Mise à jour éventuelle du malus armure - if (this.data.data.attributs.malusarmure && newMalusArmure != malusArmureData.value) { + if (this.data.data.attributs && this.data.data.attributs.malusarmure && newMalusArmure != malusArmureData.value) { malusArmureData.value = newMalusArmure; await this.update({ "data.attributs.malusarmure": malusArmureData }); } @@ -875,7 +888,7 @@ export class RdDActor extends Actor { data.compteurs.surenc.value = - this.detectSurEncombrement(); } } - + /* -------------------------------------------- */ async ajouterRefoulement(value = 1) { let ret = "none"; diff --git a/module/rdd-main.js b/module/rdd-main.js index 8e0faad3..892866e5 100644 --- a/module/rdd-main.js +++ b/module/rdd-main.js @@ -12,7 +12,7 @@ import { RdDActor } from "./actor.js"; import { RdDItemSheet } from "./item-sheet.js"; import { RdDActorSheet } from "./actor-sheet.js"; import { RdDActorCreatureSheet } from "./actor-creature-sheet.js"; -//import { RdDActorHumanoideSheet } from "./actor-humanoide-sheet.js"; +import { RdDActorVehiculeSheet } from "./actor-vehicule-sheet.js"; import { RdDActorEntiteSheet } from "./actor-entite-sheet.js"; import { RdDUtility } from "./rdd-utility.js"; import { TMRUtility } from "./tmr-utility.js"; @@ -207,10 +207,10 @@ Hooks.once("init", async function() { types: ["creature"], makeDefault: true }); - /*Actors.registerSheet("foundryvtt-reve-de-dragon", RdDActorHumanoideSheet, { - types: ["humanoide"], + Actors.registerSheet("foundryvtt-reve-de-dragon", RdDActorVehiculeSheet, { + types: ["vehicule"], makeDefault: true - });*/ + }); Actors.registerSheet("foundryvtt-reve-de-dragon", RdDActorEntiteSheet, { types: ["entite"], makeDefault: true diff --git a/module/rdd-utility.js b/module/rdd-utility.js index 7b263dff..0dc497e7 100644 --- a/module/rdd-utility.js +++ b/module/rdd-utility.js @@ -128,8 +128,8 @@ export class RdDUtility { //Character Sheets 'systems/foundryvtt-reve-de-dragon/templates/actor-sheet.html', 'systems/foundryvtt-reve-de-dragon/templates/actor-creature-sheet.html', - 'systems/foundryvtt-reve-de-dragon/templates/actor-humanoide-sheet.html', 'systems/foundryvtt-reve-de-dragon/templates/actor-entite-sheet.html', + 'systems/foundryvtt-reve-de-dragon/templates/actor-vehicule-sheet.html', //Items 'systems/foundryvtt-reve-de-dragon/templates/item-competence-sheet.html', 'systems/foundryvtt-reve-de-dragon/templates/item-competencecreature-sheet.html', @@ -157,6 +157,7 @@ export class RdDUtility { 'systems/foundryvtt-reve-de-dragon/templates/enum-categorie-competence.html', 'systems/foundryvtt-reve-de-dragon/templates/enum-categorie-ingredient.html', 'systems/foundryvtt-reve-de-dragon/templates/enum-categorie-parade.html', + 'systems/foundryvtt-reve-de-dragon/templates/enum-categorie-vehicule.html', 'systems/foundryvtt-reve-de-dragon/templates/enum-competence.html', 'systems/foundryvtt-reve-de-dragon/templates/enum-rarete.html', 'systems/foundryvtt-reve-de-dragon/templates/sort-draconic.html', @@ -234,7 +235,9 @@ export class RdDUtility { } /* -------------------------------------------- */ static getAfficheContenu(conteneurId) { - return this.afficheContenu[conteneurId]; + if ( conteneurId ) + return this.afficheContenu[conteneurId]; + return undefined; } /* -------------------------------------------- */ @@ -320,7 +323,7 @@ export class RdDUtility { //console.log("OBJ:", objet); let str = Handlebars.partials['systems/foundryvtt-reve-de-dragon/templates/actor-inventaire-conteneur.html']({ item: objet }); if (objet.type == 'conteneur') { - //console.log("ITEM DISPLAYED", this.getAfficheContenu(objet._id) ); + console.log("ITEM DISPLAYED", objet ); if (this.getAfficheContenu(objet._id)) { str = str + "