@massif/lancer-data 4.0.0-beta.17 → 4.0.0-beta.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/scripts/util.js CHANGED
@@ -1,232 +1,232 @@
1
- #!/usr/bin/env node
2
- const readline = require('readline');
3
-
4
- const fs = require('fs');
5
-
6
- const path = require('path');
7
-
8
- const folderPath = '../lib';
9
- const ignore = ['manufacturers.json', 'weapons.json', 'systems.json', 'mods.json'];
10
-
11
- const ignoreWords = ['{VAL}', '({VAL})', '{VAL}+', 'HP', 'GRIT', 'SP', 'AP', '(AP)'];
12
-
13
- function decapitalize() {
14
- function decap(string) {
15
- const words = string.split(' ');
16
- const capitalizedWords = words.map((word) => {
17
- if (ignoreWords.some((x) => x === word)) return word;
18
- else if (word === word.toUpperCase()) {
19
- return word.toLowerCase().replace(/\b\w/g, (l) => l.toUpperCase());
20
- } else {
21
- return word;
22
- }
23
- });
24
- const capitalizedString = capitalizedWords.join(' ');
25
- return capitalizedString;
26
- }
27
-
28
- fs.readdir(folderPath, (err, files) => {
29
- if (err) {
30
- console.error('Error reading folder:', err);
31
- return;
32
- }
33
-
34
- files.forEach((file) => {
35
- if (ignore.some((x) => x === file)) return;
36
- const filePath = path.join(folderPath, file);
37
- console.log(filePath);
38
-
39
- fs.readFile(filePath, 'utf8', (err, data) => {
40
- if (err) {
41
- console.error('Error reading file:', file, err);
42
- return;
43
- }
44
-
45
- try {
46
- let fixed = 0;
47
- const jsonObject = JSON.parse(data);
48
- if (Array.isArray(jsonObject)) {
49
- jsonObject.forEach((e) => {
50
- if (e.name) {
51
- if (e.name.includes('ERR:')) return;
52
- if (e.name === e.name.toUpperCase()) {
53
- const decapped = decap(e.name);
54
- if (e.name !== decapped) {
55
- // console.log('decapped:', e.name, decapped);
56
- e.name = decapped;
57
- fixed++;
58
- }
59
- }
60
- }
61
- });
62
- fs.writeFile(filePath, JSON.stringify(jsonObject, null, 2), (err) => {
63
- if (err) {
64
- console.error('Error writing file:', file, err);
65
- return;
66
- }
67
- });
68
-
69
- console.log(`fixed: ${fixed} in file: ${file}`);
70
- }
71
- } catch (err) {
72
- console.error('Error parsing JSON in file:', file, err);
73
- }
74
- });
75
- });
76
- });
77
- }
78
-
79
- function collapseEffect() {
80
- fs.readdir(folderPath, (err, files) => {
81
- if (err) {
82
- console.error('Error reading directory:', err);
83
- return;
84
- }
85
-
86
- files.forEach((file) => {
87
- if (path.extname(file) === '.json') {
88
- const filePath = path.join(folderPath, file);
89
-
90
- fs.readFile(filePath, 'utf8', (err, data) => {
91
- if (err) {
92
- console.error(`Error reading file ${file}:`, err);
93
- return;
94
- }
95
-
96
- try {
97
- let jsonData = JSON.parse(data);
98
- let modified = false;
99
-
100
- jsonData = jsonData.map((obj) => {
101
- if (obj.hasOwnProperty('effect') && typeof obj.effect === 'object') {
102
- obj.effect = obj.effect.description;
103
- modified = true;
104
- }
105
- return obj;
106
- });
107
-
108
- if (modified) {
109
- fs.writeFile(filePath, JSON.stringify(jsonData, null, 2), 'utf8', (err) => {
110
- if (err) {
111
- console.error(`Error writing file ${file}:`, err);
112
- } else {
113
- console.log(`Updated ${file}`);
114
- }
115
- });
116
- }
117
- } catch (parseError) {
118
- console.error(`Error parsing JSON in file ${file}:`, parseError);
119
- }
120
- });
121
- }
122
- });
123
- });
124
- }
125
-
126
- async function collectEffects() {
127
- const collection = {
128
- active_effects: [],
129
- add_status: [],
130
- add_special: [],
131
- remove_special: [],
132
- add_resist: [],
133
- damage: [],
134
- range: [],
135
- save: [],
136
- bonus_damage: [],
137
- };
138
-
139
- fs.readdir(folderPath, (err, files) => {
140
- if (err) {
141
- console.error('Error reading directory:', err);
142
- return;
143
- }
144
-
145
- const promises = [];
146
-
147
- files.forEach((file) => {
148
- if (path.extname(file) === '.json') {
149
- const filePath = path.join(folderPath, file);
150
- promises.push(
151
- fs.readFile(filePath, 'utf8', (err, data) => {
152
- if (err) {
153
- console.error(`Error reading file ${file}:`, err);
154
- return;
155
- }
156
- try {
157
- const jsonData = JSON.parse(data);
158
- if (!Array.isArray(jsonData)) return;
159
- console.log(`Processing ${file} with ${jsonData.length} entries`);
160
- jsonData.forEach((obj) => {
161
- const elemArr = [obj];
162
- if (obj.actions) elemArr.push(...obj.actions);
163
- if (obj.deployables) elemArr.push(...obj.deployables);
164
- elemArr.forEach((e) => {
165
- if (e.active_effects) {
166
- for (const effect of e.active_effects) {
167
- if (Object.keys(effect).length > 2) {
168
- collection.active_effects.push(effect);
169
- }
170
- }
171
- }
172
- if (e.add_status) collection.add_status.push(e.add_status);
173
- if (e.add_special) collection.add_special.push(e.add_special);
174
- if (e.remove_special) collection.remove_special.push(e.remove_special);
175
- if (e.add_resist) collection.add_resist.push(e.add_resist);
176
- if (e.damage) collection.damage.push(e.damage);
177
- if (e.range) collection.range.push(e.range);
178
- if (e.save) collection.save.push(e.save);
179
- if (e.bonus_damage) collection.bonus_damage.push(e.save);
180
- });
181
- });
182
- } catch (parseError) {
183
- console.error(`Error parsing JSON in file ${file}:`, parseError);
184
- }
185
- })
186
- );
187
- }
188
- });
189
- });
190
-
191
- await new Promise((resolve) => setTimeout(resolve, 2000)); // wait for all files to be processed
192
-
193
- await fs.writeFile(
194
- 'output/activeEffects.json',
195
- JSON.stringify(collection, null, 2),
196
- 'utf8',
197
- (err) => {
198
- if (err) {
199
- console.error('Error writing activeEffects.json:', err);
200
- } else {
201
- console.log('activeEffects.json updated');
202
- }
203
- }
204
- );
205
- }
206
-
207
- // run
208
-
209
- const functions = {
210
- 1: { name: 'Decapitalize Item names', fn: decapitalize },
211
- 2: { name: 'Collapse Effect Props', fn: collapseEffect },
212
- 3: { name: 'Collect Active Effects', fn: collectEffects },
213
- };
214
-
215
- console.log('Choose a function:');
216
- for (const key in functions) {
217
- console.log(`${key}. ${functions[key].name}`);
218
- }
219
-
220
- const rl = readline.createInterface({
221
- input: process.stdin,
222
- output: process.stdout,
223
- });
224
-
225
- rl.question('> ', (answer) => {
226
- if (functions[answer]) {
227
- functions[answer].fn();
228
- } else {
229
- console.log('Invalid choice.');
230
- }
231
- rl.close();
232
- });
1
+ #!/usr/bin/env node
2
+ const readline = require('readline');
3
+
4
+ const fs = require('fs');
5
+
6
+ const path = require('path');
7
+
8
+ const folderPath = '../lib';
9
+ const ignore = ['manufacturers.json', 'weapons.json', 'systems.json', 'mods.json'];
10
+
11
+ const ignoreWords = ['{VAL}', '({VAL})', '{VAL}+', 'HP', 'GRIT', 'SP', 'AP', '(AP)'];
12
+
13
+ function decapitalize() {
14
+ function decap(string) {
15
+ const words = string.split(' ');
16
+ const capitalizedWords = words.map((word) => {
17
+ if (ignoreWords.some((x) => x === word)) return word;
18
+ else if (word === word.toUpperCase()) {
19
+ return word.toLowerCase().replace(/\b\w/g, (l) => l.toUpperCase());
20
+ } else {
21
+ return word;
22
+ }
23
+ });
24
+ const capitalizedString = capitalizedWords.join(' ');
25
+ return capitalizedString;
26
+ }
27
+
28
+ fs.readdir(folderPath, (err, files) => {
29
+ if (err) {
30
+ console.error('Error reading folder:', err);
31
+ return;
32
+ }
33
+
34
+ files.forEach((file) => {
35
+ if (ignore.some((x) => x === file)) return;
36
+ const filePath = path.join(folderPath, file);
37
+ console.log(filePath);
38
+
39
+ fs.readFile(filePath, 'utf8', (err, data) => {
40
+ if (err) {
41
+ console.error('Error reading file:', file, err);
42
+ return;
43
+ }
44
+
45
+ try {
46
+ let fixed = 0;
47
+ const jsonObject = JSON.parse(data);
48
+ if (Array.isArray(jsonObject)) {
49
+ jsonObject.forEach((e) => {
50
+ if (e.name) {
51
+ if (e.name.includes('ERR:')) return;
52
+ if (e.name === e.name.toUpperCase()) {
53
+ const decapped = decap(e.name);
54
+ if (e.name !== decapped) {
55
+ // console.log('decapped:', e.name, decapped);
56
+ e.name = decapped;
57
+ fixed++;
58
+ }
59
+ }
60
+ }
61
+ });
62
+ fs.writeFile(filePath, JSON.stringify(jsonObject, null, 2), (err) => {
63
+ if (err) {
64
+ console.error('Error writing file:', file, err);
65
+ return;
66
+ }
67
+ });
68
+
69
+ console.log(`fixed: ${fixed} in file: ${file}`);
70
+ }
71
+ } catch (err) {
72
+ console.error('Error parsing JSON in file:', file, err);
73
+ }
74
+ });
75
+ });
76
+ });
77
+ }
78
+
79
+ function collapseEffect() {
80
+ fs.readdir(folderPath, (err, files) => {
81
+ if (err) {
82
+ console.error('Error reading directory:', err);
83
+ return;
84
+ }
85
+
86
+ files.forEach((file) => {
87
+ if (path.extname(file) === '.json') {
88
+ const filePath = path.join(folderPath, file);
89
+
90
+ fs.readFile(filePath, 'utf8', (err, data) => {
91
+ if (err) {
92
+ console.error(`Error reading file ${file}:`, err);
93
+ return;
94
+ }
95
+
96
+ try {
97
+ let jsonData = JSON.parse(data);
98
+ let modified = false;
99
+
100
+ jsonData = jsonData.map((obj) => {
101
+ if (obj.hasOwnProperty('effect') && typeof obj.effect === 'object') {
102
+ obj.effect = obj.effect.description;
103
+ modified = true;
104
+ }
105
+ return obj;
106
+ });
107
+
108
+ if (modified) {
109
+ fs.writeFile(filePath, JSON.stringify(jsonData, null, 2), 'utf8', (err) => {
110
+ if (err) {
111
+ console.error(`Error writing file ${file}:`, err);
112
+ } else {
113
+ console.log(`Updated ${file}`);
114
+ }
115
+ });
116
+ }
117
+ } catch (parseError) {
118
+ console.error(`Error parsing JSON in file ${file}:`, parseError);
119
+ }
120
+ });
121
+ }
122
+ });
123
+ });
124
+ }
125
+
126
+ async function collectEffects() {
127
+ const collection = {
128
+ active_effects: [],
129
+ add_status: [],
130
+ add_special: [],
131
+ remove_special: [],
132
+ add_resist: [],
133
+ damage: [],
134
+ range: [],
135
+ save: [],
136
+ bonus_damage: [],
137
+ };
138
+
139
+ fs.readdir(folderPath, (err, files) => {
140
+ if (err) {
141
+ console.error('Error reading directory:', err);
142
+ return;
143
+ }
144
+
145
+ const promises = [];
146
+
147
+ files.forEach((file) => {
148
+ if (path.extname(file) === '.json') {
149
+ const filePath = path.join(folderPath, file);
150
+ promises.push(
151
+ fs.readFile(filePath, 'utf8', (err, data) => {
152
+ if (err) {
153
+ console.error(`Error reading file ${file}:`, err);
154
+ return;
155
+ }
156
+ try {
157
+ const jsonData = JSON.parse(data);
158
+ if (!Array.isArray(jsonData)) return;
159
+ console.log(`Processing ${file} with ${jsonData.length} entries`);
160
+ jsonData.forEach((obj) => {
161
+ const elemArr = [obj];
162
+ if (obj.actions) elemArr.push(...obj.actions);
163
+ if (obj.deployables) elemArr.push(...obj.deployables);
164
+ elemArr.forEach((e) => {
165
+ if (e.active_effects) {
166
+ for (const effect of e.active_effects) {
167
+ if (Object.keys(effect).length > 2) {
168
+ collection.active_effects.push(effect);
169
+ }
170
+ }
171
+ }
172
+ if (e.add_status) collection.add_status.push(e.add_status);
173
+ if (e.add_special) collection.add_special.push(e.add_special);
174
+ if (e.remove_special) collection.remove_special.push(e.remove_special);
175
+ if (e.add_resist) collection.add_resist.push(e.add_resist);
176
+ if (e.damage) collection.damage.push(e.damage);
177
+ if (e.range) collection.range.push(e.range);
178
+ if (e.save) collection.save.push(e.save);
179
+ if (e.bonus_damage) collection.bonus_damage.push(e.save);
180
+ });
181
+ });
182
+ } catch (parseError) {
183
+ console.error(`Error parsing JSON in file ${file}:`, parseError);
184
+ }
185
+ })
186
+ );
187
+ }
188
+ });
189
+ });
190
+
191
+ await new Promise((resolve) => setTimeout(resolve, 2000)); // wait for all files to be processed
192
+
193
+ await fs.writeFile(
194
+ 'output/activeEffects.json',
195
+ JSON.stringify(collection, null, 2),
196
+ 'utf8',
197
+ (err) => {
198
+ if (err) {
199
+ console.error('Error writing activeEffects.json:', err);
200
+ } else {
201
+ console.log('activeEffects.json updated');
202
+ }
203
+ }
204
+ );
205
+ }
206
+
207
+ // run
208
+
209
+ const functions = {
210
+ 1: { name: 'Decapitalize Item names', fn: decapitalize },
211
+ 2: { name: 'Collapse Effect Props', fn: collapseEffect },
212
+ 3: { name: 'Collect Active Effects', fn: collectEffects },
213
+ };
214
+
215
+ console.log('Choose a function:');
216
+ for (const key in functions) {
217
+ console.log(`${key}. ${functions[key].name}`);
218
+ }
219
+
220
+ const rl = readline.createInterface({
221
+ input: process.stdin,
222
+ output: process.stdout,
223
+ });
224
+
225
+ rl.question('> ', (answer) => {
226
+ if (functions[answer]) {
227
+ functions[answer].fn();
228
+ } else {
229
+ console.log('Invalid choice.');
230
+ }
231
+ rl.close();
232
+ });