Модуль:Сущность/data: различия между версиями
Pok (обсуждение | вклад) Нет описания правки |
Pok (обсуждение | вклад) мНет описания правки |
||
| Строка 6: | Строка 6: | ||
local dp = dpOk and dpModule or nil | local dp = dpOk and dpModule or nil | ||
local switchModeRegistry = {} | local switchModeRegistry = {} | ||
local switchModeOrder = {} | local switchModeOrder = {} | ||
| Строка 33: | Строка 28: | ||
local function load_module_data(page) | local function load_module_data(page) | ||
local moduleName = JsonPaths.get(page) | local moduleName = JsonPaths.get(page) | ||
local ok, data = pcall(mw.loadData, moduleName) | local ok, data = pcall(mw.loadData, moduleName) | ||
if not ok then | if not ok then | ||
return nil | return nil | ||
end | end | ||
return data | return data | ||
end | end | ||
local function load_template_content(path) | local function load_template_content(path) | ||
local title = mw.title.new("Template:" .. path) | local title = mw.title.new("Template:" .. path) | ||
if not title then | if not title then | ||
return nil | return nil | ||
end | end | ||
local ok, content = pcall(title.getContent, title) | local ok, content = pcall(title.getContent, title) | ||
if not ok then | if not ok then | ||
return nil | return nil | ||
end | end | ||
return content | return content | ||
end | end | ||
| Строка 111: | Строка 90: | ||
local function get_template_params(tplPath, content) | local function get_template_params(tplPath, content) | ||
return collect_template_params(content) | |||
end | end | ||
| Строка 507: | Строка 479: | ||
local function getTemplateMeta(frame, tplPath) | local function getTemplateMeta(frame, tplPath) | ||
local expanded = frame:expandTemplate { | local expanded = frame:expandTemplate { | ||
title = tplPath, | title = tplPath, | ||
| Строка 518: | Строка 486: | ||
local ok, data = pcall(mw.text.jsonDecode, expanded) | local ok, data = pcall(mw.text.jsonDecode, expanded) | ||
if not ok or type(data) ~= "table" then | if not ok or type(data) ~= "table" then | ||
return "" | return "" | ||
end | end | ||
| Строка 538: | Строка 505: | ||
end | end | ||
return data | return data | ||
end | end | ||
| Строка 676: | Строка 642: | ||
end | end | ||
return dp.flattenFieldSelectiveDirect(id, dataPage, paramNames) or "" | |||
end | end | ||
| Строка 795: | Строка 754: | ||
processEntity("prototype", protoName, false) | processEntity("prototype", protoName, false) | ||
end | end | ||
local compWhitelistSet = parse_csv_set(componentWhitelist) | |||
local compBlacklistSet = parse_csv_set(componentBlacklist) | |||
local protoWhitelistSet = parse_csv_set(prototypeWhitelist) | |||
local protoBlacklistSet = parse_csv_set(prototypeBlacklist) | |||
local compHasWhitelist = next(compWhitelistSet) ~= nil | |||
local protoHasWhitelist = next(protoWhitelistSet) ~= nil | |||
local componentStoreDefs = load_module_data("component_store.json") | local componentStoreDefs = load_module_data("component_store.json") | ||
| Строка 801: | Строка 768: | ||
if type(compStore) == "table" then | if type(compStore) == "table" then | ||
for compName in pairs(compStore) do | for compName in pairs(compStore) do | ||
processEntity("component", compName, true) | local allowed = true | ||
if compBlacklistSet[compName] then | |||
allowed = false | |||
elseif compHasWhitelist and not compWhitelistSet[compName] then | |||
allowed = false | |||
end | |||
if allowed then | |||
processEntity("component", compName, true) | |||
end | |||
end | end | ||
end | end | ||
| Строка 810: | Строка 785: | ||
if type(protoStore) == "table" then | if type(protoStore) == "table" then | ||
for protoName in pairs(protoStore) do | for protoName in pairs(protoStore) do | ||
processEntity("prototype", protoName, true) | local allowed = true | ||
if protoBlacklistSet[protoName] then | |||
allowed = false | |||
elseif protoHasWhitelist and not protoWhitelistSet[protoName] then | |||
allowed = false | |||
end | |||
if allowed then | |||
processEntity("prototype", protoName, true) | |||
end | |||
end | end | ||
end | end | ||