Zum Inhalt springen

Modul:Infobox Bahnhof Japan

aus Wikipedia, der freien Enzyklopädie

Die Dokumentation für dieses Modul kann unter Modul:Infobox Bahnhof Japan/Doku erstellt werden

local p = {}

-- Farben der Linien
local lineColors = {
	["奥羽本線"]     = {bg = "#2f60a3", fg = "#ffffff"},
	["男鹿線"]       = {bg = "#66cc33", fg = "#000000"},
	["羽越本線"]     = {bg = "#b44c97", fg = "#ffffff"},
	["秋田新幹線"]   = {bg = "#e60012", fg = "#ffffff"},
}

-- Farben der Regionalgesellschaften
local operatorColors = {
	["JR北海道"] = {bg = "#2cb431", fg = "#ffffff"},
	["JR東日本"] = {bg = "#008000", fg = "#ffffff"},
	["JR東海"]   = {bg = "#f77321", fg = "#ffffff"},
	["JR西日本"] = {bg = "#0072bc", fg = "#ffffff"},
	["JR四国"]   = {bg = "#1cadca", fg = "#ffffff"},
	["JR九州"]   = {bg = "#ff0000", fg = "#ffffff"},
}

local leftArrow = "◄"  -- ◀
local rightArrow = "►" -- ▶

-- Farben  abrufen
local function getColors(lineName, args, prefix)
	if not lineName then return "#ccc", "#000" end

	local colorData = lineColors[lineName]
	local bg = (args["linienfarbe" .. prefix] or (colorData and colorData.bg)) or "#ccc"      -- 社色
	local fg = (args["schriftfarbe" .. prefix] or (colorData and colorData.fg)) or "#000"     -- 文字色
	return bg, fg
end

-- Linien mappen
local function renderLine(args, index)
	local prefix = index == 0 and "" or tostring(index)
	local output = {}

	local line = args["linie" .. prefix]                          -- 所属路線
	local prevStation = args["voriger_bahnhof" .. prefix]         -- 前の駅
	local nextStation = args["naechster_bahnhof" .. prefix]       -- 次の駅
	local distA = args["entfernung_zurueck" .. prefix]            -- 駅間A
	local distB = args["entfernung_vor" .. prefix]                -- 駅間B

	if not line then return "" end

	local bg, fg = getColors(line, args, prefix)

	table.insert(output, string.format(
		'<div style="background:%s;color:%s;padding:4px;margin-top:0.5em;font-weight:bold;text-align:center;">%s</div>',
		bg, fg, line))

	if prevStation or nextStation then
		table.insert(output, '<div style="display:flex;justify-content:space-between;font-size:90%;">')

		if prevStation then
			local dist = distA and " (" .. distA .. " km)" or ""
			table.insert(output, string.format(
				'<div style="width:45%%;text-align:right;">%s [[%s]]%s</div>',
				leftArrow, prevStation, dist))
		else
			table.insert(output, '<div style="width:45%;"></div>')
		end

		if nextStation then
			local dist = distB and " (" .. distB .. " km)" or ""
			table.insert(output, string.format(
				'<div style="width:45%%;text-align:left;">%s[[%s]] %s</div>',
				dist, nextStation, rightArrow))
		else
			table.insert(output, '<div style="width:45%;"></div>')
		end

		table.insert(output, '</div>')
	end

	return table.concat(output)
end

-- Für max 9 Linien wiederholen
function p.renderAdjacentStations(frame)
	local args = frame:getParent().args
	local output = {}

	for i = 0, 8 do
		local html = renderLine(args, i)
		if html ~= "" then
			table.insert(output, html)
		end
	end

	return table.concat(output, "<hr style='margin:4px 0;'>")
end

--  Kopfzeile Farbe  Regionalgesellschaft
function p.getHeaderColors(frame)
	local args = frame:getParent().args
	local operator = args["betreiber"]                         -- 所属事業者
	local defaultBg = "#ccc"
	local defaultFg = "#000"

	local color = operatorColors[operator]
	if color then
		return string.format("background:%s;color:%s;", color.bg, color.fg)
	else
		local bg = args["linienfarbe"] or defaultBg              -- 社色
		local fg = args["schriftfarbe"] or defaultFg             -- 文字色
		return string.format("background:%s;color:%s;", bg, fg)
	end
end

return p