Модуль:GetField: различия между версиями
Pok (обсуждение | вклад) Нет описания правки |
Pok (обсуждение | вклад) Нет описания правки |
||
| Строка 129: | Строка 129: | ||
end | end | ||
function p. | function p.findInGenerator(frame) | ||
local args = frame.args or {} | local args = frame.args or {} | ||
local | local searchId = args[1] or "" | ||
local fieldId = args[ | local kind = (args[2] or ""):lower() | ||
local fieldId = args[3] or "" | |||
if | if searchId == "" or fieldId == "" then | ||
return "" | |||
end | |||
if kind ~= "prototype" and kind ~= "component" then | |||
return "" | return "" | ||
end | end | ||
local | local baseUser = "IanComradeBot/" | ||
local storeName | |||
if kind == "prototype" then | |||
storeName = "prototype_store.json" | |||
else | |||
storeName = "component_store.json" | |||
end | |||
local moduleName = "Module:" .. baseUser .. storeName .. "/data" | |||
local data = cache[moduleName] | local data = cache[moduleName] | ||
| Строка 150: | Строка 161: | ||
end | end | ||
local | local entry = data[searchId] | ||
if type( | if type(entry) ~= "table" then | ||
return "" | return "" | ||
end | end | ||
local value = | local value = entry[fieldId] | ||
if value == nil then | if value == nil then | ||
return "" | return "" | ||
| Строка 286: | Строка 297: | ||
end | end | ||
function p. | function p.getTplGenerator(frame) | ||
local args = frame.args or {} | local args = frame.args or {} | ||
local searchId = args[1] or "" | local searchId = args[1] or "" | ||
local | local kind = (args[2] or ""):lower() | ||
local | local generatorId = args[3] or "" | ||
local | local tplPath = args[4] or "" | ||
if searchId == "" or | if searchId == "" or generatorId == "" or tplPath == "" then | ||
return "" | return "" | ||
end | end | ||
if kind ~= "prototype" and kind ~= "component" then | |||
return "" | |||
end | |||
local dir = (kind == "prototype") and "prototype/" or "component/" | |||
local pagePath = dir .. generatorId .. ".json" | |||
local idsJson = p. | local idsJson = p.findInGenerator({ args = { searchId, kind, generatorId } }) | ||
local ok, ids = pcall(mw.text.jsonDecode, idsJson or "") | local ok, ids = pcall(mw.text.jsonDecode, idsJson or "") | ||
if not ok or type(ids) ~= "table" or #ids == 0 then | if not ok or type(ids) ~= "table" or #ids == 0 then | ||