Dizzy-AU/code/converter.js

31 lines
796 B
JavaScript
Raw Normal View History

2022-05-28 17:22:38 +00:00
const fs = require("fs");
2022-05-28 17:30:22 +00:00
var path = process.argv[2]
console.log(path);
2022-05-28 17:22:38 +00:00
2022-05-28 17:30:22 +00:00
var json = JSON.parse(fs.readFileSync(path + "/story/database.json", { encoding: "utf8" }));
2022-05-28 17:22:38 +00:00
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;
}
});
2022-05-28 17:30:22 +00:00
fs.writeFileSync(`${path}/story/human-readable/${v.id}.md`, mdTemp, {encoding: "utf8"});
2022-05-28 17:22:38 +00:00
})