Extract Switch._createTrackConnections method

# Conflicts:
#	src/model/switch.js
This commit is contained in:
dominik-korsa 2025-07-19 13:58:11 +02:00
parent e1d1540f9e
commit aea4e53760
No known key found for this signature in database
GPG Key ID: 5A24D76EE0A30974

View File

@ -28,8 +28,10 @@ export default class Switch extends SceneryObject {
Object.assign(this, {
model,
data,
id_switch, id_isolation,
maxspeed, derailspeed,
id_switch,
id_isolation,
maxspeed,
derailspeed,
track_prefab_name
});
@ -64,7 +66,7 @@ export default class Switch extends SceneryObject {
return;
}
let def = DefinedSwitches[this.bare_model] || null;
const def = DefinedSwitches[this.bare_model] || null;
if (!def) {
SceneryParserLog.warn('switchUndefinedModel', `Switch ${this.id} has an undefined model "${this.bare_model}"`);
@ -105,25 +107,16 @@ export default class Switch extends SceneryObject {
return ids;
}
_createSwitchTrackFromDef(scenery, switchDef, trackDef, ids) {
const rotRad = AngleHelper.rotationDegToRad(this.rot);
if (trackDef.dataIndex >= ids.length) {
SceneryParserLog.warn(
'switchMissingTrackId',
`Switch ${this.id} with model ${this.bare_model} is missing an id for the track at index ${trackDef.dataIndex}`,
);
return null;
}
const [trackId, prevId, nextId] = ids[trackDef.dataIndex];
_createTrackConnections(switchDef, trackDef, ids) {
const connections = [];
const [_, prevId, nextId] = ids[trackDef.dataIndex];
trackDef.connections.forEach((connection) => {
if (connection.type === SwitchTrackConnectionType.INTERNAL) {
const otherTrackDef = switchDef.tracks[connection.internalId];
if (!otherTrackDef) {
SceneryParserLog.warn(
'switchMissingTrackId',
`Switch prefab for model with model ${this.bare_model} of track ${this.id} does not have the internal track ${connection.internalId}`,
`Switch ${this.id} with model ${this.bare_model} does not have the internal track ${connection.internalId}`,
);
return;
}
@ -145,6 +138,20 @@ export default class Switch extends SceneryObject {
}
}
});
return connections;
}
_createSwitchTrackFromDef(scenery, switchDef, trackDef, ids) {
const rotRad = AngleHelper.rotationDegToRad(this.rot);
if (trackDef.dataIndex >= ids.length) {
SceneryParserLog.warn(
'switchMissingTrackId',
`Switch ${this.id} with model ${this.bare_model} is missing an id for the track at index ${trackDef.dataIndex}`,
);
return null;
}
const trackId = ids[trackDef.dataIndex][0];
const connections = this._createTrackConnections(switchDef, trackDef, ids);
const localEndPos = CurveHelper
.calculateCurveEndStandard(trackDef.radius, trackDef.length)