模組:GZBUS
閱讀設定
模組解[開]
你可能想去為呢個Scribunto module開一個解版。 編者可以響呢個模組嘅沙盤 (開 | 鏡)同埋試例 (開)版度試驗佢。 請加個類到個/doc嘅細版度。 呢個模組嘅細版。 |
-- 聲明模組本體
local p = {}
-- 導入數據
local c = mw.loadData('Module:GZBUS/color')
local function _loadSystemData(loc)
local state
if loc == "南沙" then
state, system = pcall(mw.loadData, "Module:GZBUS/nansha")
elseif loc == "花都" then
state, system = pcall(mw.loadData, "Module:GZBUS/huadu")
elseif loc == "番禺" then
state, system = pcall(mw.loadData, "Module:GZBUS/panyu")
elseif loc == "增城" then
state, system = pcall(mw.loadData, "Module:GZBUS/zengcheng")
elseif loc == "从化" or loc == "從化" then
state, system = pcall(mw.loadData, "Module:GZBUS/conghua")
elseif loc == "佛山" then
state, system = pcall(mw.loadData, "Module:GZBUS/foshan") -- 廣佛線
elseif loc == "东莞" or loc == "東莞" then
state, system = pcall(mw.loadData, "Module:GZBUS/dongguan") -- 穗莞線
else
state, system = pcall(mw.loadData, "Module:GZBUS/data")
end
return system
end
-- 建立路線名稱反查解析表
do
p.revName = {}
for i, t in pairs(c.company) do
for _, k in pairs(t) do
p.revName[k] = t[1]
end
end
end
-- {{廣州巴士公司色塊}}
function p._internalColorbox(compname)
str = compname
len = #str
if len >18 or compname == "multi" then
return [[width="1%" style="background:]]..c.colors['multi']..[["]] -- 公司名超過六個字自動為聯營
else
if p.revName[compname] then
return [[width="1%" style="background:]]..c.colors[p.revName[compname]]..[["]]
else
return [[width="1%" style="background:]]..c.colors['other']..[["]]
end
end
end
-- 處理起訖點中出現嘅跨中文維基百科嘅鏈接模({{tsl|zh|arg1|arg2|arg3}})
function p.tsllink(name)
str = name
if string.find(name, "tsl") then
start = string.find(name, "{")
en3 = string.find(name, "}", start)
en1 = string.find(name, "|", start+9)
arg1 = string.sub(name, start+9, en1-1)
en2 = string.find(name, "|", en1+1)
arg2 = string.sub(name, en1+1, en2-1)
arg3 = string.sub(name, en2+1, en3-1)
no1 = string.sub(name, 0, start-1)
fi1 = string.find(name, "{", en2+1)
if fi1 == nil then -- 只引用一次tsl
no2 = string.sub(name, en3+2, string.len(name))
str = no1..mw.getCurrentFrame():expandTemplate{title = "tsl", args = {"zh", arg1, arg2, arg3}}..no2
else -- 引用兩次tsl
start1 = string.find(name, "{", en3)
no2 = string.sub(name, en3+2, start1-1)
en4 = string.find(name, "|", start1+9)
arg4 = string.sub(name, start1+9, en4-1)
en5 = string.find(name, "|", en4+1)
arg5 = string.sub(name, en4+1, en5-1)
en6 = string.find(name, "}", start1)
arg6 = string.sub(name, en5+1, en6-1)
no3 = string.sub(name, en6+2, string.len(name))
str = no1..mw.getCurrentFrame():expandTemplate{title = "tsl", args = {"zh", arg1, arg2, arg3}}..no2..mw.getCurrentFrame():expandTemplate{title = "tsl", args = {"zh", arg4, arg5, arg6}}..no3
end
return str
else
return str
end
end
-- 生成一條線嘅一列表格內容
function p._internalList(no, style, loc)
local d = _loadSystemData(loc)
if d[no] == nil then
a = [[|width="1%"| ||align=center|''']]..no..[['''||colspan=3 align=center|''(錯誤:]]..'[[Module:GZBUS]]中冇呢條[['..loc.."巴士線一覽|"..loc.."]]嘅路線)''"
elseif d[no].note == "已停辦" or d[no].note == "已停办" then
a = [[|width="1%"| ||align=center|''']]..d[no].code..[['''||colspan=3 align=center|''(錯誤:本線已經冇咗或暫停服務,請剔除)'']]
else
b = p._internalColorbox(d[no].company) -- 生成顏色方塊
e1 = p.tsllink(d[no].endpoint1) -- 處理起訖點1可能出現的{{tsl|zh-yue}}
e2 = p.tsllink(d[no].endpoint2) -- 處理起訖點2可能出現的{{tsl|zh-yue}}
-- BRT樣式(注:不顯示公司欄(noco)已不適用於BRT樣式):
if ((style == "BRT" or style == "brt") and (d[no].brt_west == nil)) then -- 不是BRT路線
a = [[|width="1%"| ||align=center|''']]..no.."'''||colspan=8 align=center|''(錯誤:呢條線唔係[[廣州快速公交運輸系統|BRT路線]])''"
elseif ((style == "BRT" or style == "brt") and (d[no].code == "B28")) then -- BRT樣式:B28(四列)
a = [[|rowspan="4"]]..b..[[| ||rowspan="4" align=center|'''B28'''||align=right rowspan="4"|]]..e1..[[||rowspan="2" align=center|→||rowspan="4"|]]..e2..[[||align=center|]]..d[no].brt_east_in..[[||align=center|]]..d[no].brt_east_out..[[||align=center|]]..d[no].brt_east..[[||align=center rowspan="4"|]]..d[no].company..[[||rowspan="4"|]]..d[no].note.."\n|-\n"..[[|align=center|]]..d[no].brt_east_in1..[[||align=center|]]..d[no].brt_east_out1..[[||align=center|]]..d[no].brt_east1.."\n|-\n"..[[|rowspan="2" align=center|←||align=center|]]..d[no].brt_west_in..[[||align=center|]]..d[no].brt_west_out..[[||align=center|]]..d[no].brt_west.."\n|-\n"..[[|align=center|]]..d[no].brt_west_in1..[[||align=center|]]..d[no].brt_west_out1..[[||align=center|]]..d[no].brt_west1
elseif ((style == "BRT" or style == "brt") and (d[no].brt_east == nil)) then -- BRT樣式:早高峰單向路線(一列)
a = [[|]]..b..[[| ||align=center|''']]..d[no].code..[['''||align=right|]]..e1..[[||align=center|早<br />←||align=left|]]..e2..[[||align=center|]]..d[no].brt_west_in..[[||align=center|]]..d[no].brt_west_out..[[||align=center|]]..d[no].brt_west..[[||align=center|]]..d[no].company..[[||]]..d[no].note
elseif ((style == "BRT" or style == "brt") and (d[no].brt_east ~= nil)) then -- BRT樣式:除B28外的雙向路線(兩列)
a = [[| rowspan="2"]]..b..[[| ||rowspan="2" align=center|''']]..d[no].code..[['''||align=right rowspan="2" |]]..e1..[[||align=center|→|| rowspan="2" |]]..e2..[[||align=center|]]..d[no].brt_east_in..[[||align=center|]]..d[no].brt_east_out..[[||align=center|]]..d[no].brt_east..[[||align=center rowspan="2" |]]..d[no].company..[[|| rowspan="2" |]]..d[no].note.."\n|-\n"..[[|align=center|←||align=center|]]..d[no].brt_west_in..[[||align=center|]]..d[no].brt_west_out..[[||align=center|]]..d[no].brt_west
-- 非BRT樣式:
else
-- 非BRT樣式:部分雙向高峰快線(兩列):
if d[no].direction1 ~= nil then
a = [[|rowspan="2"]]..b..[[| ||rowspan="2" align=center|''']]..d[no].code..[['''||rowspan="2" align=right|]]..e1..[[||align=center|]]..d[no].direction
if (d[no].endpoint3 ~= nil) then -- 部分雙向高峰快線:去程終點和返程起點不同
a = a..[[||]]..e2
else -- 部分雙向高峰快線:去程終點和返程起點相同
a = a..[[||rowspan="2"|]]..e2
end
if style == "noco" or style == "nocotr" then -- 不顯示公司欄(noco、nocotr)
a = a..[[||rowspan="2" align=center|]]..d[no].fare
elseif style == "nofa" then -- 不顯示票價欄(nofa)
a = a..[[||rowspan="2" align=center|]]..d[no].company
elseif style == "nocofa" then -- 不顯示公司和票價欄(nocofa)
a = a
else -- 顯示公司和票價欄(notr、nodo、默認)
a = a..[[||rowspan="2" align=center|]]..d[no].fare..[[||rowspan="2" align=center|]]..d[no].company
end
a = a..[[||rowspan="2"|]]..d[no].note.."\n|-\n"..[[|align=center|]]..d[no].direction1
if d[no].endpoint3 ~= nil then -- 部分雙向高峰快線:去程終點和返程起點不同
a = a..[[||]]..d[no].endpoint3
else -- 部分雙向高峰快線:去程終點和返程起點相同
a = a
end
-- 非BRT樣式:其他(一列):
else
a = [[|]]..b..[[| ||align=center|''']]..d[no].code..[['''||align=right|]]..e1..[[||align=center|]]..d[no].direction..[[||align=left|]]..e2
if (style == "noco" or style == "nocotr") then -- 不顯示公司欄(noco、nocotr)
a = a..[[||align=center|]]..d[no].fare
elseif style == "nofa" then -- 不顯示票價欄(nofa)
a = a..[[||align=center|]]..d[no].company
elseif style == "nocofa" then -- 不顯示公司和票價欄(nocofa)
a = a
else -- 顯示公司和票價欄(notr、nodo、默認)
a = a..[[||align=center|]]..d[no].fare..[[||align=center|]]..d[no].company
end
a = a..[[||]]..d[no].note
if (style == "notr" or style == "nocotr") then -- 不顯示無軌電車信息(notr、nocotr)
if (d[no].doubledecker==1) then
if d[no].note ~= "" and d[no].note ~= nil then a = a..[[;雙層巴士線]]
else a = a..[[雙層巴士線]] end
end
elseif style == "nodo" then -- 不顯示雙層巴士信息(nodo)
if (d[no].trolleybus==1) then
if d[no].note ~= "" and d[no].note ~= nil then a = a..[[;無軌電車線]]
else a = a..[[無軌電車線]] end
end
else
if (d[no].doubledecker==1) then
if d[no].note ~= "" and d[no].note ~= nil then a = a..[[;雙層巴士線]]
else a = a..[[雙層巴士線]] end
if (d[no].trolleybus==1) then a = a..[[、無軌電車線]] end
elseif (d[no].trolleybus==1) then
if d[no].note ~= "" and d[no].note ~= nil then a = a..[[;無軌電車線]]
else a = a..[[無軌電車線]] end
end
end
end
end
end
return a
end
-- {{廣州巴士線一覽}}
function p.list(frame)
local bb = frame.args
local loc = bb.loc
if loc == "" or loc == nil then loc = "廣州" end
local ret = p._internalList(bb.code, bb.format, loc)
return ret
end
-- 生成一條線嘅一列簡單表格內容
function p._internalSimpList(no, loc, vehicle)
local d = _loadSystemData(loc)
if d[no] == nil then
a = [[|align=center|''']]..no..[['''||colspan=3 align=center|''(錯誤:]]..'[[Module:GZBUS]]中冇呢條[['..loc.."巴士線一覽|"..loc.."]]嘅路線)''"
elseif d[no].note == "已停办" or d[no].note == "已停辦" then
a = [[|align=center|''']]..d[no].code..[['''||colspan=3 align=center|''(錯誤:本線已經冇咗或暫停服務,請剔除)'']]
else
e1 = p.tsllink(d[no].endpoint1) -- 處理起訖點1可能出現的{{tsl|zh}}
e2 = p.tsllink(d[no].endpoint2) -- 處理起訖點2可能出現的{{tsl|zh}}
-- 部分雙向高峰快線(兩列):
if d[no].direction1 ~= nil then
a = [[|rowspan="2" align=center|''']]..d[no].code..[['''||rowspan="2" align=right|]]..e1..[[||align=center|]]..d[no].direction
if d[no].endpoint3 ~= nil then -- 部分雙向高峰快線:去程終點和返程起點不同
a = a..[[||align=left|]]..e2
else -- 部分雙向高峰快線:去程終點和返程起點相同
a = a..[[||rowspan="2" align=left|]]..e2
end
a = a..[[||rowspan="2"|]].."\n|-\n"..[[|align=center|]]..d[no].direction1
if d[no].endpoint3 ~= nil then -- 部分雙向高峰快線:去程終點和返程起點不同
a = a..[[||align=left|]]..d[no].endpoint3
else -- 部分雙向高峰快線:去程終點和返程起點相同
a = a
end
-- 其他(一列):
else
a = [[|''']]..d[no].code..[['''||align=right|]]..e1..[[||align=center|]]..d[no].direction..[[||align=left|]]..e2..[[||]]
end
end
return a
end
-- {{廣州巴士線簡單表}}
function p.simplelist(frame)
local ss = frame.args
local loc = ss.loc
if loc == "" or loc == nil or loc == "广州" then loc = "廣州" end
local ret = p._internalSimpList(ss.code, loc)
return ret
end
-- 生成表格表頭
function p._internalTitle(style, loc)
if loc == "" or loc == nil then loc = "廣州" end
if (style == "BRT" or style == "brt")then
t = '!colspan="2" width="8.5%"|[[廣州巴士線一覽|冧巴]]!!width="25%" colspan="3"|路線!!width="10.6%"|駛入BRT通道!!width="10.6%"|駛出BRT通道!!width="8.5%"|BRT通道停靠站數!!width="14.9%"|運營商!!width="21.3%"|註'
else
if (style == "noco" or style == "nocotr") then -- 唔顯示公司欄(noco、nocotr)
t = '!colspan="2" width="14%"|[['..loc..'巴士線一覽|冧巴]]!!colspan="3"|路線!!width="10%"|全程收費!!width="22%"|註\n|-style="background:#EAECF0" height=0\n|colspan="2"| ||width="25%"| || ||width="25%"| ||colspan="2"| '
elseif style == "nofa" then -- 唔顯示票價欄(nofa)
t = '!colspan="2" width="14%"|[['..loc..'巴士線一覽|冧巴]]!!colspan="3"|路線!!width="11%"|運營商!!width="21%"|註\n|-style="background:#EAECF0" height=0\n|colspan="2"| ||width="25%"| || ||width="25%"| ||colspan="2"| '
elseif style == "nocofa" then -- 唔顯示公司和票價欄(nocofa)
t = '!colspan="2" width="16%"|[['..loc..'巴士線一覽|冧巴]]!!colspan="3"|路線!!width="24%"|註\n|-style="background:#EAECF0" height=0\n|colspan="2"| ||width="28%"| || ||width="28%"| || '
else -- 唔示公司和票價欄(notr、nodo、默認)
t = '!colspan="2" width="12%"|[['..loc..'巴士線一覽|冧巴]]!!colspan="3"|路線!!width="8%"|全程收費!!width="10%"|運營商!!width="20%"|註\n|-style="background:#EAECF0" height=0\n|colspan="2"| ||width="23%"| || ||width="23%"| ||colspan="3"| '
end
end
return t
end
-- {{廣州巴士線/表頭}}
function p.title(frame)
local tt = frame.args
local ret = p._internalTitle(tt.format, tt.loc)
return ret
end
-- {{廣州巴士公司色塊}}
function p.colorbox(frame)
local cc = frame.args
local ret = p._internalColorbox(cc.company)
return ret
end
return p