Create converter.js

This commit is contained in:
MeowcaTheoRange 2022-05-28 12:22:38 -05:00 committed by GitHub
parent 8bcba8c988
commit 340ccfa3d1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

28
code/converter.js Normal file
View file

@ -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"});
})