功能(站点广播): 实现延误与停运列车的双语广播功能

添加所有中日文广播所需的音频资源文件
将应用版本更新至v1.0.37
修复列车状态原因映射逻辑,补充广播所需的缺失字段
实现根据延误、停运状态生成对应双语广播序列的逻辑
更新测试脚本以适配区块阅读器并正确解析CRN的NBT数据
添加示例NBT转储文件作为参考
This commit is contained in:
2026-08-02 18:50:49 +08:00
parent f922ace154
commit 39dc446958
40 changed files with 190 additions and 75 deletions
+35 -56
View File
@@ -1,68 +1,47 @@
local target = peripheral.find("create_target")
if not target then
print("Error: Target block not found! Please check if Wired Modem is connected and activated (red ring).")
local reader = peripheral.find("blockReader")
if not reader then
print("Error: Block Reader not found!")
return
end
pcall(target.resize, 80, 10)
-- A helper function to parse the Create station summary line
-- Example input: "1 ?? [Local]1123 HC-02 2"
local function parseTrainLine(line)
-- Format we are parsing:
-- "<Time_Number> <Time_Unit> <Train_Name> <Destination>"
-- Example: "1 ?? [Local]1123 HC-02 2"
-- Example: "现在 ?? [Local]1123 HC-02 2" (assuming "现在" might replace the number and unit)
local timeValue, timeUnit, trainName, destination
-- Try parsing format with a number first (e.g., "1 ?? ...")
timeValue, timeUnit, trainName, destination = string.match(line, "^(%d+)%s+(.-)%s+(%[.-%][^%s]*)%s+(.*)$")
-- If that fails, it might be the "Now" (现在) format which might not have digits at the start
if not trainName then
timeValue, timeUnit, trainName, destination = string.match(line, "^([^%s]+)%s+(.-)%s+(%[.-%][^%s]*)%s+(.*)$")
end
-- Fallback for extremely weird formatting
if not trainName then
timeValue, timeUnit, trainName, destination = string.match(line, "^([^%s]+)%s+(.-)%s+([^%s]+)%s+(.*)$")
end
return {
eta_value = timeValue or "N/A",
eta_unit = timeUnit or "N/A",
trainName = trainName or "N/A",
destination = destination or "N/A",
raw = line
}
end
while true do
term.clear()
term.setCursorPos(1,1)
print("=== Receiving Station Data ===")
print("=== CRN Advanced Display Parser ===")
local lines = target.dump()
local hasData = false
local success, data = pcall(reader.getBlockData)
for i, lineText in pairs(lines) do
if lineText and lineText ~= "" and lineText:match("[%w%?%[]") then
print("--- Line " .. i .. " ---")
print("Raw: " .. lineText)
local parsed = parseTrainLine(lineText)
print(" Train Name : " .. parsed.trainName)
print(" Destination: " .. parsed.destination)
print(" ETA Value : " .. parsed.eta_value)
print(" ETA Unit : " .. parsed.eta_unit)
hasData = true
if success and data and data.TrainStops then
local now = os.epoch("utc") / 50 -- Minecraft ticks (approx)
for i, stop in ipairs(data.TrainStops) do
local st = stop.Station
if st then
local trainName = st.TrainName or "Unknown"
local dest = st.Destination or "Unknown"
-- 时间计算
local scheduledArrival = st.ScheduledArrival or 0
local realArrival = st.RealTimeArrival or 0
-- 计算 ETA (秒)
local etaTicks = realArrival - data.LastRefreshed
local etaSeconds = math.floor(etaTicks / 20)
if etaSeconds < 0 then etaSeconds = 0 end
-- 计算 Delay (分钟)
local delayTicks = realArrival - scheduledArrival
local delayMinutes = math.floor(delayTicks / (20 * 60))
if delayMinutes < 0 then delayMinutes = 0 end
print(string.format("[%d] Train: %s -> %s", i, trainName, dest))
print(string.format(" ETA: %d seconds", etaSeconds))
print(string.format(" Delay: %d minutes", delayMinutes))
print("---------------------------------")
end
end
end
if not hasData then
print("No active trains incoming/departing...")
else
print("Waiting for CRN data...")
end
os.sleep(1)