Reference
SignalMod
Indication and the earlier shared-vocabulary declaration; prefer signalModel for new projects.
Usage context
| Module | Package | SDK source |
|---|---|---|
| Kotlin/Native | nimby | kotlin/src/nimby/SignalMod.kt |
Public API for SDK 0.9.0-alpha.2. Each entry provides the Kotlin signature and its contract: what the value means, conditions of use and effects to understand. Choose imports from the module shown above.
import nimby.Indication
import nimby.SignalModDsl
import nimby.SignalContext
import nimby.SignalDefinition
import nimby.SignalModBuilder
import nimby.signalModIndication
data class Indication<A : Enum<A>, R : Enum<R>>(val aspect: A, val reason: R)Aspect and reason typed by the model’s two enums. The aspect describes the selected state; the reason explains why. Ordinals used by test recipes remain local: append new values at the end.
Indication.aspect
val aspect: AValue from this model’s aspect enum. The mod explicitly associates the aspect with appearance and driving behaviour.
Indication.reason
val reason: RValue from this model’s reason enum. Two indications with the same aspect may have different reasons and permissions.
SignalModDsl
annotation class SignalModDslKotlin signalling-DSL annotation limiting nested implicit receivers. Has no in-game effect; use the builder functions.
SignalContext
class SignalContext<A : Enum<A>, R : Enum<R>>Context for the shared-enum SignalModBuilder declaration. For new independent models, use SignalRuleContext. The SDK supplies this context; its properties trigger no game reads.
SignalContext.next
val next: Indication<A, R>?Neighbour indication in the mod’s shared enums, or null before resolution. Returning null from rules asks the SDK to resolve the downstream link.
SignalContext.signal
val signal: SignalWorking signal copy with approach validation. Check settingsStatus: a checkbox default does not prove the profile was readable.
SignalContext.observation
val observation: ObservationObservation from this context’s signal value. Check fresh and routeKnown before concluding that a track is clear.
SignalContext.block
val block: OccupancyPhysical block occupancy in this observation; rules need an explicit branch for Unknown.
SignalContext.fresh
val fresh: BooleanFreshness of the context observation after approach validation. false calls for the mod’s fallback policy.
SignalContext.routeKnown
val routeKnown: BooleanIndicates whether the observed route is known. true does not prove it clear or reserved for a train.
SignalContext.approachingTrain
val approachingTrain: Long?Validated ID of a fresh approach; null when no usable approach exists. Do not retain it as evidence of reservation.
SignalContext.trainApproaching
val trainApproaching: Booleantrue when a train head is observed approaching with fresh data. Means neither a clear block nor permission to pass.
SignalContext.settingsStatus
val settingsStatus: SettingsStatusSettings-profile status retained in the context, even when default values are used.
SignalContext.enabled
fun enabled(option: Checkbox): BooleanReads this checkbox, using its default when the key is missing. Rejects a checkbox declaration belonging to another model; the default does not replace checking settingsStatus.
SignalDefinition
class SignalDefinition<A : Enum<A>, R : Enum<R>>Type declaration in the shared-enum DSL. Supplied by SignalModBuilder.signal; for an independent model, use signalModel and SignalModelBuilder.
SignalDefinition.observeApproach
var observeApproach: BooleanEnables approach observation for this type; defaults to false. Prefer observeApproach(blocks) to choose its range as well.
SignalDefinition.approachBlocks
var approachBlocks: IntNumber of upstream blocks to observe, from 1 to 16. Has an effect only when observeApproach is enabled.
SignalDefinition.observeApproach
fun observeApproach(blocks: Int): UnitEnables approach detection and sets its range to 1 through 16 upstream blocks. Traversal chooses no arbitrary branch; the mod then decides whether to open.
SignalDefinition.checkbox
fun checkbox(name: String, label: String, description: String = "", defaultValue: Boolean = false,
onlyWhenEnabled: Boolean = false): CheckboxRegisters a model-local checkbox and returns its declaration for enabled. Keep its name stable; label and help accept tr. onlyWhenEnabled suits acknowledgement warnings.
SignalDefinition.rules
fun rules(block: SignalContext<A, R>.() -> Indication<A, R>?): UnitDeclares the required pure rule. Return an indication to conclude locally, or null to request the neighbour. A missing link or cycle without a local decision uses invalidNetwork.
SignalDefinition.action
fun action(id: String, label: String, whenMod: String, service: String): UnitAdds an optional button tied to a provider and service. Up to 16 unique IDs per model; declaring it does not call the service.
SignalDefinition.evaluate
fun evaluate(block: (Map<String, Boolean>, Observation) -> Indication<A, R>): UnitDeclares an optional isolated calculation for diagnostics and tests. Does not resolve a network; in-game calculation uses rules and observed links.
SignalDefinition.migrateSettings
fun migrateSettings(block: (Map<String, Boolean>) -> Map<String, Boolean>): UnitConverts actually saved keys when loading the profile. Return the new keys; the SDK fills missing defaults after this pure callback.
SignalDefinition.prepareObservation
fun prepareObservation(block: (Signal) -> Signal): UnitDeclares pure preparation of the observed signal before its rules. Does not read the game or persist values; preserve observation meaning and validity.
SignalDefinition.allowForcedAspect
fun allowForcedAspect(block: (A) -> Indication<A, R>?): UnitExplicitly permits indications for in-game test recipes. The callback chooses the reason together with the aspect, or null to reject. Without this declaration, all forcing is rejected.
SignalModBuilder
class SignalModBuilder<A : Enum<A>, R : Enum<R>>Signalling DSL with enums shared by every type in the mod. For independent families, prefer SignalModelsBuilder and signalModel; the SDK creates this builder.
SignalModBuilder.options
fun options(vararg values: ModOption<*>): UnitRegisters one or more global preferences; multiple calls append options. Rejects duplicate IDs and more than 64 options including window shortcuts. Keep the declared objects to read their value.
SignalModBuilder.maximumLineSpeed
var maximumLineSpeed: Boolean = falseReplaces the timetable cruising ceiling with the rolling-stock maximum, subject to track limits and braking targets. Defaults to false; its scope is broader than this mod’s signals alone.
SignalModBuilder.diagnosticFile
var diagnosticFile: String = "nimby-kotlin-faults.jsonl"Mod fault-log filename; defaults to nimby-kotlin-faults.jsonl. Choosing a project-specific name helps diagnostics.
SignalModBuilder.signal
fun signal(id: String, title: String, textures: String, block: SignalDefinition<A, R>.() -> Unit): UnitAdds a type to the shared-enum DSL with explicit identifier, title and catalogue. The block defines its checkboxes and rules; image and driving functions are shared by the builder.
SignalModBuilder.signal
fun signal(type: SignalType, block: SignalDefinition<A, R>.() -> Unit): UnitAdds an existing SignalType declaration to the shared-enum DSL, useful when sharing it with tests. Complete its rules in the block.
SignalModBuilder.images
fun images(block: (Indication<A, R>) -> String): UnitMaps each indication to a steady image path declared in construction.states. Replaces an earlier appearance declaration; selection creates no driving rule.
SignalModBuilder.animatedImages
fun animatedImages(block: (Indication<A, R>, Long, Long) -> String): UnitImage-selection callback receiving indication, simulation time and half-period in ms. For a two-image blink, prefer appearance with blink so the SDK handles the phase.
SignalModBuilder.appearance
fun appearance(block: (Indication<A, R>) -> SignalAnimation): UnitDescribes each indication’s appearance with steady or blink. Also declare all paths in the catalogue; pause and acceleration follow simulation time.
SignalModBuilder.driving
fun driving(block: (Indication<A, R>) -> DrivingRule?): UnitMaps the complete indication to an explicit rule, preferably through AutomaticDriving. null means no rule supplied; colour grants no permission.
SignalModBuilder.faults
fun faults(block: (Indication<A, R>) -> Boolean): UnitSelects which indications appear as faults in diagnostics. Defaults to false; this classification does not replace your fallback rule.
SignalModBuilder.activeWhen
fun activeWhen(block: (Indication<A, R>) -> Boolean): UnitSelects whether an indication is actively managed. Defaults to true; distinguishes a disabled model from a closed but active signal.
SignalModBuilder.aspectNames
fun aspectNames(block: (A) -> String): UnitDeclares aspect labels for diagnostics. Without a callback, the enum value’s name is used; this text does not change the aspect.
SignalModBuilder.reasonNames
fun reasonNames(block: (R) -> String): UnitDeclares reason labels explaining decisions. Without a callback, the enum name is used.
SignalModBuilder.drivingPlan
fun drivingPlan(block: (Vehicle, DrivingSettings, DrivingInput, List<Constraint>) -> DrivingPlan): UnitDeclares a planning calculation over copied vehicle, settings, situation and constraints. Returns an advisory DrivingPlan; does not replace in-game DrivingRule values.
signalMod
inline fun <reified A : Enum<A>, reified R : Enum<R>> signalMod(
id: String, title: String, fallback: Indication<A, R>,
invalidNetwork: Indication<A, R> = fallback,
noinline block: SignalModBuilder<A, R>.() -> Unit
): SignallingModBuilds a mod whose models all share the same enums. fallback handles unknown calculation; invalidNetwork handles absent or cyclic dependencies. For new independent models, prefer signalModel followed by signalMod(modInfo).