-
Notifications
You must be signed in to change notification settings - Fork 21
/
import-learnsets.js
185 lines (161 loc) · 6.03 KB
/
import-learnsets.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
// import learnsets
// FROM: text in learnsets-g6
// TO: PS data/learnsets.js
require("sugar");
fs = require("fs");
var Tools = require('./tools.js');
var Learnsets = Tools.data.Learnsets;
// remove existing gen 6 data
for (var speciesid in Learnsets) {
if (!Learnsets[speciesid] || !Learnsets[speciesid].learnset) continue;
var learnset = Learnsets[speciesid].learnset;
for (var moveid in learnset) {
var sources = learnset[moveid];
for (var i=sources.length-1; i>=0; i--) {
if (sources[i].charAt(0) === '6') {
sources.splice(i, 1);
}
}
if (!sources.length) delete learnset[moveid];
}
}
// build learnsetsG6
var LearnsetsG6 = {};
for (var speciesid in Learnsets) {
LearnsetsG6[speciesid] = {learnset:{}};
for (var moveid in Learnsets[speciesid].learnset) {
LearnsetsG6[speciesid].learnset[moveid] = [];
}
}
// If modern computers didn't come standard with 4GB of RAM,
// I'd probably stream this
var input = ''+fs.readFileSync('learnsets-g6/learnsets-g6-A-to-C.txt');
input += ''+fs.readFileSync('learnsets-g6/learnsets-g6-D-to-I.txt');
input += ''+fs.readFileSync('learnsets-g6/learnsets-g6-J-to-O.txt');
input += ''+fs.readFileSync('learnsets-g6/learnsets-g6-P-to-R.txt');
input += ''+fs.readFileSync('learnsets-g6/learnsets-g6-S-to-Z.txt');
input = input.split('\n');
var speciesid = '';
var species = '';
var lastType = '';
var lastTypeCount = 0;
for (var i=0; i<input.length; i++) {
var line = input[i];
line = line.trim();
if (!line) continue;
if (line.charAt(0) === '(') continue; // this is a comment
if (line.charAt(0) === '=') {
speciesid = Tools.getTemplate(line).id;
if (speciesid.substr(0,6) === 'deoxys') speciesid = 'deoxys';
species = line;
lastType = '';
lastTypeCount = 0;
continue;
}
var parts = line.split(' - ');
if (!parts[0] || !parts[1] || parts.length != 2) {
console.log("Line '"+line+"' must be in the format 'Source - Move' for "+species);
continue;
}
var move = Tools.getMove(parts[1]);
if (!move.exists) {
console.log("Move '"+parts[1]+"' in '"+line+"' doesn't exist for "+species);
continue;
}
var typeString = parts[0].toLowerCase().replace(/ /g,'').replace('.','');
var type = '';
var level = '';
if (typeString.substr(0,2) in {tm:1,hm:1}) type = '6M';
else if (typeString === 'tutor') type = '6T';
else if (typeString === 'egg') type = '6E';
else if (typeString === 'moverelearner' || typeString === 'relearn' || typeString === 'mr' || typeString === 'l?' || typeString === '?') type = '6L0';
else if (typeString === 'start') type = '6L1';
else if (typeString.substr(0,5) === 'event') {
var eventNum = parseInt(typeString.substr(5), 10);
if (!eventNum && typeString.substr(5) !== '0') console.log("Source '"+parts[0]+"' in '"+line+"' requires event number for "+species);
type = '6S'+eventNum;
}
else if (typeString.substr(0,5) === 'level') {
level = typeString.substr(5);
}
else if (typeString.substr(0,3) === 'lvl') {
level = typeString.substr(3);
}
else if (typeString.substr(0,2) === 'lv') {
level = typeString.substr(2);
}
else if (typeString.substr(0,1) === 'l') {
level = typeString.substr(1);
}
if (!type && !level) level = typeString;
if (level) {
if (level.charAt(0) in {'<':1,'>':1,'?':1}) type = '6L0';
else if (/^[0-9]{1,3}$/.test(level)) type = '6L'+(parseInt(level, 10)||1);
}
if (!type) console.log("Source '"+parts[0]+"' in '"+line+"' not formatted correctly for "+species);
if (type) {
if (!Learnsets[speciesid]) {
if (Learnsets[speciesid] !== '') console.log("Pokemon '"+species+"' doesn't exist or shouldn't have a learnset.");
Learnsets[speciesid] = '';
continue;
}
if (type !== '6L1') {
lastTypeCount = 0;
} else if (lastType === type) {
lastTypeCount++;
} else {
lastTypeCount = 0;
}
lastType = type;
if (!Learnsets[speciesid].learnset[move.id]) Learnsets[speciesid].learnset[move.id] = [type];
else if (Learnsets[speciesid].learnset[move.id].indexOf(type) < 0) Learnsets[speciesid].learnset[move.id].push(type);
if (type.substr(0,2) === '6L') {
type = '6L'+Number(type.substr(2)).pad(3);
if (type === '6L001') type += String.fromCharCode(97+lastTypeCount);
}
if (!LearnsetsG6[speciesid].learnset[move.id]) LearnsetsG6[speciesid].learnset[move.id] = [type];
else if (LearnsetsG6[speciesid].learnset[move.id].indexOf(type) < 0) LearnsetsG6[speciesid].learnset[move.id].push(type);
}
}
// Fill out gen 5 level-up and TM data for fallback
// for (var speciesid in Learnsets) {
// if (!Tools.getTemplate(speciesid).isUnreleased) continue;
// var learnset = Learnsets[speciesid].learnset;
// for (var moveid in learnset) {
// if (LearnsetsG6[speciesid].learnset[moveid].length) continue;
// var sources = learnset[moveid];
// for (var i=sources.length-1; i>=0; i--) {
// if (sources[i].substr(0,2) === '5L') {
// LearnsetsG6[speciesid].learnset[moveid] = ['6L000'];
// Learnsets[speciesid].learnset[moveid].push('6L0');
// } else if ((sources[i] === '5M' && !(moveid in {allyswitch:1,telekinesis:1,workup:1,pluck:1})) || (sources[i] === '5T' && moveid in {roost:1, sleeptalk:1})) {
// LearnsetsG6[speciesid].learnset[moveid] = ['6M'];
// Learnsets[speciesid].learnset[moveid].push('6M');
// }
// }
// }
// }
var output = 'exports.BattleLearnsets = {\n';
for (var speciesid in Learnsets) {
var learnset = Learnsets[speciesid].learnset;
output += ' '+speciesid+':{learnset:{';
output += Object.keys(learnset).map(function(key) {
return (key==='return'?'"return"':key)+':'+JSON.stringify(learnset[key]);
}).join(',');
output += '}},\n';
}
output = output.substr(0, output.length-2)+'\n';
output += '};\n';
fs.writeFileSync('data/learnsets.js', output);
output = 'exports.BattleLearnsets = {\n';
for (var speciesid in LearnsetsG6) {
var learnset = LearnsetsG6[speciesid].learnset;
output += ' '+speciesid+':{learnset:{';
output += Object.keys(learnset).map(function(key) {
return (key==='return'?'"return"':key)+':'+JSON.stringify(learnset[key]);
}).join(',');
output += '}},\n';
}
output = output.substr(0, output.length-2)+'\n';
output += '};\n';
fs.writeFileSync('data/learnsets-g6.js', output);