diff --git a/src/model/switch.js b/src/model/switch.js index c9dc690..7610956 100644 --- a/src/model/switch.js +++ b/src/model/switch.js @@ -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)