Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable eslint sort-keys rule #208

Merged
merged 2 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
"no-undef": "error",
"no-unused-vars": "off", // @typescript-eslint/no-unused-vars
"require-jsdoc": "off",
"sort-keys": ["error", "asc", { "caseSensitive": false, "natural": false, "minKeys": 2 }],
"space-infix-ops": "off"
}
}
2 changes: 1 addition & 1 deletion ts/Grade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export function calculateGrade(controlPoints: Vector[]): Grade[] {
const dz = controlPoints[i + 1].z - cp.z;
const length = Math.sqrt((dx * dx) + (dy * dy));
const grade = Math.abs(dz) / length;
return {length, height: dz, grade};
return {grade, height: dz, length};
});
}

Expand Down
4 changes: 2 additions & 2 deletions ts/HasLocationRotation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ export interface HasLocationRotation {
export function localToWorld(transform: HasLocationRotation, curve: HermiteCurve): HermiteCurve {
const {startPoint, endPoint, startTangent, endTangent} = curve;
return {
startPoint: vectorSum(transform.location, rotateVector(startPoint, transform.rotation)),
endPoint: vectorSum(transform.location, rotateVector(endPoint, transform.rotation)),
startTangent: rotateVector(startTangent, transform.rotation),
endTangent: rotateVector(endTangent, transform.rotation),
startPoint: vectorSum(transform.location, rotateVector(startPoint, transform.rotation)),
startTangent: rotateVector(startTangent, transform.rotation),
};
}
38 changes: 19 additions & 19 deletions ts/RailroadMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ export class RailroadMap {
const pitch = radiansToDegrees(Math.atan2(direction.z,
Math.sqrt(direction.x * direction.x + direction.y * direction.y)));
const location = vectorSum({x: 0, y: 0, z: 100}, point);
const rotation = {yaw, pitch, roll: 0};
const rotation = {pitch, roll: 0, yaw};
return {location, rotation};
}

Expand Down Expand Up @@ -631,26 +631,26 @@ export class RailroadMap {
const vertical = unknownProperty(ml, 'vertical');
const defaultNumber = (option: unknown, n: number) => typeof option === 'undefined' ? n : Number(option);
return {
pan: {
x: defaultNumber(x, 0),
y: defaultNumber(y, 0),
},
zoom: defaultNumber(zoom, 1),
mergeLimits: {
bearing: defaultNumber(bearing, 10),
inclination: defaultNumber(inclination, 2.5),
horizontal: defaultNumber(horizontal, 10),
inclination: defaultNumber(inclination, 2.5),
vertical: defaultNumber(vertical, 1),
},
pan: {
x: defaultNumber(x, 0),
y: defaultNumber(y, 0),
},
zoom: defaultNumber(zoom, 1),
};
}

writeOptions() {
const key = `railroadstudio.${this.railroad.saveGame.uniqueWorldId}`;
const options: MapOptions = {
mergeLimits: this.mergeLimits,
pan: this.panFrom(),
zoom: this.panZoom.getZoom(),
mergeLimits: this.mergeLimits,
};
localStorage.setItem(key, JSON.stringify(options));
}
Expand Down Expand Up @@ -824,11 +824,14 @@ export class RailroadMap {

let listeners: { [key: string]: (e: Event) => unknown };
return svgPanZoom(this.svg.node, {
zoomScaleSensitivity: 0.5,
minZoom: 0.5,
maxZoom: 500,
beforePan: beforePan,
customEventsHandler: {
destroy: () => {
// Unregister listeners
for (const eventName of Object.keys(listeners)) {
this.svg.node.removeEventListener(eventName, listeners[eventName]);
}
},
haltEventListeners: [],
init: (options) => {
let mouseDown = false;
Expand Down Expand Up @@ -933,15 +936,12 @@ export class RailroadMap {
options.svgElement.addEventListener(eventName, listeners[eventName]);
}
},
destroy: () => {
// Unregister listeners
for (const eventName of Object.keys(listeners)) {
this.svg.node.removeEventListener(eventName, listeners[eventName]);
}
},
},
maxZoom: 500,
minZoom: 0.5,
onPan: onPanZoom,
onZoom: onPanZoom,
zoomScaleSensitivity: 0.5,
});
}

Expand Down Expand Up @@ -1806,7 +1806,7 @@ export class RailroadMap {
const bezier = hermiteToBezier(spline);
const sharpest = cubicBezierMinRadius(bezier);
const length = cubicBezierLength(bezier);
console.log({index, sharpest, spline, steepest, length});
console.log({index, length, sharpest, spline, steepest});
}
break;
case MapToolMode.delete:
Expand Down Expand Up @@ -1892,7 +1892,7 @@ export class RailroadMap {
const {location, rotation} = this.rerailLocation(e, spline, this.toolFrame);
const {name, number, type, state} = this.toolFrame;
// Copy the frame to the new location
const frame: Frame = {location, name, number, rotation, type, state};
const frame: Frame = {location, name, number, rotation, state, type};
this.railroad.frames.push(frame);
this.setMapModified(true);
// Update the map
Expand Down
16 changes: 8 additions & 8 deletions ts/SplineTrackType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,31 +55,31 @@ export enum SplineTrackType {
}

const secondLegSwitchLeft = {
startPoint: {x: 0, y: 0, z: 0},
startTangent: {x: 1879.3, y: 0, z: 0},
endPoint: {x: 1879.3, y: 0, z: 0},
endTangent: {x: 1879.3, y: 0, z: 0},
startPoint: {x: 0, y: 0, z: 0},
startTangent: {x: 1879.3, y: 0, z: 0},
};

const secondLegSwitchRight = {
startPoint: {x: 0, y: 0, z: 0},
startTangent: {x: 2153.67, y: 0, z: 0},
endPoint: {x: 1863.4, y: 184.8, z: 0},
endTangent: {x: 2125.36, y: 348.04, z: 0},
startPoint: {x: 0, y: 0, z: 0},
startTangent: {x: 2153.67, y: 0, z: 0},
};

const switchCross45 = {
startPoint: {x: 87.9, y: 212.1, z: 0},
startTangent: {x: 424.2, y: -424.2, z: 0},
endPoint: {x: 512.1, y: -212.1, z: 0},
endTangent: {x: 424.2, y: -424.2, z: 0},
startPoint: {x: 87.9, y: 212.1, z: 0},
startTangent: {x: 424.2, y: -424.2, z: 0},
};

const switchCross90 = {
startPoint: {x: 191.2, y: -191.2, z: 0},
startTangent: {x: 0, y: 382.4, z: 0},
endPoint: {x: 191.2, y: 191.2, z: 0},
endTangent: {x: 0, y: 382.4, z: 0},
startPoint: {x: 191.2, y: -191.2, z: 0},
startTangent: {x: 0, y: 382.4, z: 0},
};

export const switchExtraLegs: Partial<Record<SplineTrackType, HermiteCurve[]>> = {
Expand Down
17 changes: 9 additions & 8 deletions ts/Studio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -746,11 +746,11 @@ export class Studio {
isFrameType(f.type) && (frameDefinitions[f.type][c] ?? false);
const labels = {
engine: `Engines (${railroad.frames.filter((f) => frameInCategory(f, 'engine')).length})`,
tender: `Tenders (${railroad.frames.filter((f) => frameInCategory(f, 'tender')).length})`,
handcar: `Handcars (${railroad.frames.filter((f) => frameInCategory(f, 'handcar')).length})`,
freight: `Freight (${railroad.frames.filter((f) => frameInCategory(f, 'freight')).length})`,
passenger: `Passenger (${railroad.frames.filter((f) => frameInCategory(f, 'passenger')).length})`,
handcar: `Handcars (${railroad.frames.filter((f) => frameInCategory(f, 'handcar')).length})`,
mow: `Maintenance (${railroad.frames.filter((f) => frameInCategory(f, 'mow')).length})`,
passenger: `Passenger (${railroad.frames.filter((f) => frameInCategory(f, 'passenger')).length})`,
tender: `Tenders (${railroad.frames.filter((f) => frameInCategory(f, 'tender')).length})`,
};
const anyInCategory = (c: typeof frameCategories[number]): boolean =>
railroad.frames.some((f) => frameInCategory(f, c));
Expand Down Expand Up @@ -1020,8 +1020,8 @@ export class Studio {
!spline.type.includes('switch') &&
!spline.type.includes('bumper'))
.map((spline) => {
const {startPoint, startTangent, endPoint, endTangent} = spline;
return {startPoint, startTangent, endPoint, endTangent};
const {endPoint, endTangent, startPoint, startTangent} = spline;
return {endPoint, endTangent, startPoint, startTangent};
}),
);
// Calculate minimum radius
Expand Down Expand Up @@ -1216,8 +1216,8 @@ export class Studio {
tooltip = `Expected ${key} to in range [${minValue}, ${maxValue}]`;
}
const options: InputTextOptions = {
min: String(minValue),
max: String(maxValue),
min: String(minValue),
step: 'step' in meta && meta.step ? String(meta.step) : undefined,
};
const displayValue = (value: number) => Number.isInteger(value) ? String(value) : value.toFixed(1);
Expand Down Expand Up @@ -1290,7 +1290,7 @@ export class Studio {
const limits: Partial<Record<CargoType, number>> = cargoLimits[frame.type];
const limit = isCargoType(freightType) ? limits[freightType] ?? 0 : 0;
const max = String(limit);
const options: InputTextOptions = {min: '0', max};
const options: InputTextOptions = {max, min: '0'};
const form = editNumber(this, frame.state.freightAmount, options, setAmount);
if (isCargoType(freightType) &&
typeof limits[freightType] !== 'undefined' &&
Expand Down Expand Up @@ -1577,7 +1577,8 @@ export class Studio {
if (player.rotation) {
td = document.createElement('td');
const setPlayerRotation = (r: number) => player.rotation = r;
td.replaceChildren(editNumber(this, player.rotation, {min: '-180', max: '180'}, setPlayerRotation));
const options: InputTextOptions = {max: '180', min: '-180'};
td.replaceChildren(editNumber(this, player.rotation, options, setPlayerRotation));
tr.appendChild(td);
}
// Permissions
Expand Down
2 changes: 2 additions & 0 deletions ts/StudioEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,7 @@ export function editQuaternion(
saveValue: (value: Quaternion) => Quaternion,
) {
const encode = (v: Quaternion): number[] => [v.x, v.y, v.z, v.w];
// eslint-disable-next-line sort-keys
const decode = (t: number[]): Quaternion => fp32q({x: t[0], y: t[1], z: t[2], w: t[3]});
const display = (t: number[]) => {
const xZero = t[0] === 0;
Expand All @@ -406,6 +407,7 @@ export function editRotator(
saveValue: (value: Rotator) => Rotator,
) {
const encode = (r: Rotator): number[] => [r.roll, r.yaw, r.pitch];
// eslint-disable-next-line sort-keys
const decode = (t: number[]): Rotator => fp32r({roll: t[0], yaw: t[1], pitch: t[2]});
const display = (t: number[]) => {
if (t[0] === 0 && t[2] === 0) {
Expand Down
Loading