Improved switches

+Added support for the speedLimit field in switch definitions
*Updated defined-switches.js, removing unused fields and adding speedLimit
*Changed the header of StandardTrack.createSwitchTrack
This commit is contained in:
izawartka 2025-08-05 22:31:25 +02:00
parent 415878ba02
commit 5f57eb24ee
3 changed files with 488 additions and 487 deletions

File diff suppressed because it is too large Load Diff

View File

@ -80,7 +80,7 @@ export default class Switch extends SceneryObject {
const trackIds = this._getTrackIds(); const trackIds = this._getTrackIds();
if (!trackIds) return; if (!trackIds) return;
const tracks = Object.entries(def.tracks).map(([key, track]) => { const tracks = Object.values(def.tracks).map((track) => {
return this._createSwitchTrackFromDef(scenery, def, track, trackIds); return this._createSwitchTrackFromDef(scenery, def, track, trackIds);
}); });
@ -155,15 +155,16 @@ export default class Switch extends SceneryObject {
const { startPos, rotationDeg } = CurveHelper.transformStart(this.pos, this.rot, trackDef.pos, trackDef.rot); const { startPos, rotationDeg } = CurveHelper.transformStart(this.pos, this.rot, trackDef.pos, trackDef.rot);
const track = StandardTrack.createSwitchTrack( const track = StandardTrack.createSwitchTrack(
this,
trackId, trackId,
startPos, startPos,
rotationDeg, rotationDeg,
trackDef.length, trackDef.length,
trackDef.radius, trackDef.radius,
connections, connections,
trackDef.slope1, trackDef.slope1 ?? 0,
trackDef.slope2, trackDef.slope2 ?? 0,
this, trackDef.speedLimit ?? 999
); );
scenery.addObject(track); scenery.addObject(track);
return track; return track;

View File

@ -99,20 +99,20 @@ export default class StandardTrack extends Track {
return track; return track;
} }
static createSwitchTrack(id, start, rot, len, r, connections, start_slope, end_slope, object) { static createSwitchTrack(switchObj, id, start, rot, len, r, connections, start_slope, end_slope, speed_limit) {
const track = new StandardTrack( const track = new StandardTrack(
id, start, rot, len, r, id, start, rot, len, r,
connections, connections,
object.id_switch, switchObj.id_switch,
start_slope, start_slope,
end_slope, end_slope,
object.id_isolation, switchObj.id_isolation,
object.prefab_name, switchObj.prefab_name,
object.maxspeed, Math.min(switchObj.maxspeed, speed_limit),
object.derailspeed, Math.min(switchObj.derailspeed, speed_limit),
TrackSource.SWITCH, TrackSource.SWITCH,
); );
track.switch = object; track.switch = switchObj;
return track; return track;
} }
} }