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

Нет описания правки
Метка: отменено
Нет описания правки
Метка: отменено
Строка 38: Строка 38:
end
end


local function makeTplCall(tplPath, sw, key, id, extra)
local function makeTplCall(tplPath, sw, key, id)
     local tplStr = "{{" .. tplPath .. "|" .. sw .. "|" .. key
     if not id or id == "" then
     tplStr = tplStr .. "|id=" .. tostring(id)
        return "{{" .. tplPath .. "|" .. sw .. "|" .. key .. "}}"
    if extra and extra ~= "" then tplStr = tplStr .. "|" .. extra end
     end
    tplStr = tplStr .. "}}"
    local tplArgs = tplPath .. "{{!}}" .. sw .. "{{!}}" .. key
    return tplStr
    return "{{ajax|<nowiki>{{#invoke:GetField|getTpl|" .. tostring(id) .. "|" .. tplPath .. ".json|{{#tag:nowiki|" .. tplArgs .. "}}}}</nowiki>|auto}}"
end
end


Строка 512: Строка 512:
     end
     end
     return outLocal
     return outLocal
end
function p.get(frame)
    local args = getArgs(frame, { removeBlanks = false })
    local id = args[1] or ""
    if id == "" then return "" end
    local filter = build_key_filter(args)
    local ignoreComponents = args.ignoreComponents or args.ignoreComponent or ""
    local ignorePrototypes = args.ignorePrototypes or args.ignorePrototype or ""
    local componentDefs = load_module_data("component.json")
    local prototypeStoreDefs = load_module_data("prototype_store.json")
    local componentStoreDefs = load_module_data("component_store.json")
    if not componentDefs or not prototypeStoreDefs or not componentStoreDefs then return "" end
    local foundComponents, foundPrototypes = collect_entity_sets(id, componentDefs, prototypeStoreDefs, ignoreComponents,
        ignorePrototypes)
    local state = new_switch_state()
    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)
        if not content then
            if filter.hasWhitelist then
                return
            end
            errors[#errors + 1] = build_missing_template_error(kind, name, isStore, tplPath)
            return
        end
        local parsed = getTemplateMeta(frame, tplPath)
        if type(parsed) ~= "table" then
            parsed = {}
        end
        add_entries_from_meta(state, parsed, {
            tplPath = tplPath,
            id = id,
            source = make_source(kind, name, pathName, tplPath),
            priority = resolve_priority(parsed)
        }, filter, false)
    end
    for compName in pairs(foundComponents) do
        processEntity("component", compName, false)
    end
    for protoName in pairs(foundPrototypes) do
        processEntity("prototype", protoName, false)
    end
    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
    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
    local out = {}
    if #errors > 0 then
        table.insert(out, '{{сущность/infobox|' .. table.concat(errors, "\n") .. '}}')
    end
    local blocks = renderBlocks(frame, state, filter.hasWhitelist, id)
    for _, b in ipairs(blocks) do
        table.insert(out, b)
    end
    return frame:preprocess(table.concat(out, "\n") .. "[[Категория:Сущности]]")
end
end


Строка 533: Строка 622:
         tplPath = tplPath,
         tplPath = tplPath,
         id = "",
         id = "",
        extra = "",
         source = make_source("", tplPath, tplPath, tplPath),
         source = make_source("", tplPath, tplPath, tplPath),
         priority = 1
         priority = 1
Строка 562: Строка 650:
     return count > 0 and max == count
     return count > 0 and max == count
end
end


local function apply_pattern(s, pattern, repl)
local function apply_pattern(s, pattern, repl)
Строка 639: Строка 728:
     end
     end


     local rendered = table.concat(calls, " ")
     local rendered = table.concat(calls, "\n")
     return frame:preprocess(rendered)
     return frame:preprocess(rendered)
end
end