xkhofmann-tfdidesign-md11-f.../scripts/extractNodesForTooltips.mjs

71 lines
2.0 KiB
JavaScript

import fs from "node:fs";
import path from "node:path";
const paths = [
"..\\PackageSources\\ModelBehaviorDefs\\TFDi_Design\\MD11\\Cabin",
"..\\PackageSources\\ModelBehaviorDefs\\TFDi_Design\\MD11\\FlightDeck",
];
let excludes = [
"MD11_Bin",
"MD11_Cabin_WindowBlinds",
"MD11_TrayTable",
"MD11_OxyMasksDoor",
"MD11_Cabin_Lighting",
"TFDi_Design_MD11_Annunciator",
"TFDi_Design_MD11_Vistag",
"MD11_Cabin_Oxygen_Masks_Viz",
"MD11_Cabin_Power_Viz",
"MD11_Animation",
"MD11_IntegralLighting_Template",
"MD11_Floodlight_bulbs",
"MD11_Yoke_Toggle",
"TFDi_Design_MD11_Clickspot",
"TFDi_Design_MD11_Volume_Knob_Light",
"MD11_Cabin_Seatbelt_Viz",
"MD11_Cabin_NoSmoking_Viz",
"TFDi_Design_MD11_Range_Template",
"TFDi_Design_MD11_Evac_Light",
];
excludes = excludes.map((exclude) => exclude.toLowerCase());
const objects = [];
paths.forEach((_path) => {
const files = fs.readdirSync(_path);
files.forEach((file) => {
const _file = fs.readFileSync(path.join(_path, file), {
encoding: "utf-8",
});
const lines = _file.split("\n");
let templateName;
let nodeID;
lines.forEach((line) => {
const _line = line.trim();
const open = [..._line.matchAll(/^<UseTemplate Name="(.*)">$/gi)];
const _nodeID = [..._line.matchAll(/^<NODE_ID>(.*)<\/NODE_ID>$/gi)];
const close = [..._line.matchAll(/^<\/UseTemplate/gi)];
if (open.length > 0) {
templateName = open[0][1];
if (excludes.includes(templateName.toLowerCase()))
templateName = undefined;
} else if (_nodeID.length > 0) {
nodeID = _nodeID[0][1];
} else if (close.length > 0 && templateName && nodeID) {
objects.push({ file, templateName, nodeID });
templateName = undefined;
nodeID = undefined;
}
});
});
});
const fd = fs.openSync("tooltips.csv", "w");
fs.writeSync(fd, "File|Template Name|Node ID|Tooltip\n");
objects.forEach((obj) => {
fs.writeSync(fd, `${obj.file}|${obj.templateName}|${obj.nodeID}|\n`);
});
fs.closeSync(fd);