Support @roll[2d6]
This commit is contained in:
parent
06aff9a3c0
commit
792558ac84
@ -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 journaux texte
|
||||||
- on peut ajouter des liens "jet de dés" dans les descriptions, notes, ...
|
- 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" 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
|
- 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
|
## 12.0.33 - la vieillesse d'Astrobazzarh
|
||||||
- retour de l'expérience pour les joueurs
|
- retour de l'expérience pour les joueurs
|
||||||
|
@ -48,7 +48,7 @@ export class RdDBaseActorReveSheet extends RdDBaseActorSheet {
|
|||||||
}
|
}
|
||||||
}], { renderSheet: true })
|
}], { 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) {
|
if (this.options.vueDetaillee) {
|
||||||
// On carac change
|
// On carac change
|
||||||
|
@ -4,50 +4,28 @@ import { SystemCompendiums } from "../settings/system-compendiums.js";
|
|||||||
import { RdDItemCompetence } from "../item-competence.js";
|
import { RdDItemCompetence } from "../item-competence.js";
|
||||||
import { ACTOR_TYPES } from "../item.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')
|
||||||
|
|
||||||
export class RdDTextEditor {
|
const REGEXP_ROLL_FORMULA = "(?<formula>[^\\[\\]]+)"
|
||||||
static async enrichHTML(text, object) {
|
const XREGEXP_ROLL_FORMULA = XRegExp("@roll\\[" + REGEXP_ROLL_FORMULA + "\\]", 'giu')
|
||||||
const rddTextEditor = new RdDTextEditor(text)
|
|
||||||
const replacedRolls = await rddTextEditor.replaceRolls()
|
/**
|
||||||
return await TextEditor.enrichHTML(replacedRolls, {
|
* classe pour gérer les jets de caractéristique/compétence depuis
|
||||||
relativeTo: object,
|
* les journaux/descriptions
|
||||||
secrets: object?.isOwner,
|
*/
|
||||||
async: true
|
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()
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(text) {
|
static async onRollText(event, actor) {
|
||||||
this.original = text
|
const caracCode = event.currentTarget.attributes['data-carac-code']?.value
|
||||||
}
|
if (caracCode) {
|
||||||
|
const competence = event.currentTarget.attributes['data-competence']?.value
|
||||||
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 diff = event.currentTarget.attributes['data-diff']?.value
|
||||||
|
|
||||||
const path = RdDCarac.caracDetails(caracCode)?.path
|
const path = RdDCarac.caracDetails(caracCode)?.path
|
||||||
@ -56,3 +34,83 @@ export class RdDTextEditor {
|
|||||||
.forEach(it => it.doRollCaracCompetence(caracCode, competence, diff))
|
.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 context = { text }
|
||||||
|
await TextRollCaracCompetence.onReplaceRoll(context)
|
||||||
|
await TextRollFoundry.onReplaceRoll(context)
|
||||||
|
return await TextEditor.enrichHTML(context.text, {
|
||||||
|
relativeTo: object,
|
||||||
|
secrets: object?.isOwner,
|
||||||
|
async: true
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
static async rollText(event, actor) {
|
||||||
|
await TextRollCaracCompetence.onRollText(event, actor)
|
||||||
|
await TextRollFoundry.onRollText(event, actor)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,13 +1,13 @@
|
|||||||
export const SYSTEM_RDD = 'foundryvtt-reve-de-dragon';
|
export const SYSTEM_RDD = 'foundryvtt-reve-de-dragon'
|
||||||
export const SYSTEM_SOCKET_ID = 'system.foundryvtt-reve-de-dragon';
|
export const SYSTEM_SOCKET_ID = 'system.foundryvtt-reve-de-dragon'
|
||||||
export const LOG_HEAD = 'RdD | ';
|
export const LOG_HEAD = 'RdD | '
|
||||||
|
|
||||||
export const HIDE_DICE = 'hide';
|
export const HIDE_DICE = 'hide'
|
||||||
export const SHOW_DICE = 'show';
|
export const SHOW_DICE = 'show'
|
||||||
|
|
||||||
export const ENTITE_INCARNE = 'incarne';
|
export const ENTITE_INCARNE = 'incarne'
|
||||||
export const ENTITE_NONINCARNE = 'nonincarne';
|
export const ENTITE_NONINCARNE = 'nonincarne'
|
||||||
export const ENTITE_BLURETTE = 'blurette';
|
export const ENTITE_BLURETTE = 'blurette'
|
||||||
|
|
||||||
export const RDD_CONFIG = {
|
export const RDD_CONFIG = {
|
||||||
niveauEthylisme : [
|
niveauEthylisme : [
|
||||||
|
@ -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('.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('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) => {
|
this.html.find('.alchimie-tache a').click((event) => {
|
||||||
let actor = this._getEventActor(event);
|
let actor = this._getEventActor(event);
|
||||||
if (actor) {
|
if (actor) {
|
||||||
|
@ -23,6 +23,6 @@ export class RdDJournalSheet extends JournalTextPageSheet {
|
|||||||
activateListeners(html) {
|
activateListeners(html) {
|
||||||
super.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))
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -76,6 +76,7 @@ import { AppPersonnageAleatoire } from "./actor/random/app-personnage-aleatoire.
|
|||||||
import { RdDActorExportSheet } from "./actor/export-scriptarium/actor-encart-sheet.js"
|
import { RdDActorExportSheet } from "./actor/export-scriptarium/actor-encart-sheet.js"
|
||||||
import { RdDStatBlockParser } from "./apps/rdd-import-stats.js"
|
import { RdDStatBlockParser } from "./apps/rdd-import-stats.js"
|
||||||
import { RdDJournalSheet } from "./journal/journal-sheet.js"
|
import { RdDJournalSheet } from "./journal/journal-sheet.js"
|
||||||
|
import { RdDTextEditor } from "./apps/rdd-text-roll.js"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* RdD system
|
* RdD system
|
||||||
|
@ -173,7 +173,7 @@ export class RdDRoll extends Dialog {
|
|||||||
this.updateRollResult(html);
|
this.updateRollResult(html);
|
||||||
this.html.find("[name='diffLibre']").val(this.rollData.diffLibre);
|
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
|
const competence = event.currentTarget.value
|
||||||
this.rollData.competence = this.rollData.competences.find(it => Grammar.equalsInsensitive(it.name, competence))
|
this.rollData.competence = this.rollData.competences.find(it => Grammar.equalsInsensitive(it.name, competence))
|
||||||
this.updateRollResult(html);
|
this.updateRollResult(html);
|
||||||
|
@ -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 competence}}data-competence="{{competence}}"{{/if~}}
|
||||||
{{#if diff}}data-diff="{{diff}}"{{/if~}}
|
{{#if diff}}data-diff="{{diff}}"{{/if~}}
|
||||||
data-carac-code="{{carac.code}}">
|
data-carac-code="{{carac.code}}">
|
3
templates/apps/link-text-roll-foundry.hbs
Normal file
3
templates/apps/link-text-roll-foundry.hbs
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
<span><a class="roll-text content-link" data-roll-foundry="{{formula}}">
|
||||||
|
{{~formula~}}
|
||||||
|
</a></span>
|
@ -1,7 +1,7 @@
|
|||||||
{{#if @root.competences}}
|
{{#if @root.competences}}
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="roll-carac-competence">Compétence</label>
|
<label for="roll-text">Compétence</label>
|
||||||
<select name="roll-carac-competence" class="roll-carac-competence" data-dtype="String">
|
<select name="roll-text" class="roll-text" data-dtype="String">
|
||||||
{{#select ''}}<option value="">Sans compétence</option>
|
{{#select ''}}<option value="">Sans compétence</option>
|
||||||
{{>"systems/foundryvtt-reve-de-dragon/templates/enum-competence.html"}}
|
{{>"systems/foundryvtt-reve-de-dragon/templates/enum-competence.html"}}
|
||||||
{{/select}}
|
{{/select}}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user