fr
Connexion

← Retour à la référence de l'API

Layout The layout

The layout as a whole: what happens to all of it (the scripts starting and stopping, routes, the command station, track power, devices coming and going) and what you do for the whole layout (a message, an announcement, track power, the emergency stop).

À quoi ça sert : For what has to happen at start and stop (onStart, onShutdown), to react to the command station or the track power, and to follow routes without knowing which ones.

layout.onStart {
   log "All scripts have started"
}
layout.onStationLost {
   announce "The command station is gone"
}

Méthodes

say

A message on every screen.

The same as say without an object; inside a class write Trax.layout.say.

Trax.layout.say "Done"

announce

An announcement: shown and spoken on every screen.

The same as announce without an object; inside a class Trax.layout.announce.

Trax.layout.announce "The train is leaving"

power

The track power on or off.

The same as power without an object.

layout.power(false)

stopAll

The emergency stop.

The same as stopAll without an object.

layout.stopAll()

between → boolean

Whether the clock is between two times.

Whether this computer's clock is between two times; over midnight when the first is later.

if (layout.between("08:00", "18:00")) log "daytime"

Événements

onStart

Once every script has run its own lines.

Fires once, after every script has run its top-level code. The place to read the layout's state and initialise.

layout.onStart {
   log "${trains.size()} trains on the layout"
}

onRouteSet → RouteEvent

When a route is set: its turnouts sent.

Fires when a route is being set: its turnouts are sent, not all reported yet. Gives a RouteEvent.

layout.onRouteSet { RouteEvent r ->
   log "route ${r.name} is being set"
}

onRouteReady → RouteEvent

When every turnout of a route is reported in place.

Fires when every turnout of a route is reported in place: the route is set.

layout.onRouteReady { RouteEvent r ->
   log "${r.from.name} to ${r.to.name} is set"
}

onRouteDisturbed → RouteEvent

When a turnout of a route is reported the other way.

Fires when a turnout of a locked route is reported the wrong way.

layout.onRouteDisturbed { RouteEvent r ->
   say "Route ${r.name} is disturbed"
}

onRouteReleased → RouteEvent

When a route is released.

Fires when a route is released: behind the train, by hand, or because it was taken over.

layout.onRouteReleased { RouteEvent r ->
   log "${r.name} released"
}

onStationConnected

When the command station is connected again.

Fires when the connection to the command station is made (again).

layout.onStationConnected {
   log "command station connected"
}

onStationLost

When the command station is lost.

Fires when the connection to the command station is lost. Commands to the layout are refused meanwhile.

layout.onStationLost {
   announce "Attention: the command station is gone"
}

onPowerOn

When the track power goes on.

Fires when track power goes on.

layout.onPowerOn {
   log "power on"
}

onPowerOff

When the track power goes off.

Fires when track power goes off.

layout.onPowerOff {
   log "power off"
}

onEmergencyStop

When every train is stopped at once.

Fires at the emergency stop: every train stopped at once.

layout.onEmergencyStop {
   log "emergency stop"
}

onDeviceCame → Device

When a device opens TRAX Control while it had none open.

Fires when a registered device opens TRAX Control while it had none open. Gives the Device.

layout.onDeviceCame { Device d ->
   say "${d.name} is here"
}

onDeviceWent → Device

When a device has had TRAX Control closed for a little while.

Fires when a device has had TRAX Control closed for a while (about a minute). Gives the Device.

layout.onDeviceWent { Device d ->
   log "${d.name} has gone"
}

onDeviceAsks → Device

When a new device registers and asks to be admitted.

Fires when a new device registers and asks to be admitted. The dispatcher admits it on the Devices page or from the alert.

layout.onDeviceAsks { Device d ->
   say "${d.name} asks to be admitted"
}

onShutdown

When the scripts stop: a few seconds at most.

Fires when the scripts stop (saving, switching off, TRAX Control stopping). You have a few seconds at most; do not count on it always completing.

layout.onShutdown {
   log "scripts stopping"
}