Skip to content

Commit

Permalink
🛠️ test.js -> Updated filePath variable
Browse files Browse the repository at this point in the history
🛠️ test.js -> Renamed craftInfo.fields to craftInfo.parts
🛠️ test.js -> Added functionality to parse and write part information to a file
  • Loading branch information
g9aerospace committed Mar 14, 2024
1 parent 65c5bd0 commit 80bed03
Show file tree
Hide file tree
Showing 2 changed files with 166 additions and 6 deletions.
120 changes: 120 additions & 0 deletions part_list.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
Part: Mark1Cockpit_4294811528
Instance 1:

Part: linearRcs_4294811464
Instance 1:

Part: linearRcs_4294811426
Instance 1:

Part: SmallGearBay_4294811388
Instance 1:

Part: advSasModule_4294811210
Instance 1:

Part: dockingPortLateral_4294811182
Instance 1:

Part: RCSFuelTank_4294811106
Instance 1:

Part: R8winglet_4294809932
Instance 1:

Part: R8winglet_4294809894
Instance 1:

Part: batteryBank_4293934584
Instance 1:

Part: fuelTank.long_4294811080
Instance 1:

Part: fuelTank_4294810884
Instance 1:

Part: turboFanEngine_4294810852
Instance 1:

Part: SmallGearBay_4294810618
Instance 1:

Part: deltaWing_4294809682
Instance 1:

Part: linearRcs_4294809610
Instance 1:

Part: RCSBlock_4294809534
Instance 1:

Part: StandardCtrlSrf_4294809466
Instance 1:

Part: elevon2_4294809406
Instance 1:

Part: fuelLine_4294267148
Instance 1:

Part: shockConeIntake_4294445008
Instance 1:

Part: fuelTank_4294810408
Instance 1:

Part: turboFanEngine_4294810376
Instance 1:

Part: SmallGearBay_4294810142
Instance 1:

Part: deltaWing_4294805548
Instance 1:

Part: linearRcs_4294805510
Instance 1:

Part: RCSBlock_4294805458
Instance 1:

Part: StandardCtrlSrf_4294805376
Instance 1:

Part: elevon2_4294805342
Instance 1:

Part: fuelLine_4294810222
Instance 1:

Part: shockConeIntake_4294444846
Instance 1:

Part: structuralWing_4294809824
Instance 1:

Part: RCSBlock_4294809754
Instance 1:

Part: structuralWing_4294805734
Instance 1:

Part: RCSBlock_4294805698
Instance 1:

Part: MK1Fuselage_4294561332
Instance 1:

Part: delta.small_4292691204
Instance 1:

Part: elevon3_4292690220
Instance 1:

Part: toroidalAerospike_4294685750
Instance 1:

Part: SurfAntenna_4293951262
Instance 1:

52 changes: 46 additions & 6 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const readline = require('readline');
const path = require('path');

// Open file dialog to select a .craft file
const filePath = 'test.craft';
const filePath = 'test.craft'; // Replace 'example.craft' with the path to your craft file
const fileStream = fs.createReadStream(filePath);
const rl = readline.createInterface({
input: fileStream,
Expand All @@ -13,20 +13,60 @@ const rl = readline.createInterface({
// Initialize craftInfo object to store field-value pairs
const craftInfo = {
filename: path.basename(filePath),
fields: {}
parts: {}
};

// Read each line of the file
rl.on('line', (line) => {
// Split the line into field and value
const [field, value] = line.split('=');
if (field && value) {
craftInfo.fields[field.trim()] = value.trim();
// Check if the field is 'part' to identify parts
if (field.trim() === 'part') {
const partName = value.trim();
// Add part to the parts object
craftInfo.parts[partName] = craftInfo.parts[partName] || [];
// Add the current part's information to the array of parts
craftInfo.parts[partName].push(parsePartFields(line));
}
}
});

// When all lines are read, display the craft file information
// When all lines are read, write the part information to a file
rl.on('close', () => {
console.log('Craft File Information:');
console.log(craftInfo);
const outputFile = 'part_list.txt'; // Output file name
writePartListToFile(outputFile, craftInfo.parts);
console.log(`Part information written to ${outputFile}`);
});

// Function to parse the fields of a part line
function parsePartFields(line) {
const fields = {};
// Split the line into field and value
const parts = line.split('=');
parts.shift(); // Remove 'part' field
// Add each field-value pair to the fields object
parts.forEach(part => {
const [field, value] = part.split(':');
if (field && value) {
fields[field.trim()] = value.trim();
}
});
return fields;
}

// Function to write part information to a file
function writePartListToFile(outputFile, parts) {
let outputContent = '';
for (const partName in parts) {
outputContent += `Part: ${partName}\n`;
parts[partName].forEach((part, index) => {
outputContent += `Instance ${index + 1}:\n`;
for (const field in part) {
outputContent += `${field}: ${part[field]}\n`;
}
outputContent += '\n';
});
}
fs.writeFileSync(outputFile, outputContent);
}

0 comments on commit 80bed03

Please sign in to comment.