Модуль:Сущность: различия между версиями
Pok (обсуждение | вклад) мНет описания правки |
Pok (обсуждение | вклад) Нет описания правки |
||
| Строка 275: | Строка 275: | ||
local componentDefs = load_module_data("component.json") | local componentDefs = load_module_data("component.json") | ||
local prototypeStoreDefs = load_module_data("prototype_store.json") | local prototypeStoreDefs = load_module_data("prototype_store.json") | ||
local componentStoreDefs = load_module_data("component_store.json") | local componentStoreDefs = load_module_data("component_store.json") | ||
if not componentDefs then return "" end | if not componentDefs or not prototypeStoreDefs or not componentStoreDefs then return "" end | ||
local foundComponents, foundPrototypes = {}, {} | |||
local compList = componentDefs[id] | local compList = componentDefs[id] | ||
if type(compList) == "table" then | if type(compList) == "table" then | ||
| Строка 291: | Строка 288: | ||
end | end | ||
local | local protoEntry = prototypeStoreDefs[id] | ||
if type( | if type(protoEntry) == "table" then | ||
for | for protoName, _ in pairs(protoEntry) do | ||
if type( | if type(protoName) == "string" then | ||
foundPrototypes[protoName] = true | |||
end | end | ||
end | end | ||
end | end | ||
-- support component_store.json: when the searched id is present as a key there, | |||
-- create component/*/store templates (and prototype/*/store for prototype_store.json) | |||
local compStoreEntry = componentStoreDefs[id] | |||
if type(compStoreEntry) == "table" then | |||
for compName, members in pairs(compStoreEntry) do | |||
-- mark the component as found so we also process its regular template if exists | |||
foundComponents[compName] = true | |||
end | end | ||
end | end | ||
-- if the id references other names (comma separated), include their defs too | |||
for name in string.gmatch(id, "[^,]+") do | for name in string.gmatch(id, "[^,]+") do | ||
local n = trim(name) | local n = trim(name) | ||
| Строка 316: | Строка 313: | ||
if componentDefs[n] ~= nil then | if componentDefs[n] ~= nil then | ||
foundComponents[n] = true | foundComponents[n] = true | ||
elseif prototypeStoreDefs[n] ~= nil then | |||
foundPrototypes[n] = true | |||
end | end | ||
end | end | ||
| Строка 337: | Строка 322: | ||
for item in string.gmatch(ignoreComponents, "[^,]+") do | for item in string.gmatch(ignoreComponents, "[^,]+") do | ||
local name = trim(item) | local name = trim(item) | ||
if name ~= "" then | if name ~= "" then foundComponents[name] = nil end | ||
end | end | ||
end | end | ||
| Строка 346: | Строка 328: | ||
for item in string.gmatch(ignorePrototypes, "[^,]+") do | for item in string.gmatch(ignorePrototypes, "[^,]+") do | ||
local name = trim(item) | local name = trim(item) | ||
if name ~= "" then | if name ~= "" then foundPrototypes[name] = nil end | ||
end | end | ||
end | end | ||
| Строка 357: | Строка 339: | ||
local ok, dp = pcall(require, "Module:GetField") | local ok, dp = pcall(require, "Module:GetField") | ||
local errors = {} | local errors = {} | ||
local function processEntity(kind, name, isStore) | |||
local pathName = lcfirst(name) | |||
local tplPath = kind .. "/" .. pathName | |||
if isStore then | |||
tplPath = tplPath .. "/store" | |||
end | |||
local content = load_template_content(tplPath) | local content = load_template_content(tplPath) | ||
if not content then | if not content then | ||
if hasWhitelist then return end | if hasWhitelist then | ||
local | return | ||
table.insert(errors, "{{сущность/infobox|тип=" .. | end | ||
local classType = (kind and (kind:sub(1, 1):upper() .. kind:sub(2)) or "") | |||
if isStore then classType = classType .. "Store" end | |||
local className = name .. classType | |||
local tplLabel = "Template:" .. tplPath | |||
table.insert(errors, | |||
"{{сущность/infobox|тип=" .. classType .. "|название=" .. className .. "|ссылка=" .. tplLabel .. "}}") | |||
return | return | ||
end | end | ||
local parsed = getTemplateMeta(frame, tplPath) | local parsed = getTemplateMeta(frame, tplPath) | ||
for _, sw in ipairs(switches) do | for _, sw in ipairs(switches) do | ||
local keys = parsed[sw] or {} | local keys = parsed[sw] or {} | ||
for _, key in ipairs(keys) do | for _, key in ipairs(keys) do | ||
| Строка 387: | Строка 375: | ||
table.insert(switchKeyOrder[sw], key) | table.insert(switchKeyOrder[sw], key) | ||
end | end | ||
local extra = "" | |||
if ok and dp and dp.flattenField then | |||
local dataPage = tplPath .. ".json" | |||
extra = dp.flattenField({ args = { id, dataPage } }) | |||
end | |||
local tplStr | |||
local tplLabelStr, tplContentStr | |||
if sw == "card" then | |||
tplLabelStr = makeTplCall(tplPath, "cardLabel", key, id, extra) | |||
tplContentStr = makeTplCall(tplPath, "cardContent", key, id, extra) | |||
else | |||
tplStr = makeTplCall(tplPath, sw, key, id, extra) | |||
end | |||
local priority = 1 | |||
if parsed and parsed.priority ~= nil then | |||
if type(parsed.priority) == "number" then | |||
priority = parsed.priority | |||
else | else | ||
local pnum = tonumber(parsed.priority) | |||
if pnum then priority = pnum end | |||
end | end | ||
end | end | ||
local entry | |||
if sw == "card" then | |||
entry = { | |||
tplLabel = tplLabelStr, | |||
tplContent = tplContentStr, | |||
cardTag = parsed.cardTag, | |||
source = { kind = kind, name = name, pathName = pathName, tplPath = tplPath }, | |||
priority = priority, | |||
idx = #switchKeyToTemplates[sw][key] + 1 | |||
} | |||
else | |||
entry = { | |||
tpl = tplStr, | |||
source = { kind = kind, name = name, pathName = pathName, tplPath = tplPath }, | |||
priority = priority, | |||
idx = #switchKeyToTemplates[sw][key] + 1 | |||
} | |||
end | |||
table.insert(switchKeyToTemplates[sw][key], entry) | |||
end | end | ||
end | end | ||
end | end | ||
end | end | ||
for compName, _ in pairs(foundComponents) do processEntity("component", compName, false) end | |||
for protoName, _ in pairs(foundPrototypes) do processEntity("prototype", protoName, false) end | |||
for compName | if type(componentStoreDefs) == "table" then | ||
local compStore = componentStoreDefs[id] | |||
if type(compStore) == "table" then | |||
for compName in pairs(compStore) do | |||
processEntity("component", compName, true) | |||
end | |||
end | |||
end | end | ||
if type(prototypeStoreDefs) == "table" then | |||
local protoStore = prototypeStoreDefs[id] | |||
if type(protoStore) == "table" then | |||
for protoName in pairs(protoStore) do | |||
processEntity("prototype", protoName, true) | |||
end | |||
end | |||
end | end | ||
local out = {} | local out = {} | ||
for _, e in ipairs(errors) do table.insert(out, e) end | for _, e in ipairs(errors) do table.insert(out, e) end | ||
for _, s in ipairs(storeCalls) do table.insert(out, s) end | |||
local blocks = renderBlocks(frame, switches, switchConfigs, switchKeyOrder, switchKeyToTemplates, switchKeySources, | local blocks = renderBlocks(frame, switches, switchConfigs, switchKeyOrder, switchKeyToTemplates, switchKeySources, | ||
hasWhitelist, id) | hasWhitelist, id) | ||