Dantes (обсуждение | вклад) Нет описания правки Метка: отменено |
Dantes (обсуждение | вклад) Нет описания правки Метка: отменено |
||
| Строка 10: | Строка 10: | ||
for _ in pairs(T) do count = count + 1 end | for _ in pairs(T) do count = count + 1 end | ||
return count | return count | ||
end | |||
local function safe(val, default) | |||
if val == nil then return default end | |||
return val | |||
end | end | ||
| Строка 16: | Строка 21: | ||
local chem = p.chem[key] | local chem = p.chem[key] | ||
if not chem then return "" end | if not chem then return "" end | ||
local out = '<div class="chem-card" style="background:'. | |||
out = out .. '<div class="chem-card-header" style="color:'. | local bg = safe(chem.bg, "#101010") | ||
local border = safe(chem.border, "#777") | |||
local color = safe(chem.color, "#FFF") | |||
local out = '<div class="chem-card" style="background:'..bg..'; border:2px solid '..border..'; padding:8px; border-radius:8px; margin:4px;">' | |||
out = out .. '<div class="chem-card-header" style="color:'..color..'; font-weight:700; font-size:1.1em; margin-bottom:4px;">'..safe(chem.name,"Unknown")..'</div>' | |||
if chem.recipes and tablelength(chem.recipes) > 0 then | if chem.recipes and tablelength(chem.recipes) > 0 then | ||
| Строка 27: | Строка 37: | ||
out = out .. '<b>Ингредиенты:</b> ' | out = out .. '<b>Ингредиенты:</b> ' | ||
for i, ing in pairs(reactdata.reactants) do | for i, ing in pairs(reactdata.reactants) do | ||
out = out .. | local iname = safe(ing.name, "Unknown") | ||
local iamount = safe(ing.amount, 1) | |||
out = out .. iname .. " [" .. iamount .. "]" | |||
if i<#reactdata.reactants then out = out .. ", " end | if i<#reactdata.reactants then out = out .. ", " end | ||
end | end | ||
out = out .. '<br><b>Продукты:</b> ' | out = out .. '<br><b>Продукты:</b> ' | ||
for i, prod in pairs(reactdata.products) do | for i, prod in pairs(reactdata.products) do | ||
out = out .. | local pname = safe(prod.name, "Unknown") | ||
local pamount = safe(prod.amount, 1) | |||
out = out .. pname .. " [" .. pamount .. "]" | |||
if i<#reactdata.products then out = out .. ", " end | if i<#reactdata.products then out = out .. ", " end | ||
end | end | ||
| Строка 45: | Строка 59: | ||
for k, met in pairs(chem.metabolisms) do | for k, met in pairs(chem.metabolisms) do | ||
for _, e in pairs(met.effects) do | for _, e in pairs(met.effects) do | ||
out = out .. e.description .. "<br>" | out = out .. safe(e.description,"") .. "<br>" | ||
end | end | ||
end | end | ||
| Строка 51: | Строка 65: | ||
end | end | ||
out = out .. '<div class="chem-card-desc" style="font-size:0.9em;">'..chem.desc..'</div>' | out = out .. '<div class="chem-card-desc" style="font-size:0.9em;">'..safe(chem.desc,"")..'</div>' | ||
out = out .. '</div>' | out = out .. '</div>' | ||
return out | return out | ||
Версия от 08:07, 11 ноября 2025
Для документации этого модуля может быть создана страница Модуль:ChemCard/doc
local prototypes = mw.loadData("Module:Chemistry Lookup/data")
local p = {}
p.chem = prototypes.chem
p.react = prototypes.react
p.groupDirection = prototypes.groupDirection
local function tablelength(T)
local count = 0
for _ in pairs(T) do count = count + 1 end
return count
end
local function safe(val, default)
if val == nil then return default end
return val
end
function p.card(frame)
local key = frame.args[1]
local chem = p.chem[key]
if not chem then return "" end
local bg = safe(chem.bg, "#101010")
local border = safe(chem.border, "#777")
local color = safe(chem.color, "#FFF")
local out = '<div class="chem-card" style="background:'..bg..'; border:2px solid '..border..'; padding:8px; border-radius:8px; margin:4px;">'
out = out .. '<div class="chem-card-header" style="color:'..color..'; font-weight:700; font-size:1.1em; margin-bottom:4px;">'..safe(chem.name,"Unknown")..'</div>'
if chem.recipes and tablelength(chem.recipes) > 0 then
out = out .. '<div class="chem-card-recipes" style="margin-bottom:4px;"><b>Рецепты:</b><br>'
for _, recipe in pairs(chem.recipes) do
local reactid = recipe.id or ""
local reactdata = p.react[reactid]
if reactdata then
out = out .. '<b>Ингредиенты:</b> '
for i, ing in pairs(reactdata.reactants) do
local iname = safe(ing.name, "Unknown")
local iamount = safe(ing.amount, 1)
out = out .. iname .. " [" .. iamount .. "]"
if i<#reactdata.reactants then out = out .. ", " end
end
out = out .. '<br><b>Продукты:</b> '
for i, prod in pairs(reactdata.products) do
local pname = safe(prod.name, "Unknown")
local pamount = safe(prod.amount, 1)
out = out .. pname .. " [" .. pamount .. "]"
if i<#reactdata.products then out = out .. ", " end
end
out = out .. '<br><hr style="border:1px solid #444;">'
end
end
out = out .. '</div>'
end
if chem.metabolisms and tablelength(chem.metabolisms) > 0 then
out = out .. '<div class="chem-card-effects" style="margin-bottom:4px;"><b>Эффекты:</b><br>'
for k, met in pairs(chem.metabolisms) do
for _, e in pairs(met.effects) do
out = out .. safe(e.description,"") .. "<br>"
end
end
out = out .. '</div>'
end
out = out .. '<div class="chem-card-desc" style="font-size:0.9em;">'..safe(chem.desc,"")..'</div>'
out = out .. '</div>'
return out
end
return p