forked from public/foundryvtt-reve-de-dragon
Liens de jets de dés dans le tchat
This commit is contained in:
72
module/apps/rdd-text-roll-editor.js
Normal file
72
module/apps/rdd-text-roll-editor.js
Normal file
@ -0,0 +1,72 @@
|
||||
import "./xregexp-all.js";
|
||||
import { SystemCompendiums } from "../settings/system-compendiums.js";
|
||||
import { ACTOR_TYPES } from "../item.js";
|
||||
import { TextRollAlchimie } from "./textroll/text-roll-alchimie.js";
|
||||
import { TextRollCaracCompetence } from "./textroll/text-roll-carac-competence.js";
|
||||
import { TextRollFormula } from "./textroll/text-roll-formula.js";
|
||||
import { TextRollManager } from "./textroll/text-roll-formatter.js";
|
||||
|
||||
const TEXT_ROLL_MANAGERS = [
|
||||
new TextRollAlchimie(),
|
||||
new TextRollCaracCompetence(),
|
||||
new TextRollFormula()];
|
||||
|
||||
export class RdDTextEditor {
|
||||
|
||||
static async enrichHTML(text, object) {
|
||||
const context = {
|
||||
text, object,
|
||||
competences: await SystemCompendiums.getCompetences(ACTOR_TYPES.personnage),
|
||||
}
|
||||
|
||||
for (let manager of TEXT_ROLL_MANAGERS) {
|
||||
context.code = manager.code
|
||||
context.template = manager.template
|
||||
context.text = await manager.onReplaceRoll(context);
|
||||
}
|
||||
|
||||
// TEXT_ROLL_MANAGERS.forEach(async manager => await RdDTextEditor._applyReplaceAll(manager, context))
|
||||
return await TextEditor.enrichHTML(context.text, {
|
||||
relativeTo: object,
|
||||
secrets: object?.isOwner,
|
||||
async: true
|
||||
})
|
||||
}
|
||||
|
||||
static async _applyReplaceAll(manager, context) {
|
||||
context.code = manager.code
|
||||
context.template = manager.template
|
||||
context.text = await manager.onReplaceRoll(context);
|
||||
return context.text
|
||||
}
|
||||
|
||||
static getEventElement(event) {
|
||||
return $(event.currentTarget)?.parents(".roll-text-link");
|
||||
}
|
||||
|
||||
static async rollText(event, actor) {
|
||||
const code = TextRollManager.getNode(event)?.data('code')
|
||||
const manager = TEXT_ROLL_MANAGERS.find(it => it.code == code)
|
||||
if (manager) {
|
||||
await manager.onRollText(event, actor)
|
||||
}
|
||||
}
|
||||
|
||||
static async chatRollText(event) {
|
||||
const node = TextRollManager.getNode(event);
|
||||
if (node) {
|
||||
const code = node.data('code')
|
||||
const param = node.data('json')
|
||||
const manager = TEXT_ROLL_MANAGERS.find(it => it.code == code)
|
||||
|
||||
const text = await TextRollManager.createRollText(manager.template,
|
||||
param, false)
|
||||
ChatMessage.create({
|
||||
content: text
|
||||
})
|
||||
}
|
||||
}
|
||||
static registerChatCallbacks(html) {
|
||||
html.find('.roll-text').click(async event => await RdDTextEditor.rollText(event))
|
||||
}
|
||||
}
|
@ -1,224 +0,0 @@
|
||||
import "./xregexp-all.js";
|
||||
import { RdDCarac } from "../rdd-carac.js";
|
||||
import { SystemCompendiums } from "../settings/system-compendiums.js";
|
||||
import { RdDItemCompetence } from "../item-competence.js";
|
||||
import { ACTOR_TYPES, ITEM_TYPES } from "../item.js";
|
||||
import { RdDUtility } from "../rdd-utility.js";
|
||||
import { Misc } from "../misc.js";
|
||||
import { RdDAlchimie } from "../rdd-alchimie.js";
|
||||
|
||||
const REGEX_ALCHIMIE_TERMES = "(?<termes>(\\w|-)+)"
|
||||
const REGEX_ALCHIMIE_MANIP = "(?<manip>(couleur|consistance))"
|
||||
const XREGEXP_ROLL_ALCHIMIE = XRegExp("@roll\\[" + REGEX_ALCHIMIE_MANIP + "\\s+" + REGEX_ALCHIMIE_TERMES + "\\]", 'giu')
|
||||
const XREGEXP_ROLL_ALCHIMIE_MANIP = XRegExp("@" + REGEX_ALCHIMIE_MANIP + "\\{" + REGEX_ALCHIMIE_TERMES + "\\}", '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 d'alchimie
|
||||
*/
|
||||
class TextRollAlchimie {
|
||||
static async onRollText(event, actor) {
|
||||
actor = TextRollAlchimie.getSelectedActor(actor)
|
||||
if (actor) {
|
||||
const recetteId = event.currentTarget.attributes['data-recette-id']?.value
|
||||
const manip = event.currentTarget.attributes['data-manip'].value
|
||||
const termes = event.currentTarget.attributes['data-termes'].value
|
||||
if (recetteId) {
|
||||
await actor.effectuerTacheAlchimie(recetteId, manip, termes)
|
||||
}
|
||||
else {
|
||||
const carac = RdDCarac.caracDetails(RdDAlchimie.getCaracTache(manip))
|
||||
const diff = RdDAlchimie.getDifficulte(termes)
|
||||
await actor.rollCaracCompetence(carac.code, 'Alchimie', diff)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static getSelectedActor(actor) {
|
||||
actor = actor ?? RdDUtility.getSelectedActor()
|
||||
if (actor && actor.type == ACTOR_TYPES.personnage) {
|
||||
return actor
|
||||
}
|
||||
return undefined
|
||||
}
|
||||
|
||||
static async onReplaceRoll(context) {
|
||||
const handler = new TextRollAlchimie(context)
|
||||
context.text = await handler.replaceManipulationAlchimie()
|
||||
}
|
||||
|
||||
constructor(context) {
|
||||
this.context = context
|
||||
}
|
||||
|
||||
async replaceManipulationAlchimie() {
|
||||
await XRegExp.forEach(this.context.text, XREGEXP_ROLL_ALCHIMIE, async (rollMatch, i) => await this._replaceOneAlchimie(rollMatch, i))
|
||||
await XRegExp.forEach(this.context.text, XREGEXP_ROLL_ALCHIMIE_MANIP, async (rollMatch, i) => await this._replaceOneAlchimie(rollMatch, i))
|
||||
return this.context.text
|
||||
}
|
||||
|
||||
async _replaceOneAlchimie(rollMatch, i) {
|
||||
if (rollMatch.termes && rollMatch.manip) {
|
||||
const manip = rollMatch.manip
|
||||
await this._replaceManip(manip, rollMatch, i)
|
||||
}
|
||||
}
|
||||
|
||||
async _replaceManip(manip, rollMatch, i) {
|
||||
const termes = rollMatch.termes
|
||||
const carac = RdDCarac.caracDetails(RdDAlchimie.getCaracTache(manip))
|
||||
const diff = RdDAlchimie.getDifficulte(termes)
|
||||
const recette = (this.context.object instanceof Item && this.context.object.type == ITEM_TYPES.recettealchimique) ? this.context.object : undefined
|
||||
const replacement = await renderTemplate(`systems/foundryvtt-reve-de-dragon/templates/apps/link-text-roll-alchimie.hbs`, {
|
||||
manip,
|
||||
termes,
|
||||
recette,
|
||||
carac,
|
||||
diff
|
||||
})
|
||||
this.context.text = this.context.text.replace(rollMatch[0], replacement);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* classe pour gérer les jets de caractéristique/compétence depuis
|
||||
* les journaux/descriptions
|
||||
*/
|
||||
class TextRollCaracCompetence {
|
||||
|
||||
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 actors = TextRollCaracCompetence.getSelectedActors(actor)
|
||||
actors.forEach(async it => await TextRollCaracCompetence.doRoll(it, caracCode, competence, diff))
|
||||
}
|
||||
}
|
||||
static async doRoll(actor, caracCode, competence, diff) {
|
||||
caracCode = actor.mapCarac(caracCode)
|
||||
if (competence) {
|
||||
if (actor.type == ACTOR_TYPES.personnage) {
|
||||
await actor.rollCaracCompetence(caracCode, competence, diff)
|
||||
}
|
||||
else {
|
||||
await actor.doRollCaracCompetence(caracCode, competence, diff)
|
||||
}
|
||||
}
|
||||
else {
|
||||
await actor.rollCarac(caracCode, { diff })
|
||||
}
|
||||
}
|
||||
|
||||
static async onReplaceRoll(context) {
|
||||
const handler = new TextRollCaracCompetence(context)
|
||||
context.text = await handler.replaceRollCaracCompetence()
|
||||
}
|
||||
|
||||
static getSelectedActors(actor) {
|
||||
const selected = canvas.tokens.controlled.map(it => it.actor).filter(it => it)
|
||||
if (selected.length > 0) {
|
||||
return selected
|
||||
}
|
||||
actor = actor ?? RdDUtility.getSelectedActor()
|
||||
if (actor) {
|
||||
return [actor]
|
||||
}
|
||||
return []
|
||||
}
|
||||
|
||||
constructor(context) {
|
||||
this.context = context
|
||||
}
|
||||
|
||||
async replaceRollCaracCompetence() {
|
||||
await XRegExp.forEach(this.context.text, XREGEXP_ROLL_CARAC_COMP, async (rollMatch, i) => await this._replaceOne(rollMatch, i))
|
||||
return this.context.text
|
||||
}
|
||||
|
||||
async _replaceOne(rollMatch, i) {
|
||||
const carac = RdDCarac.caracDetails(rollMatch.carac)
|
||||
if (carac) {
|
||||
const competence = rollMatch.competence ? RdDItemCompetence.findCompetence(this.context.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.context.text = this.context.text.replace(rollMatch[0], replacement)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* classe pour gérer les jets de dés (formules Foundry)
|
||||
*/
|
||||
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 competences = await SystemCompendiums.getCompetences(ACTOR_TYPES.personnage);
|
||||
const context = { text, competences, object }
|
||||
await TextRollAlchimie.onReplaceRoll(context)
|
||||
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) {
|
||||
const rollMode = event.currentTarget.attributes['data-roll-mode']?.value;
|
||||
switch (rollMode) {
|
||||
case 'foundry':
|
||||
return await TextRollFoundry.onRollText(event, actor)
|
||||
case 'carac':
|
||||
return await TextRollCaracCompetence.onRollText(event, actor)
|
||||
case 'alchimie':
|
||||
return await TextRollAlchimie.onRollText(event, actor)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
79
module/apps/textroll/text-roll-alchimie.js
Normal file
79
module/apps/textroll/text-roll-alchimie.js
Normal file
@ -0,0 +1,79 @@
|
||||
import "../xregexp-all.js";
|
||||
import { ACTOR_TYPES, ITEM_TYPES } from "../../item.js";
|
||||
import { RdDCarac } from "../../rdd-carac.js";
|
||||
import { RdDUtility } from "../../rdd-utility.js";
|
||||
import { RdDAlchimie } from "../../rdd-alchimie.js";
|
||||
import { TextRollManager } from "./text-roll-formatter.js";
|
||||
|
||||
const REGEX_ALCHIMIE_TERMES = "(?<termes>(\\w|-)+)"
|
||||
const REGEX_ALCHIMIE_MANIP = "(?<manip>(couleur|consistance))"
|
||||
const XREGEXP_ROLL_ALCHIMIE = XRegExp("@roll\\[" + REGEX_ALCHIMIE_MANIP + "\\s+" + REGEX_ALCHIMIE_TERMES + "\\]", 'giu')
|
||||
const XREGEXP_ROLL_ALCHIMIE_MANIP = XRegExp("@" + REGEX_ALCHIMIE_MANIP + "\\{" + REGEX_ALCHIMIE_TERMES + "\\}", 'giu')
|
||||
|
||||
/**
|
||||
* classe pour gérer les jets d'alchimie
|
||||
*/
|
||||
export class TextRollAlchimie {
|
||||
get code() { return 'alchimie' }
|
||||
get template() { return `systems/foundryvtt-reve-de-dragon/templates/apps/textroll/link-text-roll-alchimie.hbs` }
|
||||
|
||||
async onReplaceRoll(context) {
|
||||
const handler = new AlchimieTextBuilder(context)
|
||||
return await handler.replaceAll()
|
||||
}
|
||||
|
||||
async onRollText(event, actor) {
|
||||
actor = this.getSelectedActor(actor)
|
||||
if (actor) {
|
||||
const node = TextRollManager.getNode(event)
|
||||
const recetteId = node.data('recetteid')
|
||||
const manip = node.data('manip')
|
||||
const termes = node.data('termes')
|
||||
if (recetteId) {
|
||||
await actor.effectuerTacheAlchimie(recetteId, manip, termes)
|
||||
}
|
||||
else {
|
||||
const carac = RdDCarac.caracDetails(RdDAlchimie.getCaracTache(manip))
|
||||
const diff = RdDAlchimie.getDifficulte(termes)
|
||||
await actor.rollCaracCompetence(carac.code, 'Alchimie', diff)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
getSelectedActor(actor) {
|
||||
actor = actor ?? RdDUtility.getSelectedActor()
|
||||
if (actor && actor.type == ACTOR_TYPES.personnage) {
|
||||
return actor
|
||||
}
|
||||
return undefined
|
||||
}
|
||||
}
|
||||
|
||||
class AlchimieTextBuilder {
|
||||
constructor(context) {
|
||||
this.context = context
|
||||
}
|
||||
|
||||
async replaceAll() {
|
||||
await XRegExp.forEach(this.context.text, XREGEXP_ROLL_ALCHIMIE, async (rollMatch, i) => await this.replaceMatch(rollMatch, i))
|
||||
await XRegExp.forEach(this.context.text, XREGEXP_ROLL_ALCHIMIE_MANIP, async (rollMatch, i) => await this.replaceMatch(rollMatch, i))
|
||||
return this.context.text
|
||||
}
|
||||
|
||||
async replaceMatch(rollMatch, i) {
|
||||
if (rollMatch.termes && rollMatch.manip) {
|
||||
const manip = rollMatch.manip
|
||||
const termes = rollMatch.termes
|
||||
const carac = RdDCarac.caracDetails(RdDAlchimie.getCaracTache(manip))
|
||||
const diff = RdDAlchimie.getDifficulte(termes)
|
||||
const recette = (this.context.object instanceof Item && this.context.object.type == ITEM_TYPES.recettealchimique) ? this.context.object : undefined
|
||||
const replacement = await TextRollManager.createRollText(this.context.template,
|
||||
{
|
||||
code: this.context.code,
|
||||
manip, termes, carac, diff, recetteid: recette?.id,
|
||||
})
|
||||
this.context.text = this.context.text.replace(rollMatch[0], replacement);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
88
module/apps/textroll/text-roll-carac-competence.js
Normal file
88
module/apps/textroll/text-roll-carac-competence.js
Normal file
@ -0,0 +1,88 @@
|
||||
import "../xregexp-all.js";
|
||||
import { ACTOR_TYPES } from "../../item.js";
|
||||
import { RdDCarac } from "../../rdd-carac.js";
|
||||
import { RdDItemCompetence } from "../../item-competence.js";
|
||||
import { RdDUtility } from "../../rdd-utility.js";
|
||||
import { TextRollManager } from "./text-roll-formatter.js";
|
||||
|
||||
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')
|
||||
|
||||
/**
|
||||
* classe pour gérer les jets de caractéristique/compétence depuis
|
||||
* les journaux/descriptions
|
||||
*/
|
||||
export class TextRollCaracCompetence {
|
||||
get code() { return 'carac' }
|
||||
get template() { return `systems/foundryvtt-reve-de-dragon/templates/apps/textroll/link-text-roll-carac-competence.hbs` }
|
||||
|
||||
async onReplaceRoll(context) {
|
||||
const handler = new CaracCompetenceTextBuilder(context)
|
||||
return await handler.replaceAll()
|
||||
}
|
||||
|
||||
async onRollText(event, actor) {
|
||||
const node = TextRollManager.getNode(event)
|
||||
const caracCode = node.data('carac-code')
|
||||
if (caracCode) {
|
||||
const competence = node.data('competence')
|
||||
const diff = node.data('diff')
|
||||
const actors = this.getSelectedActors(actor)
|
||||
actors.forEach(async it => await this.doRoll(it, caracCode, competence, diff))
|
||||
}
|
||||
}
|
||||
|
||||
async doRoll(actor, caracCode, competence, diff) {
|
||||
caracCode = actor.mapCarac(caracCode)
|
||||
if (competence) {
|
||||
if (actor.type == ACTOR_TYPES.personnage) {
|
||||
await actor.rollCaracCompetence(caracCode, competence, diff)
|
||||
}
|
||||
else {
|
||||
await actor.doRollCaracCompetence(caracCode, competence, diff)
|
||||
}
|
||||
}
|
||||
else {
|
||||
await actor.rollCarac(caracCode, { diff })
|
||||
}
|
||||
}
|
||||
|
||||
getSelectedActors(actor) {
|
||||
const selected = canvas.tokens.controlled.map(it => it.actor).filter(it => it)
|
||||
if (selected.length > 0) {
|
||||
return selected
|
||||
}
|
||||
actor = actor ?? RdDUtility.getSelectedActor()
|
||||
if (actor) {
|
||||
return [actor]
|
||||
}
|
||||
return []
|
||||
}
|
||||
}
|
||||
|
||||
class CaracCompetenceTextBuilder {
|
||||
constructor(context) {
|
||||
this.context = context
|
||||
}
|
||||
|
||||
async replaceAll() {
|
||||
await XRegExp.forEach(this.context.text, XREGEXP_ROLL_CARAC_COMP, async (rollMatch, i) => await this.replaceMatch(rollMatch, i))
|
||||
return this.context.text
|
||||
}
|
||||
|
||||
async replaceMatch(rollMatch, i) {
|
||||
const carac = RdDCarac.caracDetails(rollMatch.carac)
|
||||
if (carac) {
|
||||
const competence = rollMatch.competence ? RdDItemCompetence.findCompetence(this.context.competences, rollMatch.competence) : undefined
|
||||
const replacement = await TextRollManager.createRollText(this.context.template,
|
||||
{
|
||||
code: this.context.code,
|
||||
carac: carac,
|
||||
competence: competence?.name,
|
||||
diff: rollMatch.diff,
|
||||
})
|
||||
this.context.text = this.context.text.replace(rollMatch[0], replacement)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
14
module/apps/textroll/text-roll-formatter.js
Normal file
14
module/apps/textroll/text-roll-formatter.js
Normal file
@ -0,0 +1,14 @@
|
||||
|
||||
export class TextRollManager {
|
||||
|
||||
static async createRollText(template, param, showLink = true) {
|
||||
return await renderTemplate(template, {
|
||||
param: param,
|
||||
options: { showlink: showLink }
|
||||
})
|
||||
}
|
||||
|
||||
static getNode(event) {
|
||||
return $(event.currentTarget)?.parents(".roll-text-link");
|
||||
}
|
||||
}
|
51
module/apps/textroll/text-roll-formula.js
Normal file
51
module/apps/textroll/text-roll-formula.js
Normal file
@ -0,0 +1,51 @@
|
||||
import "../xregexp-all.js";
|
||||
import { TextRollManager } from "./text-roll-formatter.js";
|
||||
|
||||
const REGEXP_ROLL_FORMULA = "(?<formula>[^\\[\\]]+)"
|
||||
const XREGEXP_ROLL_FORMULA = XRegExp("@roll\\[" + REGEXP_ROLL_FORMULA + "\\]", 'giu')
|
||||
|
||||
/**
|
||||
* classe pour gérer les jets de dés (formules Foundry)
|
||||
*/
|
||||
export class TextRollFormula {
|
||||
get code() { return 'formula' }
|
||||
get template() { return `systems/foundryvtt-reve-de-dragon/templates/apps/textroll/link-text-roll-formula.hbs` }
|
||||
|
||||
async onReplaceRoll(context) {
|
||||
const handler = new FormulaTextBuilder(context)
|
||||
return await handler.replaceAll()
|
||||
}
|
||||
|
||||
async onRollText(event, actor) {
|
||||
const node = TextRollManager.getNode(event)
|
||||
const rollFormula = node.data('roll-formula')
|
||||
if (rollFormula) {
|
||||
const roll = new Roll(rollFormula)
|
||||
await roll.evaluate()
|
||||
await roll.toMessage()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class FormulaTextBuilder {
|
||||
constructor(context) {
|
||||
this.context = context
|
||||
}
|
||||
|
||||
async replaceAll() {
|
||||
await XRegExp.forEach(this.context.text, XREGEXP_ROLL_FORMULA,
|
||||
async (rollMatch, i) => await this.replaceMatch(rollMatch, i))
|
||||
return this.context.text
|
||||
}
|
||||
|
||||
async replaceMatch(rollMatch, i) {
|
||||
if (rollMatch.formula) {
|
||||
const replacement = await TextRollManager.createRollText(this.context.template,
|
||||
{
|
||||
code: this.context.code,
|
||||
formula: rollMatch.formula,
|
||||
})
|
||||
this.context.text = this.context.text.replace(rollMatch[0], replacement)
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user