diff --git a/station_broadcast.lua b/station_broadcast.lua index c405c96..e514619 100644 --- a/station_broadcast.lua +++ b/station_broadcast.lua @@ -2,7 +2,7 @@ -- ============================================================================ -- 1. Configuration & Constants -- ============================================================================ -local APP_VERSION_TEXT = "v1.0.12" +local APP_VERSION_TEXT = "v1.0.13" local CONFIG = { CLOUD_URL = "ws://stabadmin.fse-media.group", @@ -57,6 +57,30 @@ local State = { -- ============================================================================ local Peripherals = {} +function Peripherals.isTrainStationPeripheral(name) + if not name then + return false + end + + local pType = peripheral.getType(name) + if pType == "train_station" then + return true + end + + local wrapped = peripheral.wrap(name) + if not wrapped then + return false + end + + -- Create Wiki documents the station peripheral by its methods rather than a + -- guaranteed fixed type string. Match on the core method set so attached + -- stations are still detected across integration/version differences. + return type(wrapped.getStationName) == "function" + and type(wrapped.isTrainPresent) == "function" + and type(wrapped.getTrainName) == "function" + and type(wrapped.getSchedule) == "function" +end + function Peripherals.init() -- Station Peripheral: prefer direct sides, then fall back to any discovered peripheral name. local station = nil @@ -65,7 +89,7 @@ function Peripherals.init() local preferredSides = { "back", "top", "bottom", "left", "right", "front" } for _, side in ipairs(preferredSides) do checkedNames[side] = true - if peripheral.getType(side) == "train_station" then + if Peripherals.isTrainStationPeripheral(side) then station = peripheral.wrap(side) stationSide = side break @@ -73,7 +97,7 @@ function Peripherals.init() end if not station and peripheral.getNames then for _, name in ipairs(peripheral.getNames()) do - if not checkedNames[name] and peripheral.getType(name) == "train_station" then + if not checkedNames[name] and Peripherals.isTrainStationPeripheral(name) then station = peripheral.wrap(name) stationSide = name break