forked from cmmcleod/coriolis-data
-
Notifications
You must be signed in to change notification settings - Fork 54
Expand file tree
/
Copy pathcheck_bulkhead_ids.js
More file actions
61 lines (49 loc) · 1.63 KB
/
check_bulkhead_ids.js
File metadata and controls
61 lines (49 loc) · 1.63 KB
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
#!/usr/bin/env node
const fs = require('fs');
const path = require('path');
function checkBulkheadIds() {
const shipsDir = path.join(__dirname, 'ships');
const shipFiles = fs.readdirSync(shipsDir)
.filter(f => f.endsWith('.json'))
.map(f => path.join(shipsDir, f));
const idUsage = {}; // Track which ships use which IDs
const shipBulkheads = {}; // Store all bulkhead IDs per ship
shipFiles.forEach(filePath => {
const filename = path.basename(filePath);
const content = fs.readFileSync(filePath, 'utf8');
const shipData = JSON.parse(content);
const shipId = Object.keys(shipData)[0];
const ship = shipData[shipId];
if (!ship.bulkheads || !Array.isArray(ship.bulkheads)) {
return;
}
const bulkheadIds = ship.bulkheads.map(b => b.id);
shipBulkheads[filename] = bulkheadIds;
bulkheadIds.forEach(id => {
if (!idUsage[id]) {
idUsage[id] = [];
}
idUsage[id].push(filename);
});
});
// Find duplicates
console.log('Duplicate bulkhead IDs:\n');
let hasDuplicates = false;
Object.keys(idUsage).sort().forEach(id => {
if (idUsage[id].length > 1) {
hasDuplicates = true;
console.log(`ID "${id}" used by ${idUsage[id].length} ships:`);
idUsage[id].forEach(ship => console.log(` - ${ship}`));
console.log('');
}
});
if (!hasDuplicates) {
console.log('No duplicate bulkhead IDs found!');
}
// Show all IDs for reference
console.log('\n\nAll ships and their bulkhead IDs:\n');
Object.keys(shipBulkheads).sort().forEach(ship => {
console.log(`${ship}: ${shipBulkheads[ship].join(', ')}`);
});
}
checkBulkheadIds();