Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let fs = require("fs");
- let encounters = {};
- let lines = fs.readFileSync("./overworld.txt", "utf-8")
- .split("\n")
- .filter(l => l.trim());
- let location = null;
- let condition = null;
- let levelRange = null;
- for (let i = 0; i < lines.length; ++i) {
- let line = lines[i];
- if (line.startsWith("\t\t")) {
- line = line.trim();
- let matches = line.match(/- (.*)[ ]*\t(\d+)%/);
- if (!matches) {
- console.error("Error parsing line " + i);
- console.error(lines[i]);
- break;
- }
- let poke = matches[1].trim();
- let odds = parseInt(matches[2], 10);
- if (!encounters[poke]) {
- encounters[poke] = [];
- }
- encounters[poke].push({
- location: location,
- condition: condition,
- levelRange: levelRange,
- odds: odds,
- overworld: true,
- });
- } else if (line.startsWith("\t")) {
- line = line.trim();
- let matches = line.match(/(.*) \(Lv\. (\d+-\d+)\)/);
- if (!matches) {
- console.error("Error parsing line " + i);
- console.error(lines[i]);
- break;
- }
- condition = matches[1];
- levelRange = matches[2];
- } else {
- location = line.trim().substr(0, line.length - 2);
- }
- }
- lines = fs.readFileSync("./non-overworld.txt", "utf-8")
- .split("\n")
- .filter(l => l.trim());
- location = null;
- condition = null;
- levelRange = null;
- for (let i = 0; i < lines.length; ++i) {
- let line = lines[i];
- if (line.startsWith("\t\t")) {
- line = line.trim();
- let matches = line.match(/- (.*)[ ]*\t(\d+)%/);
- if (!matches) {
- console.error("Error parsing line " + i);
- console.error(lines[i]);
- break;
- }
- let poke = matches[1].trim();
- let odds = parseInt(matches[2], 10);
- if (!encounters[poke]) {
- encounters[poke] = [];
- }
- encounters[poke].push({
- location: location,
- condition: condition,
- levelRange: levelRange,
- odds: odds,
- overworld: false,
- });
- } else if (line.startsWith("\t")) {
- line = line.trim();
- let matches = line.match(/(.*) \(Lv\. (\d+-\d+)\)/);
- if (!matches) {
- console.error("Error parsing line " + i);
- console.error(lines[i]);
- break;
- }
- condition = matches[1];
- levelRange = matches[2];
- } else {
- location = line.trim().substr(0, line.length - 2);
- }
- }
- let finalResult = [];
- for (let poke in encounters) {
- if (encounters.hasOwnProperty(poke)) {
- finalResult.push({
- poke: poke,
- encounters: encounters[poke],
- });
- }
- }
- finalResult.sort((a, b) => a.poke.localeCompare(b.poke));
- // fs.writeFileSync("sword.json", JSON.stringify(finalResult, undefined, 2));
- fs.writeFileSync("shield.json", JSON.stringify(finalResult, undefined, 2));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement