Модуль:ChemCard

Материал из Space Stories Wiki

Для документации этого модуля может быть создана страница Модуль:ChemCard/doc

local p = {}
local data = mw.loadData("Module:ChemCard/data")

function p.card(frame)
	local proto = frame.args.prototype
	local chem = data[proto]
	if not chem then return "Нет данных для " .. proto end

	local out = mw.html.create("div")
	out:addClass("chem-card")
	out:cssText(
		"background-color:"..chem.bg..";border:2px solid "..chem.border..";color:"..chem.color..
		";padding:8px;margin:4px;border-radius:8px;flex:0 1 calc(25% - 12px);max-width:320px;min-width:200px;"
	)

	out:tag("div"):cssText("font-weight:700;margin-bottom:4px;"):wikitext(chem.name)

	if chem.recipes and #chem.recipes > 0 then
		local recipeBlock = mw.html.create("div")
		recipeBlock:wikitext("Рецепт:\n")
		for _, r in ipairs(chem.recipes) do
			recipeBlock:tag("div"):wikitext(r)
		end
		out:node(recipeBlock)
	end

	if chem.effects and #chem.effects > 0 then
		local effectBlock = mw.html.create("div")
		effectBlock:wikitext("Эффекты:\n")
		for _, e in ipairs(chem.effects) do
			effectBlock:tag("div"):wikitext(e)
		end
		out:node(effectBlock)
	end

	if chem.desc then
		out:tag("div"):wikitext(chem.desc)
	end

	return tostring(out)
end

return p