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.
For complete property listings of every returned object, see the Type Reference.
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.bullet}: ${route.stNodes.length} stops, color ${route.color}`);
});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('Riders in last 15 min:', ridership.totalRiders);
// Note: stats are based on a 15-minute rolling window, not cumulative all-timegetLineMetrics#
Get per-line performance metrics. Revenue values include the fare multiplier and match what you see in the financial dashboard.
const lineMetrics = window.SubwayBuilderAPI.gameState.getLineMetrics();
lineMetrics.forEach((line) => {
console.log(`Route ${line.routeBullet}: ${line.ridersPerHour} riders/hr, $${line.revenuePerHour}/hr`);
});
// Each metric object contains:
// { routeId, routeBullet, routeColor, trainCount, trainsPerHour, ridersPerHour, revenuePerHour }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`);
});getCompletedCommutes#
Get all completed commutes from the last 15 minutes of game time. Useful for advanced analytics mods that need raw commute data.
const commutes = window.SubwayBuilderAPI.gameState.getCompletedCommutes();
console.log(`${commutes.length} commutes in last 15 min`);
commutes.forEach((c) => {
console.log(`Group of ${c.size} from ${c.originId} to ${c.destId}`);
});Transfer & Station Groups#
getStationGroups#
Get all station groups (transfer hubs where nearby stations are grouped together).
const groups = window.SubwayBuilderAPI.gameState.getStationGroups();
groups.forEach((group) => {
console.log(`Group ${group.id}: ${group.stationIds.length} stations`);
});getTransferStationIds#
Get IDs of all stations that are part of a transfer (in groups with 2+ stations).
const transferIds = window.SubwayBuilderAPI.gameState.getTransferStationIds();
console.log(`${transferIds.length} stations serve as transfers`);getSiblingStationIds#
Get sibling station IDs for a given station (other stations in the same transfer group).
const siblings = window.SubwayBuilderAPI.gameState.getSiblingStationIds('station-123');
console.log(`Station has ${siblings.length} transfer siblings`);Save State#
getSaveName#
Get the name of the currently loaded save, or null if no save is loaded.
const saveName = window.SubwayBuilderAPI.gameState.getSaveName();
if (saveName) {
console.log(`Playing save: ${saveName}`);
}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 | |
getCompletedCommutes() | object[] | Raw commutes (last 15 min) | |
getStationGroups() | StationGroup[] | All station groups | |
getTransferStationIds() | string[] | Station IDs in transfer groups | |
getSiblingStationIds(id) | string[] | Sibling stations in same group | |
getSaveName() | `string \ | null` | Current save name |
calculateBlueprintCost(tracks) | object | Cost breakdown |