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

мНет описания правки
м Серная кислота не существует в раздатчике химикатов. Это миф
Метки: с мобильного устройства из мобильной версии
 
(не показано 50 промежуточных версий 1 участника)
Строка 1: Строка 1:
p = {}
p = {}
p.chem = mw.text.jsonDecode(mw.title.new("User:IanComradeBot/chem_prototypes.json"):getContent())
p.react = mw.text.jsonDecode(mw.title.new("User:IanComradeBot/react_prototypes.json"):getContent())


local prototypes = mw.loadData("Module:Chemistry Lookup/data")
p.fillReactTable = function(frame)
p.chem = prototypes.chem
p.react = prototypes.react
local out = ""
for _, reactPrototype in pairs(p.react) do
if tablelength(reactPrototype.effects) ~= 0 then
local reactants = {}
local reactantTemplate = "%s [[#chem_%s|%s]]"
for reactantId, reactantValue in pairs(reactPrototype.reactants) do
local reactantChemData = p.chem[reactantId]
local reactantText = string.format(reactantTemplate, reactantValue.amount, reactantChemData.id,  reactantChemData.name)
if reactantValue.catalyst then
reactantText = reactantText .. " (катализатор)"
end
table.insert(reactants, reactantText)
end
local templateArgs = {}
templateArgs.reactants = table.concat(reactants, "<br>")
local products = {}
local productTemplate = "%s [[#chem_%s|%s]]"
for productId, productAmount in pairs(reactPrototype.products) do
local productChemData = p.chem[productId]
local productText = string.format(productTemplate, productAmount, productChemData.id,  productChemData.name)
table.insert(products, productText)
end
-- Эффекты реакции
if tablelength(reactPrototype.effects) then
for _, effect in pairs(reactPrototype.effects) do
if effect.description ~= "" then
table.insert(products, effect.description)
end
end
end
templateArgs.products = table.concat(products, "<br>")
templateArgs.actions = getActions(reactPrototype)
local template = "Строка_реакции"
out = out .. frame:expandTemplate{ title = template, args = templateArgs}
end
end
return out
end


p.fillTable = function(frame)
p.fillChemTable = function(frame)
local out = ""
local out = ""
local group = frame.args.group
local group = frame.args.group
local groups
if group ~= nil and group ~= "" then
groups = mw.text.split(group, ",")
end
local additional = frame.args.additional
local additional = frame.args.additional
if additional ~= nil then
if additional ~= nil and additional ~= "" then
local additionalChemPrototypeIds = mw.text.split(additional, ",")
local additionalChemPrototypeIds = mw.text.split(additional, ",")
Строка 20: Строка 73:
for _, chemPrototype in pairs(p.chem) do
for _, chemPrototype in pairs(p.chem) do
if group == nil or group == "all" or chemPrototype.group == group then
if group == nil or group == "" or contains(groups, chemPrototype.group) then
out = out .. fillChemistryRow(chemPrototype.id, frame)  
out = out .. fillChemistryRow(chemPrototype.id, frame)  
end
end
Строка 28: Строка 81:
end
end


p.fillChemistryRow = function(frame)
p.fillContentOfDispencer = function(frame)
local dispencer = frame.args.dispencer
return fillChemistryRow(frame.args.id, frame)
local out = ""
for _, chemId in pairs(dispencersContent()[dispencer]) do
out = out .. frame:expandTemplate{ title = "Кнопка_реагента", args = {chemId, "y"}}
end
return out
end
 
function dispencersContent()
local content = {
["Химикатов"]={
"Aluminium","Carbon","Chlorine","Copper","Ethanol","Fluorine","Hydrogen","Iodine",
"Iron","Lithium","Mercury","Nitrogen","Oxygen","Phosphorus","Potassium","Radium",
"Silicon","Sodium","Sugar","Sulfur"
},
["Соды"]={
"Water","Ice","Coffee","Cream","Tea","GreenTea","IcedTea","IcedGreenTea",
"Cola","SpaceMountainWind","DrGibb","SpaceUp","TonicWater","SodaWater","LemonLime","Sugar",
"JuiceOrange","JuiceLime","JuiceWatermelon"
},
["Алкоголя"]={
"LemonLime","Sugar","JuiceOrange","JuiceLime","SodaWater","TonicWater","Beer","CoffeeLiqueur",
"Whiskey","Wine","Vodka","Gin","Rum","Tequila","Vermouth","Cognac",
"Ale","Mead"
}
}
return content
end
 
 
p.readArg = function(frame)
return mw.text.nowiki(p.chem[frame.args[1]][frame.args[2]])
end
 
 
function contains(list, x)
for _, v in ipairs(list) do
if v == x then return true end
end
return false
end
end


