Модуль:Сущность: различия между версиями
Pok (обсуждение | вклад) Нет описания правки |
Pok (обсуждение | вклад) мНет описания правки |
||
| Строка 274: | Строка 274: | ||
local componentDefs = load_module_data("component.json") | local componentDefs = load_module_data("component.json") | ||
local | local prototypeStoreDefs = load_module_data("prototype_store.json") | ||
if not componentDefs | local componentStoreDefs = load_module_data("component_store.json") or {} | ||
if not componentDefs then return "" end | |||
local foundComponents = {} | |||
local foundComponentStores = {} | |||
local foundPrototypeStores = {} | |||
local compList = componentDefs[id] | local compList = componentDefs[id] | ||
if type(compList) == "table" then | if type(compList) == "table" then | ||
| Строка 287: | Строка 291: | ||
end | end | ||
local protoEntry = | local compStoreEntry = componentStoreDefs[id] | ||
if type(compStoreEntry) == "table" then | |||
for compName, entityList in pairs(compStoreEntry) do | |||
if type(compName) == "string" and type(entityList) == "table" and #entityList > 0 then | |||
foundComponentStores[compName] = entityList | |||
end | |||
end | |||
end | |||
if type(prototypeStoreDefs) == "table" then | |||
local protoEntry = prototypeStoreDefs[id] | |||
if type(protoEntry) == "table" then | |||
for protoName, entityList in pairs(protoEntry) do | |||
if type(protoName) == "string" and type(entityList) == "table" and #entityList > 0 then | |||
foundPrototypeStores[protoName] = entityList | |||
end | |||
end | end | ||
end | end | ||
| Строка 301: | Строка 316: | ||
if componentDefs[n] ~= nil then | if componentDefs[n] ~= nil then | ||
foundComponents[n] = true | foundComponents[n] = true | ||
end | |||
if componentStoreDefs[n] and type(componentStoreDefs[n]) == "table" then | |||
for compName, entityList in pairs(componentStoreDefs[n]) do | |||
if type(compName) == "string" and type(entityList) == "table" and #entityList > 0 then | |||
foundComponentStores[compName] = entityList | |||
end | |||
end | |||
end | |||
if prototypeStoreDefs and prototypeStoreDefs[n] and type(prototypeStoreDefs[n]) == "table" then | |||
for protoName, entityList in pairs(prototypeStoreDefs[n]) do | |||
if type(protoName) == "string" and type(entityList) == "table" and #entityList > 0 then | |||
foundPrototypeStores[protoName] = entityList | |||
end | |||
end | |||
end | end | ||
end | end | ||
| Строка 310: | Строка 337: | ||
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 foundComponents[name] = nil end | if name ~= "" then | ||
foundComponents[name] = nil | |||
foundComponentStores[name] = nil | |||
end | |||
end | end | ||
end | end | ||
| Строка 316: | Строка 346: | ||
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 foundPrototypeStores[name] = nil end | ||
end | end | ||
end | end | ||
| Строка 327: | Строка 357: | ||
local ok, dp = pcall(require, "Module:GetField") | local ok, dp = pcall(require, "Module:GetField") | ||
local errors = {} | local errors = {} | ||
local function processEntity(kind, name) | |||
local function processEntity(kind, name, isStore, storeEntities) | |||
local pathName = lcfirst(name) | local pathName = lcfirst(name) | ||
local tplPath = kind .. "/" .. pathName | local tplPath = kind .. "/" .. pathName .. (isStore and "/store" or "") | ||
local content = load_template_content(tplPath) | local content = load_template_content(tplPath) | ||
if not content then | if not content then | ||
| Строка 343: | Строка 374: | ||
end | end | ||
local parsed = getTemplateMeta(frame, tplPath) | local parsed = getTemplateMeta(frame, tplPath) | ||
for _, sw in ipairs( | local dataPage = (kind .. "/" .. pathName) .. ".json" | ||
local entities = isStore and storeEntities or { id } | |||
local switchesToProcess = isStore and { "card" } or switches | |||
for _, sw in ipairs(switchesToProcess) do | |||
local keys = parsed[sw] or {} | local keys = parsed[sw] or {} | ||
for _, key in ipairs(keys) do | for _, key in ipairs(keys) do | ||
| Строка 357: | Строка 392: | ||
table.insert(switchKeyOrder[sw], key) | table.insert(switchKeyOrder[sw], key) | ||
end | end | ||
local extra = "" | for _, entityId in ipairs(entities) do | ||
local extra = "" | |||
if ok and dp and dp.flattenField then | |||
extra = dp.flattenField({ args = { entityId, dataPage } }) or "" | |||
end | |||
local tplStr | |||
local tplLabelStr, tplContentStr | |||
if sw == "card" then | |||
tplLabelStr = makeTplCall(tplPath, "cardLabel", key, entityId, extra) | |||
tplContentStr = makeTplCall(tplPath, "cardContent", key, entityId, extra) | |||
else | |||
tplStr = makeTplCall(tplPath, sw, key, entityId, extra) | |||
end | |||
local priority = 1 | |||
if parsed and parsed.priority ~= nil then | |||
if type(parsed.priority) == "number" then | |||
priority = parsed.priority | priority = parsed.priority | ||
else | |||
local pnum = tonumber(parsed.priority) | |||
if pnum then priority = pnum 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 | else | ||
entry = { | |||
tpl = tplStr, | |||
source = { kind = kind, name = name, pathName = pathName, tplPath = tplPath }, | |||
priority = priority, | |||
idx = #switchKeyToTemplates[sw][key] + 1 | |||
} | |||
end | end | ||
table.insert(switchKeyToTemplates[sw][key], entry) | |||
end | end | ||
end | end | ||
end | end | ||
| Строка 403: | Строка 439: | ||
end | end | ||
for compName, _ in pairs(foundComponents) do | |||
for compName, _ in pairs(foundComponents) do | processEntity("component", compName, false) | ||
for | end | ||
for | for compName, entityList in pairs(foundComponentStores) do | ||
processEntity("component", compName, true, entityList) | |||
end | |||
for protoName, entityList in pairs(foundPrototypeStores) do | |||
processEntity("prototype", protoName, true, entityList) | |||
end | |||
local out = {} | local out = {} | ||