diff --git a/public/jdr/core.json b/public/jdr/core.json index a191504..e657e64 100644 --- a/public/jdr/core.json +++ b/public/jdr/core.json @@ -1,3 +1,8 @@ { - "name":"Règles de bases" + "name":"Règles de bases", + "vars":[ + {"name":"determination01","value":"Effet dépendant du JDR"}, + {"name":"determination19","value":"Effet dépendant du JDR"}, + {"name":"determination20","value":"Effet dépendant du JDR"} + ] } \ No newline at end of file diff --git a/public/jdr/erratum.json b/public/jdr/erratum.json index 0177fee..21230c4 100644 --- a/public/jdr/erratum.json +++ b/public/jdr/erratum.json @@ -19,5 +19,10 @@ ], "hideLinks":[ { "menu":10, "link":"rules/personnages/niveaux" } + ], + "vars":[ + {"name":"determination01","value":"Le personnage fait un jet d'apothéose (D100). Si réussite critique: apothéose, si échec critique, jet d'anomie, sinon +1 karma"}, + {"name":"determination19","value":"Le personnage fait un jet d'anomie"}, + {"name":"determination20","value":"Le personnage devient anomique"} ] } \ No newline at end of file diff --git a/public/rules/divers/afflictions.md b/public/rules/divers/afflictions.md index 2f672fa..c792320 100644 --- a/public/rules/divers/afflictions.md +++ b/public/rules/divers/afflictions.md @@ -149,7 +149,7 @@ Le jet de détermination se fait sur un D20. | Résultat | Effet | |:--------:|:------| -| 01 | Effet dépendant du JDR | +| 01 | {{determination01}} | | 02 | Le personnage gagne un point de karma | | 03-06 | Le personnage fait un jet de bénédiction. | | 07 | Le personnage reçoit la grâce de la royauté. | @@ -163,7 +163,7 @@ Le jet de détermination se fait sur un D20. | 15 | Les attaques de moral feront 1.5× plus d'effet | | 16-17 | Le personnage fait un jet de pestilence (si PV > PM) ou de panique (si PV < PM). | | 18 | Le personnage à un malus de deux éclat pour la partie. -| 19 | Effet dépendant du JDR | -| 20 | Effet dépendant du JDR | +| 19 | {{determination19}} | +| 20 | {{determination20}} | diff --git a/src/components/MarkdownFile.vue b/src/components/MarkdownFile.vue index 0e74bf1..8e44b5c 100644 --- a/src/components/MarkdownFile.vue +++ b/src/components/MarkdownFile.vue @@ -5,6 +5,7 @@ import { useTocStore } from "../stores/toc"; import axios from "axios"; import { useRoute } from "vue-router"; +import { useConfigStore } from "@/stores/config"; const props = defineProps<{ path: string; @@ -23,6 +24,7 @@ specialQuote.set("DANGER", { class: "danger", text: "Danger :" }); var renderer = new marked.Renderer(); const toc = useTocStore(); +const config = useConfigStore(); const route = useRoute(); var tocNbr = 1; @@ -40,7 +42,6 @@ renderer.heading = function (text, level, raw) { }; renderer.blockquote = function (quote) { - console.log(quote); var bqClass = ""; var newQuote = quote; for (const [key, quoteData] of specialQuote) { @@ -56,9 +57,37 @@ renderer.blockquote = function (quote) { return `
${newQuote}
`; }; +const variable = { + name: "variable", + level: "inline", // Is this a block-level or inline-level tokenizer? + start(src: string) { + return src.match(/{{/)?.index; + }, // Hint to Marked.js to stop and check for a match + tokenizer( + src: string + ): { type: string; raw: string; [index: string]: any } | undefined { + const rule = /\{\{([A-Za-z0-9_]+)\}\}/; // Regex for the complete token, anchor to string start + const match = rule.exec(src); + if (match) { + return { + // Token to generate + type: "variable", // Should match "name" above + raw: match[0], // Text to consume from the source + ["varName"]: match[1], + }; + } + }, + renderer(token: { type: string; raw: string; [index: string]: any }): string { + const varName = token["varName"] as string | null; + const value = `${config.getVar(varName ?? "")}`; + return value; + }, +}; + marked.setOptions({ renderer: renderer, }); +marked.use({ extensions: [variable] }); function refresh() { const markdownFileUrl = `/${props.path}.md`; @@ -72,7 +101,6 @@ function refresh() { .then((response) => { tocNbr = 1; htmlContent.value = marked.parse(response.data); - console.log(toc); }) .catch( () => @@ -83,7 +111,9 @@ function refresh() { } onMounted(() => { - refresh(); + setTimeout(() => { + refresh(); + }, 100); }); onBeforeUpdate(() => { diff --git a/src/stores/config.ts b/src/stores/config.ts index 3271b31..e3755e1 100644 --- a/src/stores/config.ts +++ b/src/stores/config.ts @@ -70,6 +70,17 @@ export const useConfigStore = defineStore("config", () => { } } + function getVar(name?: string): string { + if (name) { + for (const varData of jdrConfig?.value?.vars ?? []) { + if (varData.name === name) { + return varData.value; + } + } + } + return ""; + } + return { config, currentJdr, @@ -79,5 +90,6 @@ export const useConfigStore = defineStore("config", () => { loadJdr, resetJdr, isJdrLoaded, + getVar, }; }); diff --git a/src/types/JdrConfig.ts b/src/types/JdrConfig.ts index 72a044d..8d67365 100644 --- a/src/types/JdrConfig.ts +++ b/src/types/JdrConfig.ts @@ -5,4 +5,5 @@ export default interface JdrConfig { name: string; sidebar: LinkList[]; hideLinks: HideLink[]; + vars: { name: string; value: string }[]; }