Модуль:GetField: различия между версиями
Pok (обсуждение | вклад) Отмена версии 315700, сделанной Pok (обсуждение) Метка: отмена |
Pok (обсуждение | вклад) Нет описания правки |
||
| Строка 10: | Строка 10: | ||
end | end | ||
return loaded | return loaded | ||
end | |||
local function load_json_data(pagePath) | |||
local titleName = JsonPaths.getJson(pagePath) | |||
if not titleName or titleName == "" then | |||
return nil | |||
end | |||
local ok, data = pcall(mw.loadJsonData, titleName) | |||
if not ok or type(data) ~= "table" then | |||
return nil | |||
end | |||
return data | |||
end | end | ||
| Строка 146: | Строка 160: | ||
end | end | ||
local function | local function resolve_entry_from_data(data, id) | ||
if type(data) ~= "table" then | if type(data) ~= "table" then | ||
return nil | return nil | ||
| Строка 178: | Строка 192: | ||
return nil | return nil | ||
end | |||
local function load_entry(id, pagePath, data) | |||
data = data or load_cached_data(JsonPaths.get(pagePath)) | |||
return resolve_entry_from_data(data, id) | |||
end | end | ||
| Строка 418: | Строка 437: | ||
end | end | ||
local | local entry = preEntry or load_entry(id, pagePath, data) | ||
if entry == nil then | |||
if | |||
return "" | return "" | ||
end | end | ||
local extra = flatten_entry(entry) | local extra = flatten_entry(entry) | ||
local extraTplArgs = tplArgs or "" | local extraTplArgs = tplArgs or "" | ||
| Строка 457: | Строка 474: | ||
local storeName = (kind == "prototype") and "prototype_store.json" or "component_store.json" | local storeName = (kind == "prototype") and "prototype_store.json" or "component_store.json" | ||
local | local data = load_json_data(storeName) | ||
if not data then | if not data then | ||
return "" | return "" | ||
| Строка 494: | Строка 510: | ||
end | end | ||
local entry = load_entry(id, pagePath) or {} | |||
local entry = | |||
return flatten_entry(entry) | return flatten_entry(entry) | ||
end | end | ||
| Строка 518: | Строка 528: | ||
end | end | ||
local entry = load_entry(id, pagePath) or {} | |||
local entry = | |||
local parts = flatten_selected_parts(entry, keys) | local parts = flatten_selected_parts(entry, keys) | ||
if #parts == 0 then | if #parts == 0 then | ||
| Строка 543: | Строка 547: | ||
end | end | ||
local entry = load_entry(id, pagePath) | |||
local entry = | |||
if entry == nil then | if entry == nil then | ||
return "" | return "" | ||
| Строка 713: | Строка 711: | ||
end | end | ||
local | local data = load_json_data(pagePath) | ||
if not data then | if not data then | ||
return "[]" | return "[]" | ||
| Строка 733: | Строка 730: | ||
for _, idKey in ipairs(ids) do | for _, idKey in ipairs(ids) do | ||
local entry = | local entry = resolve_entry_from_data(data, idKey) | ||
if type(entry) == "table" and entry_matches_path(entry, parsedPath, target, searchType) then | if type(entry) == "table" and entry_matches_path(entry, parsedPath, target, searchType) then | ||
matches[#matches + 1] = idKey | matches[#matches + 1] = idKey | ||
| Строка 772: | Строка 769: | ||
end | end | ||
local | local data = load_json_data(pagePath) | ||
if not data or type(data) ~= "table" then | if not data or type(data) ~= "table" then | ||
return "[]" | return "[]" | ||
| Строка 839: | Строка 835: | ||
for _, idKey in ipairs(ids) do | for _, idKey in ipairs(ids) do | ||
local entry = | local entry = resolve_entry_from_data(data, idKey) | ||
if mode == "component" then | if mode == "component" then | ||
if entry_has_all_targets_component(entry, targets) then | if entry_has_all_targets_component(entry, targets) then | ||
| Строка 889: | Строка 885: | ||
end | end | ||
local | local data = load_json_data(pagePath) | ||
if not data then | if not data then | ||
return "" | return "" | ||
| Строка 910: | Строка 905: | ||
if searchType == "path" then | if searchType == "path" then | ||
for _, idKey in ipairs(ids) do | for _, idKey in ipairs(ids) do | ||
local entry = | local entry = resolve_entry_from_data(data, idKey) | ||
entryCache[idKey] = entry | entryCache[idKey] = entry | ||
if type(entry) == "table" and entry_has_any_nonempty_path(entry, parsedPath) then | if type(entry) == "table" and entry_has_any_nonempty_path(entry, parsedPath) then | ||
| Строка 919: | Строка 914: | ||
local target = tostring(searchValue) | local target = tostring(searchValue) | ||
for _, idKey in ipairs(ids) do | for _, idKey in ipairs(ids) do | ||
local entry = | local entry = resolve_entry_from_data(data, idKey) | ||
entryCache[idKey] = entry | entryCache[idKey] = entry | ||
if type(entry) == "table" and entry_matches_path(entry, parsedPath, target, searchType) then | if type(entry) == "table" and entry_matches_path(entry, parsedPath, target, searchType) then | ||
| Строка 959: | Строка 954: | ||
end | end | ||
local data = frame.data | local data = frame.data | ||
local tplStr = build_tpl(id, pagePath, tplPath, data, tplArgs) | local tplStr = build_tpl(id, pagePath, tplPath, data, tplArgs) | ||
return preprocess_or_return(frame, tplStr) | return preprocess_or_return(frame, tplStr) | ||
| Строка 997: | Строка 984: | ||
end | end | ||
local | local data = load_json_data(pagePath) | ||
if not data then | if not data then | ||
return "" | return "" | ||
| Строка 1005: | Строка 991: | ||
local out = {} | local out = {} | ||
for _, id in ipairs(ids) do | for _, id in ipairs(ids) do | ||
local tpl = build_tpl(id, pagePath, tplPath, data, tplArgs) | local entry = resolve_entry_from_data(data, id) | ||
if entry ~= nil then | |||
local tpl = build_tpl(id, pagePath, tplPath, data, tplArgs, entry) | |||
if tpl ~= "" then | |||
out[#out + 1] = tpl | |||
end | |||
end | end | ||
end | end | ||
| Строка 1123: | Строка 1112: | ||
end | end | ||
local | local data = load_json_data(pagePath) | ||
if not data then | if not data then | ||
return "" | return "" | ||
end | end | ||
local idsTable = data.id | local idsTable = data.id or data | ||
if type(idsTable) ~= "table" then | if type(idsTable) ~= "table" then | ||
return "" | return "" | ||
| Строка 1174: | Строка 1162: | ||
end | end | ||
local | local data = load_json_data(pagePath) | ||
if not data then | if not data then | ||
return "" | return "" | ||
end | end | ||
local idsTable = data.id | local idsTable = data.id or data | ||
if type(idsTable) ~= "table" then | if type(idsTable) ~= "table" then | ||
return "" | return "" | ||
| Строка 1188: | Строка 1175: | ||
for idKey in pairs(idsTable) do | for idKey in pairs(idsTable) do | ||
local tpl = build_tpl(idKey, pagePath, tplPath, data, tplArgs) | local entry = resolve_entry_from_data(data, idKey) | ||
if entry ~= nil then | |||
local tpl = build_tpl(idKey, pagePath, tplPath, data, tplArgs, entry) | |||
if tpl ~= "" then | |||
out[#out + 1] = tpl | |||
end | |||
end | end | ||
end | end | ||
| Строка 1624: | Строка 1614: | ||
end | end | ||
local entry = load_entry(id, dataPage) or {} | |||
local entry = | |||
local parts = flatten_selected_parts(entry, paramNames) | local parts = flatten_selected_parts(entry, paramNames) | ||
if #parts == 0 then | if #parts == 0 then | ||