Build Automation
Programmatically build tracks, routes, and trains
The Build API provides programmatic access to construction and route management. Useful for automated scenarios, testing, and scripted gameplay.
Place Blueprint Tracks#
Place tracks as blueprints (not yet constructed):
javascript
const result = window.SubwayBuilderAPI.build.placeBlueprintTracks(
// Array of track definitions
[
{
coords: [
[-73.98, 40.76], // [longitude, latitude]
[-73.97, 40.755]
],
trackType: 'standard', // optional
startElevation: 0, // 0 = surface, negative = underground
endElevation: -10 // descending into tunnel
},
{
coords: [
[-73.97, 40.755],
[-73.96, 40.75]
]
}
],
// Optional: track groups (for parallel tracks)
[
{
trackIds: ['track1', 'track2'],
centerLine: [[-73.98, 40.76], [-73.96, 40.75]],
trackLanesType: 'parallel' // 'single', 'parallel', or 'quad'
}
]
);
if (result.success) {
console.log('Placed tracks:', result.trackIds);
console.log('Track groups:', result.trackGroupIds);
} else {
console.error('Failed:', result.error);
}Build Blueprints#
Convert all blueprint tracks to constructed tracks:
javascript
const result = await window.SubwayBuilderAPI.build.buildBlueprints();
if (result.success) {
console.log(`Built ${result.builtTrackCount} tracks`);
console.log(`Total cost: $${result.totalCost}`);
} else {
console.error('Build failed:', result.error);
}Erase Blueprints#
Remove all blueprint tracks without building:
javascript
window.SubwayBuilderAPI.build.eraseBlueprints();Undo/Redo Blueprints#
javascript
// Undo last blueprint placement
window.SubwayBuilderAPI.build.undoBlueprint();
// Redo previously undone placement
window.SubwayBuilderAPI.build.redoBlueprint();Get Blueprint Info#
javascript
// Get current blueprint cost estimate
const cost = window.SubwayBuilderAPI.build.getBlueprintCost();
console.log(`Building will cost: $${cost}`);
// Get number of blueprint tracks
const count = window.SubwayBuilderAPI.build.getBlueprintCount();
console.log(`${count} blueprint tracks placed`);Create Route#
Create a new route (subway line):
javascript
const result = window.SubwayBuilderAPI.build.createRoute({
bullet: 'A', // optional, line identifier
color: '#FF5733', // optional, hex color
textColor: '#FFFFFF', // optional, text/bullet color
shape: 'pill', // optional: 'circle', 'pill', 'diamond', 'square'
trainType: 'standard' // optional: 'standard', 'light-rail', etc.
});
if (result.success) {
console.log(`Created route ${result.route.bullet}`);
console.log(`Route ID: ${result.route.id}`);
}Delete Route#
javascript
const success = window.SubwayBuilderAPI.build.deleteRoute('route-id');
// Note: This also removes all trains on the routeBuy Trains#
Purchase trains to add to inventory:
javascript
const result = window.SubwayBuilderAPI.build.buyTrains(5, 'standard');
if (result.success) {
console.log(`Purchased ${result.totalPurchased} trains`);
} else {
console.error('Purchase failed:', result.error);
}Add Train to Route#
Spawn a train on a route at a specific station:
javascript
const result = window.SubwayBuilderAPI.build.addTrainToRoute(
'route-id', // Route to add train to
0 // Station index (0 = first station)
);
if (result.success) {
console.log(`Spawned train: ${result.trainId}`);
} else {
console.error('Spawn failed:', result.error);
}Delete Train#
javascript
const success = window.SubwayBuilderAPI.build.deleteTrain('train-id');Complete Example: Automated Line Builder#
javascript
async function buildSimpleLine() {
const api = window.SubwayBuilderAPI;
// 1. Place blueprint tracks between two points
const trackResult = api.build.placeBlueprintTracks([
{
coords: [
[-73.985, 40.758],
[-73.980, 40.755],
[-73.975, 40.752]
],
startElevation: -15, // Underground
endElevation: -15
}
]);
if (!trackResult.success) {
console.error('Track placement failed:', trackResult.error);
return;
}
// 2. Check cost
const cost = api.build.getBlueprintCost();
console.log(`Construction will cost: $${cost.toLocaleString()}`);
// 3. Build the tracks
const buildResult = await api.build.buildBlueprints();
if (!buildResult.success) {
console.error('Build failed:', buildResult.error);
return;
}
// 4. Create a route
const routeResult = api.build.createRoute({
bullet: '7',
color: '#B933AD',
shape: 'circle'
});
if (!routeResult.success) {
console.error('Route creation failed:', routeResult.error);
return;
}
// 5. Buy and add trains
api.build.buyTrains(3, 'standard');
api.build.addTrainToRoute(routeResult.route.id, 0);
console.log('Line built successfully!');
}
buildSimpleLine();API Summary#
| Method | Returns | Description |
|---|---|---|
placeBlueprintTracks(tracks, groups?) | Result | Place blueprint tracks |
buildBlueprints() | Promise<Result> | Build all blueprints |
eraseBlueprints() | void | Remove all blueprints |
undoBlueprint() | void | Undo last placement |
redoBlueprint() | void | Redo undone placement |
getBlueprintCost() | number | Get total blueprint cost |
getBlueprintCount() | number | Get blueprint track count |
createRoute(options?) | Result | Create new route |
deleteRoute(id) | boolean | Delete route |
buyTrains(count, type) | Result | Purchase trains |
addTrainToRoute(routeId, stationIdx) | Result | Spawn train on route |
deleteTrain(id) | boolean | Delete train |