Строка 37: Строка 127:
local out = ""
local out = ""
local chemPrototype = p.chem[chemPrototypeId] -- Считаем что id совпадает с ключем p.chem
local chemPrototype = p.chem[chemPrototypeId]
local templateArgs = {}
local templateArgs = {}
templateArgs.id = chemPrototype.id
templateArgs.id = chemPrototype.id
templateArgs.name = chemPrototype.name
templateArgs.name = chemPrototype.name
templateArgs.description = chemPrototype.desc .. " На вид " .. chemPrototype.physicalDesc .. "."
templateArgs.description = chemPrototype.desc .. " На вид " .. chemPrototype.physicalDesc .. "."
templateArgs.color = getColor(chemPrototype.id)
templateArgs.color = chemPrototype.color
templateArgs.textColor = getTextColor(chemPrototype.id)
templateArgs.textColor = chemPrototype.textColor
templateArgs.effects = getEffects(chemPrototype.id)
templateArgs.recipes_count = tablelength(chemPrototype.recipes)
templateArgs.recipes_count = tablelength(chemPrototype.recipes)
Строка 60: Строка 150:
local reactPrototype = p.react[reactId]
local reactPrototype = p.react[reactId]
local reactants = {}
local reactants = {}
local reactantTemplate = "%s [[#%s|%s]]"
local reactantTemplate = "%s [[#chem_%s|%s]]"
for reactantId, reactantValue in pairs(reactPrototype.reactants) do
for reactantId, reactantValue in pairs(reactPrototype.reactants) do
Строка 66: Строка 156:
local reactantChemData = p.chem[reactantId]
local reactantChemData = p.chem[reactantId]
local reactantText = string.format(reactantTemplate, reactantValue.amount, reactantChemData.id,  reactantChemData.name)
local reactantText = string.format(reactantTemplate, reactantValue.amount, reactantChemData.id,  reactantChemData.name)
if reactantValue.catalyst then
reactantText = reactantText .. " (катализатор)"
end
table.insert(reactants, reactantText)
table.insert(reactants, reactantText)
end
end
Строка 71: Строка 164:
local products = {}
local products = {}
local productTemplate = "%s [[#%s|%s]]"
local productTemplate = "%s [[#chem_%s|%s]]"
for productId, productAmount in pairs(reactPrototype.products) do
for productId, productAmount in pairs(reactPrototype.products) do
Строка 78: Строка 171:
local productText = string.format(productTemplate, productAmount, productChemData.id,  productChemData.name)
local productText = string.format(productTemplate, productAmount, productChemData.id,  productChemData.name)
table.insert(products, productText)
table.insert(products, productText)
end
-- Эффекты реакции
if tablelength(reactPrototype.effects) then
for _, effect in pairs(reactPrototype.effects) do
if effect.description ~= "" then
table.insert(products, effect.description)
end
end
end
end
templateArgs.products = table.concat(products, "<br>")
templateArgs.products = table.concat(products, "<br>")
templateArgs.action = "[[File:Beaker.png|32px]]<br>Смешать"
templateArgs.actions = getActions(reactPrototype)
local template = "Строка_химического_вещества"
local template = "Строка_химического_вещества"
Строка 95: Строка 196:
end
end


getActions = function(reactPrototype)
local actions = {}
-- Температура
local minMaxTemplate = "выше %sК и ниже %sК"
local minTemplate = "выше %sК"
local maxTemplate = "ниже %sК"
local hasMin = reactPrototype.minTemp ~= 0
local hasMax = reactPrototype.hasMax
local tempString = ""
if hasMax and hasMin then
tempString = string.format(minMaxTemplate, reactPrototype.minTemp, reactPrototype.maxTemp)
elseif hasMin then
tempString = string.format(minTemplate, reactPrototype.minTemp)
elseif hasMax then
tempString = string.format(maxTemplate, reactPrototype.maxTemp)
end
for _, mixingCategory in pairs(reactPrototype.mixingCategories) do
local image = getMixingImage(mixingCategory.id)
if image ~= nil then
table.insert(actions, string.format("[[File:%s|32px|link=]]", image)) -- Картинка
end
table.insert(actions, mixingCategory.name .. " " .. tempString) -- Название
end
return table.concat(actions, "<br>")
end


 
getMixingImage = function(mixingId)
p.fillEffectsTable = function(frame)
local images = {
["DummyMix"] = "Beaker.png", -- Смешивание
["DummyGrind"] = "Blender.png", -- Измельчение
["DummyJuice"] = "Blender.png", -- Выжимка
["DummyCondense"] = "Конденсатор газа.png",
["Centrifuge"] = "Центрифуга.png",
["Electrolysis"] = "Электролизер.png",
["Holy"] = "Библия.png"
}
return images[mixingId]
--Временно заполняем старым описанием эфектов
local chemPrototypeId = frame.args.id
return p.geneffects(chemPrototypeId)
end
end


