feat(gate): 优化显示屏显示逻辑并更新版本
为 install_ticketmachine.lua 添加标准文件头注释 升级 gate.lua 版本至 v1.5.28 新增 splitDisplayLines 函数用于拆分多行显示文本 重构 draw 与 readyLine2 函数以支持多行状态文本的居中渲染 新增 displayStationCode 函数优化车站代码格式,移除 ST 前缀与多余空格
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
local DEFAULT_SERVER_BASE = "https://ticket.fse-media.group"
|
||||
local DEFAULT_SERVER_PATH = "/api/tickets/check"
|
||||
local GATE_OPEN_SECONDS = 2
|
||||
local VERSION = "v1.5.27"
|
||||
local VERSION = "v1.5.28"
|
||||
local VERSION_CHECK_INTERVAL = 5
|
||||
|
||||
local serverURL = nil
|
||||
@@ -227,6 +227,17 @@ local function centerText(y, text, color)
|
||||
termDev.write(text)
|
||||
end
|
||||
|
||||
local function splitDisplayLines(text)
|
||||
local out = {}
|
||||
text = tostring(text or "")
|
||||
if #text == 0 then return out end
|
||||
for line in text:gmatch("([^\n]*)\n?") do
|
||||
if line == "" and #out > 0 and text:sub(-1) ~= "\n" then break end
|
||||
if #line > 0 then table.insert(out, line) end
|
||||
end
|
||||
return out
|
||||
end
|
||||
|
||||
local function drawServerStatusIndicator(w)
|
||||
if w < 2 then return end
|
||||
local col = colors.yellow
|
||||
@@ -278,11 +289,17 @@ local function draw(statusLine1, statusLine2, statusColor)
|
||||
centerText(2, "GATE", colors.cyan)
|
||||
drawVersionIndicator(w)
|
||||
drawServerStatusIndicator(w)
|
||||
if statusLine1 and #statusLine1 > 0 then
|
||||
centerText(math.max(2, math.floor(h / 2)), statusLine1, statusColor or colors.white)
|
||||
local lines = {}
|
||||
for _, line in ipairs(splitDisplayLines(statusLine1)) do table.insert(lines, line) end
|
||||
for _, line in ipairs(splitDisplayLines(statusLine2)) do table.insert(lines, line) end
|
||||
if #lines > 0 then
|
||||
local maxBodyY = math.max(3, h - 1)
|
||||
local startY = math.max(3, math.floor((maxBodyY - #lines) / 2) + 1)
|
||||
for idx, line in ipairs(lines) do
|
||||
local y = startY + idx - 1
|
||||
if y > maxBodyY then break end
|
||||
centerText(y, line, statusColor or colors.white)
|
||||
end
|
||||
if statusLine2 and #statusLine2 > 0 then
|
||||
centerText(math.min(h, math.max(3, math.floor(h / 2) + 1)), statusLine2, statusColor or colors.white)
|
||||
end
|
||||
termDev.setCursorPos(1, h)
|
||||
termDev.setTextColor(colors.gray)
|
||||
@@ -852,6 +869,15 @@ local function stationCodeForSide(side)
|
||||
return defaultStationCode()
|
||||
end
|
||||
|
||||
local function displayStationCode(code)
|
||||
local s = trim(code)
|
||||
if #s == 0 then return s end
|
||||
if s:sub(1, 2):upper() == "ST" then
|
||||
s = s:sub(3):gsub("^[%s%-_]+", "")
|
||||
end
|
||||
return s
|
||||
end
|
||||
|
||||
local function isInspectionPeripheral(p)
|
||||
return type(p) == "table" and (
|
||||
type(p.getLastScanned) == "function"
|
||||
@@ -947,15 +973,38 @@ local function readyLine1()
|
||||
end
|
||||
|
||||
local function readyLine2()
|
||||
if not modeBySide then
|
||||
return "ST " .. stationCodeForSide(nil)
|
||||
local lines = {}
|
||||
local seen = {}
|
||||
local function addLine(line)
|
||||
line = trim(line)
|
||||
if #line == 0 then return end
|
||||
local key = line:lower()
|
||||
if seen[key] then return end
|
||||
seen[key] = true
|
||||
table.insert(lines, line)
|
||||
end
|
||||
local frontCode = stationCodeForSide("front")
|
||||
local backCode = stationCodeForSide("back")
|
||||
if frontCode == backCode then
|
||||
return "ST " .. frontCode
|
||||
|
||||
if type(sideStationCodeBySide) == "table" and next(sideStationCodeBySide) ~= nil then
|
||||
local orderedSides = { "front", "back", "left", "right", "top", "bottom" }
|
||||
for _, side in ipairs(orderedSides) do
|
||||
local code = displayStationCode(sideStationCodeBySide[side] or "")
|
||||
if #code > 0 then
|
||||
addLine(string.upper(side:sub(1, 1)) .. " " .. code)
|
||||
end
|
||||
return "F " .. frontCode .. " B " .. backCode
|
||||
end
|
||||
end
|
||||
|
||||
if #lines == 0 then
|
||||
for _, code in ipairs(stationCodesPayload) do
|
||||
addLine(displayStationCode(code))
|
||||
end
|
||||
end
|
||||
|
||||
if #lines == 0 then
|
||||
addLine(displayStationCode(stationCodeForSide(nil)))
|
||||
end
|
||||
|
||||
return table.concat(lines, "\n")
|
||||
end
|
||||
|
||||
local function drawReadyScreen()
|
||||
|
||||
Reference in New Issue
Block a user