Properly connect route tracks

This commit is contained in:
dominik-korsa 2025-07-12 16:04:58 +02:00
parent e78c1ccde5
commit 60e2f1f8fa
No known key found for this signature in database
GPG Key ID: 5A24D76EE0A30974
3 changed files with 19 additions and 6 deletions

View File

@ -2,6 +2,7 @@ import SceneryObject from "./scenery-object";
import Vector3 from "./vector3";
import SceneryParserLog from "./scenery-parser-log";
import RouteTrack from "./tracks/route-track";
import TrackConnection, {TrackConnectionEnd} from "./track-connection";
export default class Route extends SceneryObject {
track_count;
@ -101,18 +102,30 @@ export default class Route extends SceneryObject {
lengths[index],
radii[index],
[], // connections
this.electrified,
this, // route
);
});
if (this.segments.length >= 2) {
const prevSegment = this.segments[this.segments.length - 2];
const newSegment = this.segments[this.segments.length - 1];
newSegment.tracks.forEach((track, index) => {
const prevTrack = prevSegment.tracks[index];
track.connections.push(new TrackConnection(prevTrack.id, TrackConnectionEnd.START));
prevTrack.connections.push(new TrackConnection(track.id, TrackConnectionEnd.END));
});
}
this.segments.push({ length, radius, trackIds, tracks });
}
// This method is future-proofed for more than 2 tracks
_getOffsets() {
const leftmost_offset = -(this.track_count - 1) * 2 + this.track_offset;
const leftmost_offset = (this.track_count - 1) * 2 + this.track_offset;
const result = [];
for (let i = 0; i < this.track_count; i++) {
result.push(leftmost_offset + i * 4);
result.push(leftmost_offset - i * 4);
}
return result;
}

View File

@ -174,9 +174,9 @@ export default class SceneryParser {
const trackIds = fields[3]
.split(',')
.map(segment => {
const id = segment.split(':')[0];
if (!id) return null;
return parseInt(id);
const id = segment.split(':')[0].trim();
if (id === '') return null;
return id;
});
if (trackIds.some(id => id === null || isNaN(id))) {
SceneryParserLog.warn('routeInvalidSegment', `Invalid route segment track IDs: ${fields[3]}`);

View File

@ -7,7 +7,7 @@ export default class RouteTrack extends Track {
points;
route;
constructor(id, start, end, rot, len, r, connections, route, electrified) {
constructor(id, start, end, rot, len, r, connections, electrified, route) {
super(
id, start, rot, len, r, connections,
null, // id_station,