fix(station): detect create stations by capability

Use the Create station method set from the CC:Tweaked integration docs to identify attached train stations even when the peripheral type string is not reported as train_station.
This commit is contained in:
2026-08-01 10:46:26 +08:00
parent b51e31e00f
commit a92fb55f60
+27 -3
View File
@@ -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