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, ... }
}
SectionDescription
Lifecycle HooksReact to game events (day change, station built, etc.)
Game ActionsModify game state (money, pause, speed)
UI CustomizationAdd buttons, panels, notifications
Game StateRead current game state (stations, routes, budget)
Custom CitiesAdd new cities with custom data
Train TypesRegister and modify train types
Station TypesCustomize station behavior
Map CustomizationAdd custom map layers and tiles
Build AutomationProgrammatically build tracks and routes
Career MissionsCreate 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
});