API Reference
Complete reference for all Subway Builder modding APIs
The Subway Builder modding API is organized into several namespaces, each handling different aspects of the game.
API Structure#
javascript
window.SubwayBuilderAPI = {
version: '1.0.0',
// Lifecycle hooks
hooks: { onGameInit, onDayChange, onStationBuilt, ... },
// Game actions (modify game state)
actions: { setMoney, addMoney, setPause, setSpeed, ... },
// UI customization
ui: { showNotification, addButton, registerComponent, ... },
// Read-only game state
gameState: { getStations, getRoutes, getTrains, getBudget, ... },
// City registration
registerCity, cities: { registerTab, setCityDataFiles, ... },
// Train types
trains: { registerTrainType, modifyTrainType, getTrainTypes, ... },
// Station types
stations: { registerStationType, modifyStationType, ... },
// Map customization
map: { registerSource, registerLayer, registerStyle, ... },
// Build automation
build: { placeBlueprintTracks, buildBlueprints, createRoute, ... },
// Career missions
career: { registerMission, getMissionsForCity, METRICS, ... },
// Utilities
utils: { React, icons, components, charts, i18n, ... },
// Storage (Electron only)
storage: { get, set, delete, keys },
// Data validation schemas
schemas: { DemandDataSchema, BuildingIndexSchema, ... }
}Quick Links#
| Section | Description |
|---|---|
| Lifecycle Hooks | React to game events (day change, station built, etc.) |
| Game Actions | Modify game state (money, pause, speed) |
| UI Customization | Add buttons, panels, notifications |
| Game State | Read current game state (stations, routes, budget) |
| Custom Cities | Add new cities with custom data |
| Train Types | Register and modify train types |
| Station Types | Customize station behavior |
| Map Customization | Add custom map layers and tiles |
| Build Automation | Programmatically build tracks and routes |
| Career Missions | Create custom career challenges |
TypeScript Support#
The API is fully typed. If using TypeScript:
typescript
import type { ModdingAPI } from '@/app/game/moddingAPI';
declare global {
interface Window {
SubwayBuilderAPI: ModdingAPI;
}
}
// Now you get autocomplete!
window.SubwayBuilderAPI.registerCity({
// TypeScript will validate this
});