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

Материал из Space Stories Wiki
Нет описания правки
Нет описания правки
 
Строка 1: Строка 1:
return {
local prototypes = mw.loadData("Module:Chemistry Lookup/data")
Chlorine = {
 
name = "Хлор",
local p = {}
color = "#00ff44",
p.chem = prototypes.chem
border = "#0077ff",
p.react = prototypes.react
bg = "#ff0077",
p.groupDirection = prototypes.groupDirection
recipes = {
 
{ reactants = { {name="Натрий", amount=1}, {name="Хлор", amount=1} }, products = { {name="Столовая соль", amount=2} } }
local function tablelength(T)
},
  local count = 0
effects = {
  for _ in pairs(T) do count = count + 1 end
{id="Poison", rate=0.5, description="Poison (0.5 единиц в секунду); Наносит 4 Poison за единицу"}
  return count
},
end
desc = "Токсичный газ, желто-зеленый, опасен для человека."
 
},
function p.card(frame)
Fluorine = {
local key = frame.args[1]
name = "Фтор",
local chem = p.chem[key]
color = "#a0ff00",
if not chem then return "" end
border = "#70bf00",
local out = '<div class="chem-card" style="background:'..chem.bg..'; border:2px solid '..chem.border..'; padding:8px; border-radius:8px; margin:4px;">'
bg = "#101010",
out = out .. '<div class="chem-card-header" style="color:'..chem.color..'; font-weight:700; font-size:1.1em; margin-bottom:4px;">'..chem.name..'</div>'
recipes = {
{ reactants = { {name="Фтор", amount=1} }, products = { {name="Результат F", amount=1} } }
if chem.recipes and tablelength(chem.recipes) > 0 then
},
out = out .. '<div class="chem-card-recipes" style="margin-bottom:4px;"><b>Рецепты:</b><br>'
effects = {
for _, recipe in pairs(chem.recipes) do
{id="Poison", rate=0.5, description="Poison (0.5 единиц в секунду); Наносит 1 Caustic и 1 Poison за единицу"}
local reactid = recipe.id or ""
},
local reactdata = p.react[reactid]
desc = "Очень реактивный бледно-жёлтый газ."
if reactdata then
},
out = out .. '<b>Ингредиенты:</b> '
Example3 = {
for i, ing in pairs(reactdata.reactants) do
name = "Пример 3",
out = out .. ing.name .. " [" .. ing.amount .. "]"
color = "#ff7f50",
if i<#reactdata.reactants then out = out .. ", " end
border = "#bf5f40",
end
bg = "#101010",
out = out .. '<br><b>Продукты:</b> '
recipes = {
for i, prod in pairs(reactdata.products) do
{ reactants = { {name="Элемент A", amount=2}, {name="Элемент B", amount=1} }, products = { {name="Результат C", amount=1} } }
out = out .. prod.name .. " [" .. prod.amount .. "]"
},
if i<#reactdata.products then out = out .. ", " end
effects = {},
end
desc = "Это демонстрационная реакция: элементы смешиваются и дают результат."
out = out .. '<br><hr style="border:1px solid #444;">'
},
end
Example4 = {
end
name = "Пример 4",
out = out .. '</div>'
color = "#7fafff",
end
border = "#5f8fbf",
bg = "#101010",
if chem.metabolisms and tablelength(chem.metabolisms) > 0 then
recipes = {
out = out .. '<div class="chem-card-effects" style="margin-bottom:4px;"><b>Эффекты:</b><br>'
{ reactants = { {name="Элемент X", amount=1}, {name="Элемент Y", amount=2} }, products = { {name="Результат Z", amount=1} } }
for k, met in pairs(chem.metabolisms) do
},
for _, e in pairs(met.effects) do
effects = {},
out = out .. e.description .. "<br>"
desc = "Демонстрация другой реакции с кастомным описанием."
end
},
end
Hydrogen = {
out = out .. '</div>'
name = "Водород",
end
color = "#66ccff",
border = "#3399cc",
out = out .. '<div class="chem-card-desc" style="font-size:0.9em;">'..chem.desc..'</div>'
bg = "#101010",
out = out .. '</div>'
recipes = {},
return out
effects = {},
end
desc = "Простейший и самый распространенный элемент во Вселенной. Газ без цвета, запаха и вкуса."
 
},
return p
Oxygen = {
name = "Кислород",
color = "#99ff99",
border = "#33cc33",
bg = "#101010",
recipes = {},
effects = {},
desc = "Газ, необходимый для дыхания живых организмов. В нормальных условиях бесцветный и без запаха."
},
Gold = {
name = "Золото",
color = "#ffd700",
border = "#bfa500",
bg = "#101010",
recipes = {},
effects = {},
desc = "Мягкий, желтый металл, который хорошо проводит электричество и тепло. Используется в ювелирных изделиях."
},
Carbon = {
name = "Углерод",
color = "#aaaaaa",
border = "#777777",
bg = "#101010",
recipes = {},
effects = {},
desc = "Элемент, образующий основу органической химии. Встречается в алмазах, графите и живых организмах."
}
}

Текущая версия от 08:05, 11 ноября 2025

Для документации этого модуля может быть создана страница Модуль:ChemCard/data/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

function p.card(frame)
	local key = frame.args[1]
	local chem = p.chem[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 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
					out = out .. ing.name .. " [" .. ing.amount .. "]"
					if i<#reactdata.reactants then out = out .. ", " end
				end
				out = out .. '<br><b>Продукты:</b> '
				for i, prod in pairs(reactdata.products) do
					out = out .. prod.name .. " [" .. prod.amount .. "]"
					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 .. e.description .. "<br>"
			end
		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