From 340ccfa3d1905523cea26e9f75a319c450e06a79 Mon Sep 17 00:00:00 2001 From: MeowcaTheoRange <58280776+MeowcaTheoRange@users.noreply.github.com> Date: Sat, 28 May 2022 12:22:38 -0500 Subject: [PATCH] Create converter.js --- code/converter.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 code/converter.js diff --git a/code/converter.js b/code/converter.js new file mode 100644 index 0000000..7c8a8df --- /dev/null +++ b/code/converter.js @@ -0,0 +1,28 @@ +const fs = require("fs"); + +var json = JSON.parse(fs.readFileSync("$GITHUB_WORKSPACE/story/database.json", { encoding: "utf8" })); + +json.forEach((v, i) => { + var mdTemp = `# ${v.scene}\n`; + var chars = { + "---": "---" + }; + v.appearing_characters.forEach((vv, vi) => { + chars[vv[0]] = vv[1]; + mdTemp += `- ${vv[1]}\n`; + }); + v.content.forEach((vv, vi) => { + switch (vv.type) { + case "message": + mdTemp += `\n### ${chars[vv.person]}\n`; + vv.content.forEach((vvv, vvi) => { + mdTemp += `\n> ${vvv}\n`; + }); + break; + case "break": + mdTemp += `\n -- ${vv.content} --\n`; + break; + } + }); + fs.writeFileSync(`$GITHUB_WORKSPACE/story/human-readable/${v.id}.md`, mdTemp, {encoding: "utf8"}); +})