Модуль:Сущность/data: различия между версиями

Нет описания правки
Метка: ручная отмена
Нет описания правки
Строка 2: Строка 2:
local getArgs = require('Module:Arguments').getArgs
local getArgs = require('Module:Arguments').getArgs
local JsonPaths = require('Module:JsonPaths')
local JsonPaths = require('Module:JsonPaths')
local dpOk, dpModule = pcall(require, "Module:GetField")
local dp = dpOk and dpModule or nil


local moduleDataCache = {}
local moduleDataCache = {}
Строка 55: Строка 58:
         return nil
         return nil
     end
     end
     local ok, content = pcall(function() return title:getContent() end)
     local ok, content = pcall(title.getContent, title)
     if not ok then
     if not ok then
         templateContentCache[path] = false
         templateContentCache[path] = false
Строка 148: Строка 151:
     if not byKey[key] then
     if not byKey[key] then
         byKey[key] = {}
         byKey[key] = {}
         table.insert(state.keyOrder[sw], key)
         state.keyOrder[sw][#state.keyOrder[sw] + 1] = key
     end
     end
     return byKey[key]
     return byKey[key]
Строка 196: Строка 199:
                     line = line .. '<div class="ts-Сущность-field">' .. makeSourceLink(src) .. '</div>'
                     line = line .. '<div class="ts-Сущность-field">' .. makeSourceLink(src) .. '</div>'
                 end
                 end
                 table.insert(parts, '<div class="ts-Сущность">' .. line .. '</div>')
                 parts[#parts + 1] = '<div class="ts-Сущность">' .. line .. '</div>'
             end
             end
         end
         end
Строка 363: Строка 366:
                     if not merged.sectionsMap[section] then
                     if not merged.sectionsMap[section] then
                         merged.sectionsMap[section] = true
                         merged.sectionsMap[section] = true
                         table.insert(merged.sections, section)
                         merged.sections[#merged.sections + 1] = section
                     end
                     end
                     if displayLabel ~= "" and (not merged.labelOverrides[compositeKey] or merged.labelOverrides[compositeKey] == "") then
                     if displayLabel ~= "" and (not merged.labelOverrides[compositeKey] or merged.labelOverrides[compositeKey] == "") then
Строка 381: Строка 384:
                         merged.labelSets[section][compositeKey] = true
                         merged.labelSets[section][compositeKey] = true
                         local cur = merged.labelLists[section] or {}
                         local cur = merged.labelLists[section] or {}
                         table.insert(cur, compositeKey)
                         cur[#cur + 1] = compositeKey
                         merged.labelLists[section] = cur
                         merged.labelLists[section] = cur
                     end
                     end
Строка 389: Строка 392:
                     if not merged.tagSet[tagText] then
                     if not merged.tagSet[tagText] then
                         merged.tagSet[tagText] = true
                         merged.tagSet[tagText] = true
                         table.insert(merged.tags, tagText)
                         merged.tags[#merged.tags + 1] = tagText
                     end
                     end
                 end
                 end
Строка 399: Строка 402:
         if not merged.tagSet[extraTag] then
         if not merged.tagSet[extraTag] then
             merged.tagSet[extraTag] = true
             merged.tagSet[extraTag] = true
             table.insert(merged.tags, extraTag)
             merged.tags[#merged.tags + 1] = extraTag
         end
         end
     end)
     end)
Строка 527: Строка 530:
                     if not seen[lab] then
                     if not seen[lab] then
                         seen[lab] = true
                         seen[lab] = true
                         table.insert(cardKeys, lab)
                         cardKeys[#cardKeys + 1] = lab
                     end
                     end
                 end
                 end
Строка 665: Строка 668:
end
end


local function get_selective_extra(dp, id, dataPage, paramNames)
local function get_selective_extra(id, dataPage, paramNames)
     if not dp or type(dp.flattenFieldSelective) ~= "function" then
     if not dp or type(dp.flattenFieldSelectiveDirect) ~= "function" then
         return ""
         return ""
     end
     end
Строка 673: Строка 676:
     end
     end


    local okJson, keysJson = pcall(mw.text.jsonEncode, paramNames)
     local cacheKey = dataPage .. "\31" .. id .. "\31" .. table.concat(paramNames, "\30")
    if not okJson or not keysJson or keysJson == "" then
        return ""
    end
 
     local cacheKey = dataPage .. "\31" .. id .. "\31" .. keysJson
     if flattenExtraCache[cacheKey] ~= nil then
     if flattenExtraCache[cacheKey] ~= nil then
         return flattenExtraCache[cacheKey]
         return flattenExtraCache[cacheKey]
     end
     end


     local extra = dp.flattenFieldSelective({ args = { id, dataPage, keysJson } }) or ""
     local extra = dp.flattenFieldSelectiveDirect(id, dataPage, paramNames) or ""
     flattenExtraCache[cacheKey] = extra
     flattenExtraCache[cacheKey] = extra
     return extra
     return extra
Строка 754: Строка 752:
     local foundComponents, foundPrototypes = collect_entity_sets(id, componentDefs, prototypeStoreDefs,
     local foundComponents, foundPrototypes = collect_entity_sets(id, componentDefs, prototypeStoreDefs,
         componentWhitelist, componentBlacklist, prototypeWhitelist, prototypeBlacklist)
         componentWhitelist, componentBlacklist, prototypeWhitelist, prototypeBlacklist)
    local ok, dp = pcall(require, "Module:GetField")


     local function processEntity(kind, name, isStore)
     local function processEntity(kind, name, isStore)
Строка 779: Строка 775:
         local extra = ""
         local extra = ""
         local paramNames = get_template_params(tplPath, content)
         local paramNames = get_template_params(tplPath, content)
         if ok and dp then
         if dp then
             local dataPage = tplPath .. ".json"
             local dataPage = tplPath .. ".json"
             extra = get_selective_extra(dp, id, dataPage, paramNames)
             extra = get_selective_extra(id, dataPage, paramNames)
         end
         end


Строка 899: Строка 895:
                     entityId, noHeaders, showSource, cardFilter)
                     entityId, noHeaders, showSource, cardFilter)
             end
             end
             if outStr and outStr ~= "" then table.insert(outLocal, outStr) end
             if outStr and outStr ~= "" then outLocal[#outLocal + 1] = outStr end
         else
         else
             for _, key in ipairs(state.keyOrder[sw] or {}) do
             for _, key in ipairs(state.keyOrder[sw] or {}) do
Строка 905: Строка 901:
                 if type(mode.render_key) == "function" then
                 if type(mode.render_key) == "function" then
                     local outStr = mode.render_key(frame, key, entries, noHeaders, showSource)
                     local outStr = mode.render_key(frame, key, entries, noHeaders, showSource)
                     if outStr and outStr ~= "" then table.insert(outLocal, outStr) end
                     if outStr and outStr ~= "" then outLocal[#outLocal + 1] = outStr end
                 end
                 end
             end
             end
Строка 937: Строка 933:


     if #errors > 0 then
     if #errors > 0 then
         table.insert(out, '{{сущность/infobox|' .. table.concat(errors, "\n") .. '}}')
         out[#out + 1] = '{{сущность/infobox|' .. table.concat(errors, "\n") .. '}}'
     end
     end


Строка 944: Строка 940:
     local blocks = renderBlocks(frame, state, renderOptions, id, showSource)
     local blocks = renderBlocks(frame, state, renderOptions, id, showSource)
     for _, b in ipairs(blocks) do
     for _, b in ipairs(blocks) do
         table.insert(out, b)
         out[#out + 1] = b
     end
     end


Строка 978: Строка 974:
     }, nil, true)
     }, nil, true)


    local whitelist = previewFilter.whitelist
     local hasWhitelist = previewFilter.hasWhitelist
     local hasWhitelist = previewFilter.hasWhitelist
     renderOptions.noHeaders = hasWhitelist
     renderOptions.noHeaders = hasWhitelist
Строка 985: Строка 980:
     local blocks = renderBlocks(frame, state, renderOptions, "", showSource)
     local blocks = renderBlocks(frame, state, renderOptions, "", showSource)
     for _, b in ipairs(blocks) do
     for _, b in ipairs(blocks) do
         table.insert(out, b)
         out[#out + 1] = b
     end
     end