TMR et acteurs à cocher pour les signe draconiques

Au lieu d'une liste à sélection multiple, choisir les types de TMR
avec des cases à cocher.

Lors de l'ajout de signes éphémères, sélectionner les personnages
avec des cases à cocher.
This commit is contained in:
Vincent Vandemeulebrouck 2022-09-24 00:31:51 +02:00
parent fe80881405
commit fc5674a7d8
8 changed files with 91 additions and 52 deletions

View File

@ -1,7 +1,6 @@
import { ChatUtility } from "./chat-utility.js"; import { ChatUtility } from "./chat-utility.js";
import { HtmlUtility } from "./html-utility.js"; import { HtmlUtility } from "./html-utility.js";
import { RdDItemSigneDraconique } from "./item-signedraconique.js"; import { RdDItemSigneDraconique } from "./item-signedraconique.js";
import { Misc } from "./misc.js";
import { TMRUtility } from "./tmr-utility.js"; import { TMRUtility } from "./tmr-utility.js";
export class DialogCreateSigneDraconique extends Dialog { export class DialogCreateSigneDraconique extends Dialog {
@ -10,12 +9,13 @@ export class DialogCreateSigneDraconique extends Dialog {
const signe = await RdDItemSigneDraconique.randomSigneDraconique({ephemere: true}); const signe = await RdDItemSigneDraconique.randomSigneDraconique({ephemere: true});
let dialogData = { let dialogData = {
signe: signe, signe: signe,
tmrs: TMRUtility.listSelectedTMR(signe.system.typesTMR ?? []), tmrs: TMRUtility.buildSelectionTypesTMR(signe.system.typesTMR),
actors: game.actors.filter(actor => actor.isHautRevant()).map(actor => { actors: game.actors.filter(actor => actor.isPersonnage() && actor.isHautRevant())
let actorData = duplicate(actor); .map(actor => ({
actorData.selected = actor.hasPlayerOwner; id: actor.id,
return actorData; name: actor.name,
}) selected: true
}))
}; };
const html = await renderTemplate("systems/foundryvtt-reve-de-dragon/templates/dialog-create-signedraconique.html", dialogData); const html = await renderTemplate("systems/foundryvtt-reve-de-dragon/templates/dialog-create-signedraconique.html", dialogData);
@ -23,12 +23,11 @@ export class DialogCreateSigneDraconique extends Dialog {
.render(true); .render(true);
} }
constructor(dialogData, html, callback) { constructor(dialogData, html) {
let options = { classes: ["DialogCreateSigneDraconiqueActorsActors"], width: 500, height: 650, 'z-index': 99999 }; let options = { classes: ["DialogCreateSigneDraconiqueActorsActors"], width: 500, height: 650, 'z-index': 99999 };
let conf = { let conf = {
title: "Créer un signe", title: "Créer un signe",
content: html, content: html,
default: "Ajouter aux haut-rêvants",
buttons: { buttons: {
"Ajouter aux haut-rêvants": { label: "Ajouter aux haut-rêvants", callback: it => { this._onCreerSigneActeurs(); } } "Ajouter aux haut-rêvants": { label: "Ajouter aux haut-rêvants", callback: it => { this._onCreerSigneActeurs(); } }
} }
@ -41,7 +40,8 @@ export class DialogCreateSigneDraconique extends Dialog {
await $("[name='signe.system.ephemere']").change(); await $("[name='signe.system.ephemere']").change();
await $(".signe-xp-sort").change(); await $(".signe-xp-sort").change();
this.validerSigne(); this.validerSigne();
this.dialogData.actors.filter(it => it.selected).map(it => game.actors.get(it._id)) this.dialogData.actors.filter(it => it.selected)
.map(it => game.actors.get(it.id))
.forEach(actor => this._createSigneForActor(actor, this.dialogData.signe)); .forEach(actor => this._createSigneForActor(actor, this.dialogData.signe));
} }
@ -64,7 +64,7 @@ export class DialogCreateSigneDraconique extends Dialog {
this.dialogData.signe.system.difficulte = $("[name='signe.system.difficulte']").val(); this.dialogData.signe.system.difficulte = $("[name='signe.system.difficulte']").val();
this.dialogData.signe.system.ephemere = $("[name='signe.system.ephemere']").prop("checked"); this.dialogData.signe.system.ephemere = $("[name='signe.system.ephemere']").prop("checked");
this.dialogData.signe.system.duree = $("[name='signe.system.duree']").val(); this.dialogData.signe.system.duree = $("[name='signe.system.duree']").val();
this.dialogData.signe.system.typesTMR = $(".select-tmr").val(); this.dialogData.signe.system.typesTMR = TMRUtility.buildListTypesTMRSelection(this.dialogData.tmrs);
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
@ -73,8 +73,9 @@ export class DialogCreateSigneDraconique extends Dialog {
this.setEphemere(this.dialogData.signe.system.ephemere); this.setEphemere(this.dialogData.signe.system.ephemere);
html.find(".signe-aleatoire").click(event => this.setSigneAleatoire()); html.find(".signe-aleatoire").click(event => this.setSigneAleatoire());
html.find("[name='signe.system.ephemere']").change((event) => this.setEphemere(event.currentTarget.checked)); html.find("[name='signe.system.ephemere']").change((event) => this.setEphemere(event.currentTarget.checked));
html.find(".select-actor").change((event) => this.onSelectActor(event));
html.find(".signe-xp-sort").change((event) => this.onValeurXpSort(event)); html.find(".signe-xp-sort").change((event) => this.onValeurXpSort(event));
html.find("input.select-actor").change((event) => this.onSelectActor(event));
html.find("input.select-tmr").change((event) => this.onSelectTmr(event));
} }
async setSigneAleatoire() { async setSigneAleatoire() {
@ -87,7 +88,10 @@ export class DialogCreateSigneDraconique extends Dialog {
$("[name='signe.system.difficulte']").val(newSigne.system.difficulte); $("[name='signe.system.difficulte']").val(newSigne.system.difficulte);
$("[name='signe.system.duree']").val(newSigne.system.duree); $("[name='signe.system.duree']").val(newSigne.system.duree);
$("[name='signe.system.ephemere']").prop("checked", newSigne.system.ephemere); $("[name='signe.system.ephemere']").prop("checked", newSigne.system.ephemere);
$(".select-tmr").val(newSigne.system.typesTMR); this.dialogData.tmrs = TMRUtility.buildSelectionTypesTMR(newSigne.system.typesTMR);
this.dialogData.tmrs.forEach(t => {
$(`[data-tmr-name='${t.name}']`).prop( "checked", t.selected);
})
this.setEphemere(newSigne.system.ephemere); this.setEphemere(newSigne.system.ephemere);
} }
@ -97,17 +101,22 @@ export class DialogCreateSigneDraconique extends Dialog {
} }
async onSelectActor(event) { async onSelectActor(event) {
event.preventDefault(); const actorId = $(event.currentTarget)?.data("actor-id");
const options = event.currentTarget.options; const actor = this.dialogData.actors.find(it => it.id == actorId);
for (var i = 0; i < options.length; i++) { // looping over the options
const actorId = options[i].attributes["data-actor-id"].value;
const actor = this.dialogData.actors.find(it => it._id == actorId);
if (actor) { if (actor) {
actor.selected = options[i].selected; actor.selected = event.currentTarget.checked;
} }
};
} }
onSelectTmr(event) {
const tmrName = $(event.currentTarget)?.data("tmr-name");
const onTmr = this.tmrs.find(it => it.name == tmrName);
if (onTmr){
onTmr.selected = event.currentTarget.checked;
}
}
onValeurXpSort(event) { onValeurXpSort(event) {
const codeReussite = event.currentTarget.attributes['data-typereussite']?.value ?? 0; const codeReussite = event.currentTarget.attributes['data-typereussite']?.value ?? 0;
const xp = Number(event.currentTarget.value); const xp = Number(event.currentTarget.value);

View File

@ -32,8 +32,7 @@ export class RdDSigneDraconiqueItemSheet extends ItemSheet {
const position = super.setPosition(options); const position = super.setPosition(options);
const sheetHeader = this.element.find(".sheet-header"); const sheetHeader = this.element.find(".sheet-header");
const sheetBody = this.element.find(".sheet-body"); const sheetBody = this.element.find(".sheet-body");
const bodyHeight = position.height - sheetHeader[0].clientHeight; sheetBody.css("height", position.height - sheetHeader[0].clientHeight)
sheetBody.css("height", bodyHeight);
return position; return position;
} }
@ -41,16 +40,17 @@ export class RdDSigneDraconiqueItemSheet extends ItemSheet {
/* -------------------------------------------- */ /* -------------------------------------------- */
async getData() { async getData() {
const formData = duplicate(this.item); const formData = duplicate(this.item);
this.tmrs = TMRUtility.buildSelectionTypesTMR(this.item.system.typesTMR);
mergeObject(formData, { mergeObject(formData, {
tmrs: this.tmrs,
title: formData.name, title: formData.name,
isGM: game.user.isGM, isGM: game.user.isGM,
owner: this.actor.isOwner, owner: this.actor?.isOwner,
isOwned: this.actor ? true : false, isOwned: this.actor ? true : false,
actorId: this.actor?.id, actorId: this.actor?.id,
editable: this.isEditable, editable: this.isEditable,
cssClass: this.isEditable ? "editable" : "locked", cssClass: this.isEditable ? "editable" : "locked",
}); });
formData.tmrs = TMRUtility.listSelectedTMR(formData.system.typesTMR ?? []);
return formData; return formData;
} }
@ -62,7 +62,7 @@ export class RdDSigneDraconiqueItemSheet extends ItemSheet {
if (!this.options.editable) return; if (!this.options.editable) return;
html.find(".signe-aleatoire").click(event => this.setSigneAleatoire()); html.find(".signe-aleatoire").click(event => this.setSigneAleatoire());
html.find(".select-tmr").change((event) => this.onSelectTmr(event)); html.find("input.select-tmr").change((event) => this.onSelectTmr(event));
html.find(".signe-xp-sort").change((event) => this.onValeurXpSort(event.currentTarget.attributes['data-typereussite']?.value, Number(event.currentTarget.value))); html.find(".signe-xp-sort").change((event) => this.onValeurXpSort(event.currentTarget.attributes['data-typereussite']?.value, Number(event.currentTarget.value)));
} }
@ -72,9 +72,13 @@ export class RdDSigneDraconiqueItemSheet extends ItemSheet {
} }
async onSelectTmr(event) { async onSelectTmr(event) {
event.preventDefault(); const tmrName = $(event.currentTarget)?.data("tmr-name");
const selectedTMR = $(".select-tmr").val(); const onTmr = this.tmrs.find(it => it.name == tmrName);
this.item.update({ 'system.typesTMR': selectedTMR }); if (onTmr){
onTmr.selected = event.currentTarget.checked;
}
this.item.update({ 'system.typesTMR': TMRUtility.buildListTypesTMRSelection(this.tmrs) });
} }
async onValeurXpSort(event) { async onValeurXpSort(event) {

View File

@ -358,10 +358,9 @@ export class RdDCommands {
async supprimerSignesDraconiquesEphemeres() { async supprimerSignesDraconiquesEphemeres() {
game.actors.forEach(actor => { game.actors.forEach(actor => {
const ephemeres = actor.items.find(item => item.type = 'signedraconique' && item.system.ephemere) const ephemeres = actor.items.filter(item => item.type = 'signedraconique' && item.system.ephemere);
.map(item => item.id);
if (ephemeres.length > 0) { if (ephemeres.length > 0) {
actor.deleteEmbeddedDocuments("Item", ephemeres); actor.deleteEmbeddedDocuments("Item", ephemeres.map(item => item.id));
} }
}); });
return true; return true;

View File

@ -25,7 +25,7 @@ export class RdDRollTables {
/* -------------------------------------------- */ /* -------------------------------------------- */
static async drawTextFromRollTable(tableName, toChat) { static async drawTextFromRollTable(tableName, toChat) {
const drawResult = await RdDRollTables.genericGetTableResult(tableName, toChat); const drawResult = await RdDRollTables.genericGetTableResult(tableName, toChat);
return drawResult.data.text; return drawResult.text;
} }
/* -------------------------------------------- */ /* -------------------------------------------- */

View File

@ -291,12 +291,18 @@ export class TMRUtility {
static typeTmrName(type) { static typeTmrName(type) {
return Misc.upperFirst(TMRType[Grammar.toLowerCaseNoAccent(type)].name); return Misc.upperFirst(TMRType[Grammar.toLowerCaseNoAccent(type)].name);
} }
static listSelectedTMR(typesTMR) {
static buildSelectionTypesTMR(typesTMR) {
typesTMR= typesTMR?? [];
return Object.values(TMRType).map(value => Misc.upperFirst(value.name)) return Object.values(TMRType).map(value => Misc.upperFirst(value.name))
.sort() .sort()
.map(name => { return { name: name, selected: typesTMR.includes(name) } }); .map(name => { return { name: name, selected: typesTMR.includes(name) } });
} }
static buildListTypesTMRSelection(selectionTMRs) {
return selectionTMRs.filter(it => it.selected).map(it => it.name).join(" ");
}
static isCaseHumide(tmr) { static isCaseHumide(tmr) {
return tmr.type == 'fleuve' || tmr.type == 'lac' || tmr.type == 'marais'; return tmr.type == 'fleuve' || tmr.type == 'lac' || tmr.type == 'marais';
} }

View File

@ -840,6 +840,14 @@ ul, li {
margin-left: 3rem; margin-left: 3rem;
} }
.grid-select-type-tmr {
display: grid;
grid-column: span 4 / span 4;
grid-template-columns: repeat(4, minmax(0, 1fr));
gap: 0.1rem;
margin: 0.1rem;
padding: 0;
}
.grid-select-actor { .grid-select-actor {
display: grid; display: grid;
grid-column: span 2 / span 2; grid-column: span 2 / span 2;

View File

@ -31,22 +31,31 @@
<input type="text" name="signe.system.duree" value="{{signe.system.duree}}" data-dtype="String" /> <input type="text" name="signe.system.duree" value="{{signe.system.duree}}" data-dtype="String" />
</span> </span>
</div> </div>
<hr>
<label>Terres médianes</label>
<div class="form-group"> <div class="form-group">
<label for="tmrs">Terres médianes</label> <div class="grid-select-type-tmr">
<select class="select-tmr" name="tmrs" id="tmrs" size="{{tmrs.length}}" multiple>
{{#each tmrs as |tmr key|}} {{#each tmrs as |tmr key|}}
<option value="{{tmr.name}}" {{#if tmr.selected}}selected{{/if}}>{{tmr.name}}</option> <label class="flexrow">
<input type="checkbox" data-dtype="Boolean" class="select-tmr"
data-tmr-name="{{tmr.name}}" {{#if tmr.selected}}checked{{/if}} />
{{tmr.name}}
</label>
{{/each}} {{/each}}
</select>
</div> </div>
<div class="form-group"> </div>
<hr>
<label for="actors">Haut-rêvants concernés</label> <label for="actors">Haut-rêvants concernés</label>
<select class="select-actor" id="actors" size="7" multiple> <div class="form-group">
<div class="grid-select-actor">
{{#each actors as |actor key|}} {{#each actors as |actor key|}}
<option value="{{actor.name}}" data-actor-id="{{actor._id}}" {{#if actor.selected}}selected{{/if}}>{{actor.name}}</option> <label class="flexrow">
<input type="checkbox" data-dtype="Boolean" class="select-actor"
data-actor-id="{{actor.id}}" {{#if actor.selected}}checked{{/if}} />
{{actor.name}}
</label>
{{/each}} {{/each}}
</select>
</div> </div>
</div>
<hr>
</form> </form>

View File

@ -37,13 +37,17 @@
<input class="attribute-value" type="text" name="system.duree" value="{{system.duree}}" data-dtype="String" /> <input class="attribute-value" type="text" name="system.duree" value="{{system.duree}}" data-dtype="String" />
</div> </div>
{{/if}} {{/if}}
<label>Terres médianes</label>
<div class="form-group"> <div class="form-group">
<label for="tmrs">Terres médianes</label> <div class="grid-select-type-tmr">
<select class="select-tmr attribute-value" name="tmrs" id="tmrs" size={{tmrs.length}} multiple />
{{#each tmrs as |tmr key|}} {{#each tmrs as |tmr key|}}
<option class="option-tmr" value="{{tmr.name}}" {{#if tmr.selected}}selected{{/if}}>{{tmr.name}}</option> <label class="flexrow">
<input type="checkbox" data-dtype="Boolean" class="select-tmr"
data-tmr-name="{{tmr.name}}" {{#if tmr.selected}}checked{{/if}} />
{{tmr.name}}
</label>
{{/each}} {{/each}}
</select> </div>
</div> </div>
{{>"systems/foundryvtt-reve-de-dragon/templates/partial-item-description.html"}} {{>"systems/foundryvtt-reve-de-dragon/templates/partial-item-description.html"}}