function getEffects(chemPrototypeId)
function getEffects(chemPrototypeId)
local effects = ""
local chemPrototype = p.chem[chemPrototypeId]
local chemPrototype = p.chem[chemPrototypeId]
if chemPrototype.metabolisms == nil then
return effects
end
for metabolismGroupKey, metabolismGroup in pairs(chemPrototype.metabolisms) do
effects = attachAsNewLine(effects, string.format("* %s (%s единиц в секунду)", metabolismGroupKey, metabolismGroup.rate))
for _, effect in pairs(metabolismGroup.effects) do
if effect.description ~= "" then
effects = attachAsNewLine(effects, "** "..effect.description)
end
end
end
local effects = {}
local effect = {}
effect.condition = ""
effect.effect = p.geneffects(chemPrototypeId)
table.insert(effects, effect)
return effects
return effects
Строка 127: Строка 279:
return originalStr .. "\n" .. joinStr  
return originalStr .. "\n" .. joinStr  
end
end
-- НЕ МОЕ
function p.geneffects(chemPrototypeId)
local frame = mw.getCurrentFrame()
local met = p.chem[chemPrototypeId].metabolisms
if met == nil then
return ""
end
local out = ""
for k, v in pairs(met) do
out = out .. "<b>" .. k .. "</b> (" .. v.rate .. " единиц в секунду)\n" .. p.geneffectlist(v.effects, frame, v.rate)
end
return out
end
function p.geneffectlist(effects, frame, rate)
local out = ""
for l, w in pairs(effects) do
-- Popup Message is ignored on purpose
if w.id == "HealthChange" then
out = out .. ":" .. p.genhealthchange(w, rate, frame) .. "\n"
elseif w.id == "AdjustReagent" then
out = out .. ":" .. p.genadjustreagent(w, rate, frame) .. "\n"
elseif w.id == "FlammableReaction" then
out = out .. ":" .. p.genflammablereaction(w, frame) .. "\n"
elseif w.id == "AdjustTemperature" then
out = out .. ":" .. p.genadjusttemperature(w, frame) .. "\n"
elseif w.id == "GenericStatusEffect" then
out = out .. ":" .. p.gengenericstatuseffect(w, frame) .. "\n"
elseif w.id == "ExplosionReactionEffect" then
out = out .. ":" .. p.genexplosionreactioneffect(w, frame) .. "\n"
elseif w.id == "FoamAreaReactionEffect" then
out = out .. ":" .. p.genfoamareareactioneffect(w, frame) .. "\n"
elseif w.id == "SmokeAreaReactionEffect" then
out = out .. ":" .. p.gensmokeareareactioneffect(w, frame) .. "\n"
elseif w.id == "ModifyBleedAmount" then
out = out .. ":" .. p.genmodifybleedamount(w, frame) .. "\n"
end
end
return out
end
function p.gensmokeareareactioneffect(r, frame)
if r.conditions ~= nil then
conds = p.genconds(r.conditions, frame)
end
return frame:expandTemplate{ title = "SmokeAreaReactionEffect", args = { when = conds, prob = r.probability }}
end
function p.genfoamareareactioneffect(r, frame)
if r.conditions ~= nil then
conds = p.genconds(r.conditions, frame)
end
return frame:expandTemplate{ title = "FoamAreaReactionEffect", args = { when = conds, prob = r.probability }}
end
function p.genexplosionreactioneffect(r, frame)
if r.conditions ~= nil then
conds = p.genconds(r.conditions, frame)
end
return frame:expandTemplate{ title = "ExplosionReactionEffect", args = { when = conds, prob = r.probability }}
end
function p.gengenericstatuseffect(r, frame)
if r.conditions ~= nil then
conds = p.genconds(r.conditions, frame)
end
return frame:expandTemplate{ title = "GenericStatusEffect", args = { key = r.Key, type = r.Type, time = r.Time, refresh = r.Refresh, when = conds, prob = r.probability }}
end
function p.genadjusttemperature(r, frame)
if r.conditions ~= nil then
conds = p.genconds(r.conditions, frame)
end
return frame:expandTemplate{ title = "AdjustTemperature", args = { amount = r.Amount, when = conds, prob = r.probability }}
end
function p.genflammablereaction(r, frame)
if r.conditions ~= nil then
conds = p.genconds(r.conditions, frame)
end
return frame:expandTemplate{ title = "FlammableReaction", args = { multiplier = r.Multiplier, when = conds, prob = r.probability }}
end
function p.genflammablereaction(r, frame)
if r.conditions ~= nil then
conds = p.genconds(r.conditions, frame)
end
return frame:expandTemplate{ title = "FlammableReaction", args = { multiplier = r.Multiplier, when = conds, prob = r.probability }}
end
function p.genadjustreagent(r, rate, frame)
if r.conditions ~= nil then
conds = p.genconds(r.conditions, frame)
end
return frame:expandTemplate{ title = "AdjustReagent", args = { amount = r.Amount, reagent = r.Reagent, when = conds, prob = r.probability }}
end
function p.genmodifybleedamount(r, frame)
if r.conditions ~= nil then
conds = p.genconds(r.conditions, frame)
end
return frame:expandTemplate{ title = "ModifyBleedAmount", args = { amount = r.Amount, when = conds, prob = r.probability }}
end
function p.genhealthchange(h, rate, frame)
local healst = {}
local dealst = {}
local r = 1.0 / rate
if h.damage.types ~= nil then
for k, v in pairs(h.damage.types) do
if v < 0 then
healst[k] = v * r
else
dealst[k] = v * r
end
end
end
if h.damage.groups ~= nil then
for k, v in pairs(h.damage.groups) do
if v < 0 then
healst[k] = v * r
else
dealst[k] = v * r
end
end
end
local heals = hchangelist(healst, frame)
local deals = hchangelist(dealst, frame)
local conds = nil
if h.conditions ~= nil then
conds = p.genconds(h.conditions, frame)
end
return frame:expandTemplate{ title = "HealthChange", args = { heals = heals, deals = deals, when = conds, prob = h.probability }}
end
function hchangelist(l, frame)
out = ""
local len = tablelength(l)
local i = 0
for k, v in pairs(l) do
i = i + 1
if len == i and i ~= 1 then
out = out .. ", and "
elseif i ~= 1 then
out = out .. ", "
end
out = out .. hchange(k, v, frame)
end
return out
end
-- So we can make it fancy later
function hchange(ty, amnt, frame)
return frame:expandTemplate{ title = "HealthModifier", args = { adj = amnt, kind = ty } }
end
function p.genconds(conds, frame)
out = ""
local len = tablelength(conds)
local i = 0
for k, v in pairs(conds) do
i = i + 1
if len == i and i ~= 1 then
out = out .. ", and "
elseif i ~= 1 then
out = out .. ", "
end
out = out .. p.gencond(v, frame)
end
return out
end
function p.gencond(c, frame)
if c.id == "TotalDamage" then
return frame:expandTemplate{ title = "TotalDamage", args = { min = c.Min, max = c.Max } }
elseif c.id == "ReagentThreshold" then
return frame:expandTemplate{ title = "ReagentThreshold", args = { min = c.Min, max = c.Max, reagent = c.Reagent } }
elseif c.id == "OrganType" then
return frame:expandTemplate{ title = "OrganType", args = { shouldhave = c.ShouldHave, type = c.Type } }
elseif c.id == "Temperature" then
return frame:expandTemplate{ title = "Temperature", args = {  min = c.Min, max = c.Max } }
end
return ""
end
function getColor(chemPrototypeId)
return mw.text.nowiki(p.chem[chemPrototypeId].color:sub(1, 7))
end
function getTextColor(chemPrototypeId)
local basecol = p.chem[chemPrototypeId].color
local red = tonumber(basecol:sub(2, 3), 16)
local grn = tonumber(basecol:sub(4, 5), 16)
local blu = tonumber(basecol:sub(6, 7), 16)
local luminance = math.sqrt(0.241*red*red + 0.691*grn*grn + 0.068*blu*blu)
if luminance > 100 then
return mw.text.nowiki("#000")
else
return mw.text.nowiki("#FFF")
end
end
-- НЕ МОЕ


return p
return p