Модуль:ChemCard: различия между версиями

Материал из Space Stories Wiki
Нет описания правки
Метка: отменено
Нет описания правки
Метка: отменено
Строка 1: Строка 1:
local data = require("Module:ChemCard/data")
local p = {}
local p = {}
local data = mw.loadData("Module:ChemCard/data")


function p.card(frame)
function p.card(frame)
local proto = frame.args.prototype
local key = frame.args[1]
local chem = data[proto]
local chem = data[key]
if not chem then return "Нет данных для " .. proto end
if not chem then return "" end
 
local out = '<div class="chem-card" style="background:'..chem.bg..'; border:2px solid '..chem.border..'; padding: 8px; border-radius: 8px; margin: 4px;">'
local out = mw.html.create("div")
out = out .. '<div class="chem-card-header" style="color:'..chem.color..'; font-weight: 700; font-size: 1.1em; margin-bottom: 4px;">'..chem.name..'</div>'
out:addClass("chem-card")
out:cssText(
if chem.recipes and #chem.recipes>0 then
"background-color:"..chem.bg..";border:2px solid "..chem.border..";color:"..chem.color..
out = out .. '<div class="chem-card-recipes" style="margin-bottom: 4px;"><b>Рецепты:</b><br>'
";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
for _, r in ipairs(chem.recipes) do
recipeBlock:tag("div"):wikitext(r)
out = out .. '<b>Ингредиенты:</b> '
for i, ing in ipairs(r.reactants) do
out = out .. ing.name.." ["..ing.amount.."]"
if i<#r.reactants then out = out .. ", " end
end
out = out .. '<br><b>Продукты:</b> '
for i, p in ipairs(r.products) do
out = out .. p.name.." ["..p.amount.."]"
if i<#r.products then out = out .. ", " end
end
out = out .. '<br><hr style="border:1px solid #444;">'
end
end
out:node(recipeBlock)
out = out .. '</div>'
end
end
 
if chem.effects and #chem.effects > 0 then
if chem.effects and #chem.effects>0 then
local effectBlock = mw.html.create("div")
out = out .. '<div class="chem-card-effects" style="margin-bottom:4px;"><b>Эффекты:</b><br>'
effectBlock:wikitext("Эффекты:\n")
for _, e in ipairs(chem.effects) do
for _, e in ipairs(chem.effects) do
effectBlock:tag("div"):wikitext(e)
out = out .. e.description.."<br>"
end
end
out:node(effectBlock)
out = out .. '</div>'
end
 
if chem.desc then
out:tag("div"):wikitext(chem.desc)
end
end
 
return tostring(out)
out = out .. '<div class="chem-card-desc" style="font-size:0.9em;">'..chem.desc..'</div>'
out = out .. '</div>'
return out
end
end


return p
return p

Версия от 08:03, 11 ноября 2025

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

local data = require("Module:ChemCard/data")

local p = {}

function p.card(frame)
	local key = frame.args[1]
	local chem = data[key]
	if not chem then return "" end
	local out = '<div class="chem-card" style="background:'..chem.bg..'; border:2px solid '..chem.border..'; padding: 8px; border-radius: 8px; margin: 4px;">'
	out = out .. '<div class="chem-card-header" style="color:'..chem.color..'; font-weight: 700; font-size: 1.1em; margin-bottom: 4px;">'..chem.name..'</div>'
	
	if chem.recipes and #chem.recipes>0 then
		out = out .. '<div class="chem-card-recipes" style="margin-bottom: 4px;"><b>Рецепты:</b><br>'
		for _, r in ipairs(chem.recipes) do
			out = out .. '<b>Ингредиенты:</b> '
			for i, ing in ipairs(r.reactants) do
				out = out .. ing.name.." ["..ing.amount.."]"
				if i<#r.reactants then out = out .. ", " end
			end
			out = out .. '<br><b>Продукты:</b> '
			for i, p in ipairs(r.products) do
				out = out .. p.name.." ["..p.amount.."]"
				if i<#r.products then out = out .. ", " end
			end
			out = out .. '<br><hr style="border:1px solid #444;">'
		end
		out = out .. '</div>'
	end
	
	if chem.effects and #chem.effects>0 then
		out = out .. '<div class="chem-card-effects" style="margin-bottom:4px;"><b>Эффекты:</b><br>'
		for _, e in ipairs(chem.effects) do
			out = out .. e.description.."<br>"
		end
		out = out .. '</div>'
	end
	
	out = out .. '<div class="chem-card-desc" style="font-size:0.9em;">'..chem.desc..'</div>'
	out = out .. '</div>'
	return out
end

return p