Game State
Read current game state (read-only)
The game state API provides read-only access to current game data for analysis, UI mods, or debugging.
Stations#
getStations#
Get all stations in the current game.
const stations = window.SubwayBuilderAPI.gameState.getStations();
console.log('Total stations:', stations.length);
// Station data includes: id, name, coords, stationGroup, etc.
stations.forEach((station) => {
console.log(`${station.name} at [${station.coords}]`);
});Routes#
getRoutes#
Get all routes (subway lines).
const routes = window.SubwayBuilderAPI.gameState.getRoutes();
routes.forEach((route) => {
console.log(`Route ${route.name}: ${route.stations.length} stations`);
});Tracks#
getTracks#
Get all tracks with elevation/depth data.
const tracks = window.SubwayBuilderAPI.gameState.getTracks();
// Each track has startElevation and endElevation
// Negative values = underground, positive = elevated
tracks.forEach((track) => {
console.log(`Track ${track.id}: ${track.startElevation}m to ${track.endElevation}m`);
});
// Find deepest track
const deepestTrack = tracks.reduce((deepest, track) => {
const minElev = Math.min(track.startElevation, track.endElevation);
const deepestElev = Math.min(deepest.startElevation, deepest.endElevation);
return minElev < deepestElev ? track : deepest;
}, tracks[0]);
console.log('Deepest track:', deepestTrack?.startElevation, 'm');Trains#
getTrains#
Get all active trains.
const trains = window.SubwayBuilderAPI.gameState.getTrains();
console.log('Active trains:', trains.length);Time & Money#
getCurrentDay#
Get the current in-game day.
const day = window.SubwayBuilderAPI.gameState.getCurrentDay();getCurrentHour#
Get the current in-game hour (0-23).
const hour = window.SubwayBuilderAPI.gameState.getCurrentHour();getElapsedSeconds#
Get total elapsed in-game time in seconds.
const elapsedSeconds = window.SubwayBuilderAPI.gameState.getElapsedSeconds();getBudget#
Get current money balance.
const budget = window.SubwayBuilderAPI.gameState.getBudget();
console.log(`$${budget.toLocaleString()} remaining`);getTicketPrice#
Get current ticket price.
const ticketPrice = window.SubwayBuilderAPI.gameState.getTicketPrice();Game Controls#
getGameSpeed#
Get current game speed.
const speed = window.SubwayBuilderAPI.gameState.getGameSpeed();
// Returns: 'slow', 'normal', 'fast', or 'ultrafast'isPaused#
Check if game is paused.
const paused = window.SubwayBuilderAPI.gameState.isPaused();Demand Data#
getDemandData#
Get population/commuter demand data.
const demandData = window.SubwayBuilderAPI.gameState.getDemandData();
if (demandData) {
console.log('Demand points:', demandData.points.size);
console.log('Population groups:', demandData.popsMap.size);
// Iterate over demand points
demandData.points.forEach((point, id) => {
console.log(`Point ${id}: ${point.jobs} jobs, ${point.residents} residents`);
});
}Financial Data#
getBonds#
Get all active bonds.
const bonds = window.SubwayBuilderAPI.gameState.getBonds();
bonds.forEach((bond) => {
console.log(`Bond: $${bond.principal} at ${bond.interestRate}%`);
});getBondTypes#
Get available bond type definitions.
const bondTypes = window.SubwayBuilderAPI.gameState.getBondTypes();
console.log('Available bond types:', Object.keys(bondTypes));Performance Metrics#
getRidershipStats#
Get ridership statistics.
const ridership = window.SubwayBuilderAPI.gameState.getRidershipStats();
console.log('Riders per hour:', ridership.totalRidersPerHour);
console.log('Total riders all time:', ridership.totalRiders);getLineMetrics#
Get per-line performance metrics.
const lineMetrics = window.SubwayBuilderAPI.gameState.getLineMetrics();
lineMetrics.forEach((line) => {
console.log(`${line.name}: ${line.ridersPerHour} riders/hr`);
});getModeChoiceStats#
Get commuter mode choice breakdown.
const modes = window.SubwayBuilderAPI.gameState.getModeChoiceStats();
// { walking: 1200, driving: 8500, transit: 3200, unknown: 100 }
const total = modes.walking + modes.driving + modes.transit;
const transitShare = ((modes.transit / total) * 100).toFixed(1);
console.log(`Transit mode share: ${transitShare}%`);getStationRidership#
Get ridership data for stations.
// All stations
const allStats = window.SubwayBuilderAPI.gameState.getStationRidership();
console.log('Total system ridership:', allStats.total);
// Specific station
const stationStats = window.SubwayBuilderAPI.gameState.getStationRidership('station-123');
console.log(`Riders: ${stationStats.total}, transfers: ${stationStats.transfers}`);
stationStats.byRoute.forEach((r) => {
console.log(` Route ${r.routeId}: ${r.popCount} riders`);
});getRouteRidership#
Get ridership data for a route.
const routeStats = window.SubwayBuilderAPI.gameState.getRouteRidership('route-456');
routeStats.byStation.forEach((s) => {
console.log(` ${s.stationId}: ${s.popCount} riders`);
});Blueprint Cost Calculation#
calculateBlueprintCost#
Calculate cost of blueprint tracks before construction.
const tracks = window.SubwayBuilderAPI.gameState.getTracks();
const blueprintTracks = tracks.filter((t) => t.displayType === 'blueprint');
const cost = window.SubwayBuilderAPI.gameState.calculateBlueprintCost(blueprintTracks);
console.log('Total cost:', cost.totalCost.toLocaleString());
console.log('Breakdown:');
console.log(' Track cost:', cost.breakdown.trackCost.toLocaleString());
console.log(' Station cost:', cost.breakdown.stationCost.toLocaleString());
console.log(' Scissors crossover:', cost.breakdown.scissorsCrossoverCost.toLocaleString());
console.log(' Demolition:', cost.breakdown.buildingDemolitionCost.toLocaleString());State Summary#
| Method | Returns | Description |
|---|---|---|
getStations() | Station[] | All stations |
getRoutes() | Route[] | All routes |
getTracks() | Track[] | All tracks |
getTrains() | Train[] | All trains |
getCurrentDay() | number | Current day |
getCurrentHour() | number | Current hour (0-23) |
getElapsedSeconds() | number | Total elapsed seconds |
getBudget() | number | Current money |
getTicketPrice() | number | Ticket price |
getGameSpeed() | string | Game speed |
isPaused() | boolean | Pause state |
getDemandData() | DemandData | Demand/population data |
getBonds() | Bond[] | Active bonds |
getBondTypes() | object | Bond type definitions |
getRidershipStats() | object | Ridership statistics |
getLineMetrics() | object[] | Per-line metrics |
getModeChoiceStats() | object | Mode choice breakdown |
getStationRidership(id?) | object | Station ridership |
getRouteRidership(id) | object | Route ridership |
calculateBlueprintCost(tracks) | object | Cost breakdown |