Add station data and parser for the script.
Need to do: - Write the StationIfno modal and enable toggling it's display.
This commit is contained in:
@@ -3,7 +3,9 @@ import fs from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
const inputDir = './static/mapFiles/yaml';
|
||||
const stationInputDir = './static/stations';
|
||||
const outputDir = './src/lib/assets/route';
|
||||
const stationOutputDir = './src/lib/assets/station';
|
||||
const indexFile = './static/map-index.json';
|
||||
|
||||
const noiseRegex = /\s+(single line|junction|jn|junc|jct|gf|north|south|east|west)\.?$/i;
|
||||
@@ -11,6 +13,23 @@ const noiseRegex = /\s+(single line|junction|jn|junc|jct|gf|north|south|east|wes
|
||||
if (!fs.existsSync(outputDir)) fs.mkdirSync(outputDir, { recursive: true });
|
||||
|
||||
const mapList = [];
|
||||
const stationList = [];
|
||||
|
||||
fs.readdirSync(stationInputDir).forEach((file) => {
|
||||
if (file.endsWith('.yaml')) {
|
||||
const fullPath = path.join(stationInputDir, file);
|
||||
const content = yaml.load(fs.readFileSync(fullPath, 'utf8'));
|
||||
|
||||
if (content.crs) {
|
||||
stationList.push(content.crs)
|
||||
}
|
||||
|
||||
const fileName = file.replace('.yaml', '.json');
|
||||
fs.writeFileSync(path.join(stationOutputDir, fileName), JSON.stringify(content));
|
||||
}
|
||||
});
|
||||
|
||||
console.log(`Found station declarations for the following: ${JSON.stringify(stationList)}`);
|
||||
|
||||
fs.readdirSync(inputDir).forEach((file) => {
|
||||
if (file.endsWith('.yaml')) {
|
||||
@@ -18,12 +37,19 @@ fs.readdirSync(inputDir).forEach((file) => {
|
||||
const content = yaml.load(fs.readFileSync(fullPath, 'utf8'));
|
||||
|
||||
const fileName = file.replace('.yaml', '.json');
|
||||
fs.writeFileSync(path.join(outputDir, fileName), JSON.stringify(content));
|
||||
|
||||
const contentSet = new Set();
|
||||
|
||||
|
||||
// Use this loop to add a 'link' to each station if its CRS exists in 'stationList'
|
||||
if (Array.isArray(content.routeDetail)) {
|
||||
content.routeDetail.forEach((item) => {
|
||||
if ((item.type === 'station') && (item.crs)) {
|
||||
// Edit the item if item.crs exists in 'stationList' - maybe a `linkable: true`?
|
||||
if (stationList.includes(item.crs)) {
|
||||
item.stationInfo = true;
|
||||
}
|
||||
}
|
||||
if ((item.type === 'junction' || item.type === 'station') && item.name) {
|
||||
let cleanName = item.name;
|
||||
|
||||
@@ -44,6 +70,8 @@ fs.readdirSync(inputDir).forEach((file) => {
|
||||
});
|
||||
}
|
||||
|
||||
fs.writeFileSync(path.join(outputDir, fileName), JSON.stringify(content));
|
||||
|
||||
mapList.push({
|
||||
routeId: content.routeId || null,
|
||||
routeStart: content.routeStart || null,
|
||||
@@ -55,6 +83,7 @@ fs.readdirSync(inputDir).forEach((file) => {
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
fs.writeFileSync(indexFile, JSON.stringify(mapList));
|
||||
|
||||
console.log(`Generated ${mapList.length} map files and index.`);
|
||||
|
||||
Reference in New Issue
Block a user