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, ... },

    // Utilities
    utils: { React, icons, components, charts, i18n, ... },

    // Storage (Electron only)
    storage: { get, set, delete, keys, scoped },

    // Inter-mod discovery
    mods: { isLoaded, getLoadedMods },

    // Data validation schemas (JSON formats only; binary buildings index uses utils.buildings)
    schemas: { DemandDataSchema, RoadsGeojsonSchema, RunwaysTaxiwaysGeojsonSchema }
}
SectionDescription
Lifecycle HooksReact to game events (day change, station built, etc.)
Game ActionsModify game state (money, pause, speed)
Game ConstantsModify game rules and pathfinding behavior
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
Mod DiscoveryDetect other loaded mods for integrations

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
});