mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-08 17:02:52 +00:00
b56e380107
## Description: Enable the `sort-keys` eslint rule. Fixes #1629 ## Please complete the following: - [x] I have added screenshots for all UI updates - [x] I process any text displayed to the user through translateText() and I've added it to the en.json file - [x] I have added relevant tests to the test directory - [x] I confirm I have thoroughly tested these changes and take full responsibility for any bugs introduced - [ ] I have read and accepted the CLA agreement (only required once).
68 lines
1.6 KiB
TypeScript
68 lines
1.6 KiB
TypeScript
import { Game } from "./Game";
|
|
import { TileRef } from "./GameMap";
|
|
import { GameUpdateType, RailTile, RailType } from "./GameUpdates";
|
|
import { TrainStation } from "./TrainStation";
|
|
|
|
export class Railroad {
|
|
constructor(
|
|
public from: TrainStation,
|
|
public to: TrainStation,
|
|
public tiles: TileRef[],
|
|
) {}
|
|
|
|
delete(game: Game) {
|
|
const railTiles: RailTile[] = this.tiles.map((tile) => ({
|
|
railType: RailType.VERTICAL,
|
|
tile,
|
|
}));
|
|
game.addUpdate({
|
|
isActive: false,
|
|
railTiles,
|
|
type: GameUpdateType.RailroadEvent,
|
|
});
|
|
this.from.getRailroads().delete(this);
|
|
this.to.getRailroads().delete(this);
|
|
}
|
|
}
|
|
|
|
export function getOrientedRailroad(
|
|
from: TrainStation,
|
|
to: TrainStation,
|
|
): OrientedRailroad | null {
|
|
for (const railroad of from.getRailroads()) {
|
|
if (railroad.from === to) {
|
|
return new OrientedRailroad(railroad, false);
|
|
} else if (railroad.to === to) {
|
|
return new OrientedRailroad(railroad, true);
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
/**
|
|
* Wrap a railroad with a direction so it always starts at tiles[0]
|
|
*/
|
|
export class OrientedRailroad {
|
|
private tiles: TileRef[] = [];
|
|
constructor(
|
|
private railroad: Railroad,
|
|
private forward: boolean,
|
|
) {
|
|
this.tiles = this.forward
|
|
? this.railroad.tiles
|
|
: [...this.railroad.tiles].reverse();
|
|
}
|
|
|
|
getTiles(): TileRef[] {
|
|
return this.tiles;
|
|
}
|
|
|
|
getStart(): TrainStation {
|
|
return this.forward ? this.railroad.from : this.railroad.to;
|
|
}
|
|
|
|
getEnd(): TrainStation {
|
|
return this.forward ? this.railroad.to : this.railroad.from;
|
|
}
|
|
}
|