Skip to content

Commit

Permalink
spin control review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
guysv committed Oct 22, 2024
1 parent fbe10ed commit 176f40c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/services/spacingEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export function getDistanceFromProgress(car: Car, trackProgress: number): number
? new ForwardIterator(trackProgress, currentProgress)
: new BackwardIterator(abs(trackProgress), currentProgress);

let trackPosition = currentTrackLocation as CoordsXYZD;
let trackPosition: CoordsXYZD = currentTrackLocation;
let trackDistances = getTrackDistances(iteratorSegment, subposition, trackPosition.direction);
subpositionIterator._setInitialDistanceFromCarRemainingDistance(car.remainingDistance);

Expand Down
9 changes: 1 addition & 8 deletions src/services/vehicleEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ function updateVehicleSetting(args: UpdateVehicleSettingArgs): void
case massKey:
case poweredAccelerationKey:
case poweredMaxSpeedKey:
case spinKey:
{
callback = (car): void =>
{
Expand All @@ -249,14 +250,6 @@ function updateVehicleSetting(args: UpdateVehicleSettingArgs): void
};
break;
}
case spinKey:
{
callback = (car): void =>
{
car.spin += value;
};
break;
}
case trackProgressKey:
{
callback = (car): void =>
Expand Down
8 changes: 4 additions & 4 deletions src/ui/mainWindow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -376,15 +376,15 @@ export const mainWindow = window({
format: model._formatPosition,
onChange: (_, incr) => model._modifyVehicle(setPositionZ, incr)
}),
positionSpinner({
labelSpinner({
_label: { text: "Seat spin:" },
minimum: 0,
maximum: 255,
disabled: model._isPositionDisabled,
disabled: model._isEditDisabled,
step: model._multiplier,
value: model._spin,
format: model._formatPosition,
onChange: (_, incr) => model._modifyVehicle(setSpin, incr)
wrapMode: "clampThenWrap",
onChange: value => model._modifyVehicle(setSpin, value)
})
]
}),
Expand Down
17 changes: 11 additions & 6 deletions tests/services/spacingEditor.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ class TrackPiece
{
return new TrackPiece({ x, y, z, direction }, this.type, this.subpositions);
}

toLocation(): CarTrackLocation
{
return { ...this.position, trackType: this.type };
}
}

const flatTrackPiece = new TrackPiece({ x: 0, y: 0, z: 0, direction: 0 }, 1,
Expand Down Expand Up @@ -462,8 +467,8 @@ test("Two flat tracks: get spacing to next track piece by 1", t =>
const pieces = [ flatTrackPiece.copyTo(32, 64), flatTrackPiece.copyTo(32, 32) ];
const mapMock = setupTrackIterator(pieces);
const train = createTrain(mapMock, [
{ trackProgress: 0, trackLocation: {...pieces[1].position, trackType: pieces[1].type} }, // front car
{ trackProgress: 31, trackLocation: {...pieces[0].position, trackType: pieces[0].type} } // back car
{ trackProgress: 0, trackLocation: pieces[1].toLocation() }, // front car
{ trackProgress: 31, trackLocation: pieces[0].toLocation() } // back car
]);
const car = train._at(1)._car();

Expand All @@ -478,8 +483,8 @@ test("Two flat tracks: get spacing to next track piece by 10", t =>
const pieces = [ flatTrackPiece.copyTo(32, 64), flatTrackPiece.copyTo(32, 32) ];
const mapMock = setupTrackIterator(pieces);
const train = createTrain(mapMock, [
{ trackProgress: 3, trackLocation: {...pieces[1].position, trackType: pieces[1].type} }, // front car
{ trackProgress: 25, trackLocation: {...pieces[0].position, trackType: pieces[0].type} } // back car
{ trackProgress: 3, trackLocation: pieces[1].toLocation() }, // front car
{ trackProgress: 25, trackLocation: pieces[0].toLocation() } // back car
]);
const car = train._at(1)._car();

Expand All @@ -494,8 +499,8 @@ test("Three flat tracks: get spacing to next track piece by 50", t =>
const pieces = [ flatTrackPiece.copyTo(32, 96), flatTrackPiece.copyTo(32, 64), flatTrackPiece.copyTo(32, 32) ];
const mapMock = setupTrackIterator(pieces);
const train = createTrain(mapMock, [
{ trackProgress: 5, trackLocation: {...pieces[2].position, trackType: pieces[2].type} }, // front car
{ trackProgress: 19, trackLocation: {...pieces[0].position, trackType: pieces[0].type} } // back car
{ trackProgress: 5, trackLocation: pieces[2].toLocation() }, // front car
{ trackProgress: 19, trackLocation: pieces[0].toLocation() } // back car
]);
const car = train._at(1)._car();

Expand Down

0 comments on commit 176f40c

Please sign in to comment.