Support @roll[2d6]

This commit is contained in:
Vincent Vandemeulebrouck 2025-01-11 17:32:43 +01:00
parent 06aff9a3c0
commit 792558ac84
11 changed files with 119 additions and 56 deletions

View File

@ -3,8 +3,9 @@
- on peut ajouter des liens "jet de dés" dans les journaux texte
- on peut ajouter des liens "jet de dés" dans les descriptions, notes, ...
- les liens "jet de dés" peuvent être utilisés pour un acteur, ou les items de l'acteurs
- les liens "jet de dés" d'"un item non lié à un acteur agit sur les tokens sélectionnés
- les liens "jet de dés" d'un item non lié à un acteur agit sur les tokens sélectionnés
- gestion des blocs secrets dans les descriptions
- on peut ajouter des liens "jet de dés" pour appeler une formule de foundry
## 12.0.33 - la vieillesse d'Astrobazzarh
- retour de l'expérience pour les joueurs

View File

@ -48,7 +48,7 @@ export class RdDBaseActorReveSheet extends RdDBaseActorSheet {
}
}], { renderSheet: true })
)
this.html.find('.roll-carac-competence').click(async event => await RdDTextEditor.rollText(event, this.actor))
this.html.find('.roll-text').click(async event => await RdDTextEditor.rollText(event, this.actor))
if (this.options.vueDetaillee) {
// On carac change

View File

@ -4,55 +4,113 @@ import { SystemCompendiums } from "../settings/system-compendiums.js";
import { RdDItemCompetence } from "../item-competence.js";
import { ACTOR_TYPES } from "../item.js";
const XREGEXP_ROLL = XRegExp("@roll\\[(?<carac>[A-Za-zÀ-ÖØ-öø-ÿ\\s\\-]+)(\\/(?<competence>[A-Za-zÀ-ÖØ-öø-ÿ\\s\\-]+))?(/(?<diff>[\\+\\-]?\\d+))?\\]", 'giu')
const REGEXP_ROLL_CARAC_COMP = "(?<carac>[A-Za-zÀ-ÖØ-öø-ÿ\\s\\-]+)(\\/(?<competence>[A-Za-zÀ-ÖØ-öø-ÿ\\s\\-]+))?(/(?<diff>[\\+\\-]?\\d+))?"
const XREGEXP_ROLL_CARAC_COMP = XRegExp("@roll\\[" + REGEXP_ROLL_CARAC_COMP + "\\]", 'giu')
const REGEXP_ROLL_FORMULA = "(?<formula>[^\\[\\]]+)"
const XREGEXP_ROLL_FORMULA = XRegExp("@roll\\[" + REGEXP_ROLL_FORMULA + "\\]", 'giu')
/**
* classe pour gérer les jets de caractéristique/compétence depuis
* les journaux/descriptions
*/
class TextRollCaracCompetence {
static async onReplaceRoll(context) {
const competences = await SystemCompendiums.getCompetences(ACTOR_TYPES.personnage);
const handler = new TextRollCaracCompetence(context.text, competences)
context.text = await handler.replaceRollCaracCompetence()
}
static async onRollText(event, actor) {
const caracCode = event.currentTarget.attributes['data-carac-code']?.value
if (caracCode) {
const competence = event.currentTarget.attributes['data-competence']?.value
const diff = event.currentTarget.attributes['data-diff']?.value
const path = RdDCarac.caracDetails(caracCode)?.path
const actors = actor ? [actor] : canvas.tokens.controlled.map(it => it.actor).filter(it => it)
actors.filter(it => foundry.utils.getProperty(it, path) != undefined)
.forEach(it => it.doRollCaracCompetence(caracCode, competence, diff))
}
}
constructor(text, competences) {
this.text = text
this.competences = competences
}
async replaceRollCaracCompetence() {
await XRegExp.forEach(this.text, XREGEXP_ROLL_CARAC_COMP, async (rollMatch, i) => await this._replaceOne(rollMatch, i))
return this.text
}
async _replaceOne(rollMatch, i) {
const carac = RdDCarac.caracDetails(rollMatch.carac)
if (carac) {
const competence = rollMatch.competence ? RdDItemCompetence.findCompetence(this.competences, rollMatch.competence) : undefined
const replacement = await renderTemplate(`systems/foundryvtt-reve-de-dragon/templates/apps/link-text-roll-carac-competence.hbs`, {
carac: carac,
competence: competence?.name,
diff: rollMatch.diff
})
this.text = this.text.replace(rollMatch[0], replacement)
}
}
}
class TextRollFoundry {
static async onReplaceRoll(context) {
const handler = new TextRollFoundry(context.text)
context.text = await handler.replaceRolls()
}
static async onRollText(event, actor) {
const rollFoundry = event.currentTarget.attributes['data-roll-foundry']?.value
if (rollFoundry) {
const roll = new Roll(rollFoundry)
await roll.evaluate()
await roll.toMessage()
}
}
constructor(text) {
this.text = text
}
async replaceRolls() {
await XRegExp.forEach(this.text, XREGEXP_ROLL_FORMULA, async (rollMatch, i) => await this._replaceOne(rollMatch, i))
return this.text
}
async _replaceOne(rollMatch, i) {
if (rollMatch.formula) {
const replacement = await renderTemplate(`systems/foundryvtt-reve-de-dragon/templates/apps/link-text-roll-foundry.hbs`, {
formula: rollMatch.formula,
})
this.text = this.text.replace(rollMatch[0], replacement)
}
}
}
export class RdDTextEditor {
static async enrichHTML(text, object) {
const rddTextEditor = new RdDTextEditor(text)
const replacedRolls = await rddTextEditor.replaceRolls()
return await TextEditor.enrichHTML(replacedRolls, {
const context = { text }
await TextRollCaracCompetence.onReplaceRoll(context)
await TextRollFoundry.onReplaceRoll(context)
return await TextEditor.enrichHTML(context.text, {
relativeTo: object,
secrets: object?.isOwner,
async: true
})
}
constructor(text) {
this.original = text
}
async replaceRolls() {
if (!this.updated) {
this.updated = this.original
await XRegExp.forEach(this.original, XREGEXP_ROLL, async (rollMatch, i) => await this._replaceOneRoll(rollMatch))
}
return this.updated
}
async _replaceOneRoll(rollMatch) {
const carac = RdDCarac.caracDetails(rollMatch.carac);
const competence = rollMatch.competence ? RdDItemCompetence.findCompetence(await SystemCompendiums.getCompetences(ACTOR_TYPES.personnage),
rollMatch.competence) : undefined
if (carac) {
const replacement = await renderTemplate(`systems/foundryvtt-reve-de-dragon/templates/apps/link-text-roll.hbs`, {
carac: carac,
competence: competence?.name,
diff: rollMatch.diff
});
this.updated = this.updated.replace(rollMatch[0], replacement);
}
}
static async rollText(event, actor) {
const caracCode = event.currentTarget.attributes['data-carac-code'].value;
const competence = event.currentTarget.attributes['data-competence']?.value;
const diff = event.currentTarget.attributes['data-diff']?.value
const path = RdDCarac.caracDetails(caracCode)?.path
const actors = actor ? [actor] : canvas.tokens.controlled.map(it => it.actor).filter(it => it)
actors.filter(it => foundry.utils.getProperty(it, path) != undefined)
.forEach(it => it.doRollCaracCompetence(caracCode, competence, diff))
await TextRollCaracCompetence.onRollText(event, actor)
await TextRollFoundry.onRollText(event, actor)
}
}

View File

@ -1,13 +1,13 @@
export const SYSTEM_RDD = 'foundryvtt-reve-de-dragon';
export const SYSTEM_SOCKET_ID = 'system.foundryvtt-reve-de-dragon';
export const LOG_HEAD = 'RdD | ';
export const SYSTEM_RDD = 'foundryvtt-reve-de-dragon'
export const SYSTEM_SOCKET_ID = 'system.foundryvtt-reve-de-dragon'
export const LOG_HEAD = 'RdD | '
export const HIDE_DICE = 'hide';
export const SHOW_DICE = 'show';
export const HIDE_DICE = 'hide'
export const SHOW_DICE = 'show'
export const ENTITE_INCARNE = 'incarne';
export const ENTITE_NONINCARNE = 'nonincarne';
export const ENTITE_BLURETTE = 'blurette';
export const ENTITE_INCARNE = 'incarne'
export const ENTITE_NONINCARNE = 'nonincarne'
export const ENTITE_BLURETTE = 'blurette'
export const RDD_CONFIG = {
niveauEthylisme : [

View File

@ -208,7 +208,7 @@ export class RdDItemSheet extends ItemSheet {
this.html.find('.creer-potion-base').click((event) => this._getEventActor(event).actionHerbe(this.item));
this.html.find('input[name="system.cacher_points_de_tache"]').change(async event => await this.item.update({ 'system.cacher_points_de_tache': event.currentTarget.checked }));
this.html.find('.roll-carac-competence').click(async event => await RdDTextEditor.rollText(event, this.actor))
this.html.find('.roll-text').click(async event => await RdDTextEditor.rollText(event, this.actor))
this.html.find('.alchimie-tache a').click((event) => {
let actor = this._getEventActor(event);
if (actor) {

View File

@ -23,6 +23,6 @@ export class RdDJournalSheet extends JournalTextPageSheet {
activateListeners(html) {
super.activateListeners(html);
html.find('.roll-carac-competence').click(async event => await RdDTextEditor.rollText(event, this.actor))
html.find('.roll-text').click(async event => await RdDTextEditor.rollText(event, this.actor))
}
}

View File

@ -76,6 +76,7 @@ import { AppPersonnageAleatoire } from "./actor/random/app-personnage-aleatoire.
import { RdDActorExportSheet } from "./actor/export-scriptarium/actor-encart-sheet.js"
import { RdDStatBlockParser } from "./apps/rdd-import-stats.js"
import { RdDJournalSheet } from "./journal/journal-sheet.js"
import { RdDTextEditor } from "./apps/rdd-text-roll.js"
/**
* RdD system

View File

@ -173,7 +173,7 @@ export class RdDRoll extends Dialog {
this.updateRollResult(html);
this.html.find("[name='diffLibre']").val(this.rollData.diffLibre);
});
this.html.find('.roll-carac-competence').change((event) => {
this.html.find('.roll-text').change((event) => {
const competence = event.currentTarget.value
this.rollData.competence = this.rollData.competences.find(it => Grammar.equalsInsensitive(it.name, competence))
this.updateRollResult(html);

View File

@ -1,4 +1,4 @@
<span><a class="roll-carac-competence content-link"
<span><a class="roll-text content-link"
{{#if competence}}data-competence="{{competence}}"{{/if~}}
{{#if diff}}data-diff="{{diff}}"{{/if~}}
data-carac-code="{{carac.code}}">

View File

@ -0,0 +1,3 @@
<span><a class="roll-text content-link" data-roll-foundry="{{formula}}">
{{~formula~}}
</a></span>

View File

@ -1,7 +1,7 @@
{{#if @root.competences}}
<div class="form-group">
<label for="roll-carac-competence">Compétence</label>
<select name="roll-carac-competence" class="roll-carac-competence" data-dtype="String">
<label for="roll-text">Compétence</label>
<select name="roll-text" class="roll-text" data-dtype="String">
{{#select ''}}<option value="">Sans compétence</option>
{{>"systems/foundryvtt-reve-de-dragon/templates/enum-competence.html"}}
{{/select}}