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

Нет описания правки
Нет описания правки
 
(не показаны 2 промежуточные версии этого же участника)
Строка 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 dp = require( "Module:GetField")
local dpOk, dpModule = pcall(require, "Module:GetField")
local dp = dpOk and dpModule or nil


local function load_data_page(page)
local function load_data_page(page)
Строка 33: Строка 31:
         end
         end
     end
     end
end
local function load_cached(page)
    if dp then
        return dp.loadCachedData(page)
    end
    return load_data_page(page)
end
end


Строка 52: Строка 43:
     end
     end
     return content
     return content
end
local function normalize_component_name(name)
    if type(name) ~= "string" or name == "" then
        return nil
    end
    if dp then
        return dp.normalizeComponentName(name)
    end
    if name:sub(1, 5) == "type:" then
        name = name:sub(6)
    elseif name:sub(1, 6) == "!type:" then
        name = name:sub(7)
    end
    if name == "" then
        return nil
    end
    return name
end
end


Строка 76: Строка 49:
         return {}
         return {}
     end
     end
     if dp then
     local entity = dp.loadEntityData(entityId)
        local entity = dp.loadEntityData(entityId)
    if entity then
        if entity then
        return dp.collectEntityComponents(entity)
            return dp.collectEntityComponents(entity)
        end
    end
    local data = load_data_page("prototype/Entity/" .. entityId .. ".json")
    if type(data) ~= "table" or type(data.components) ~= "table" then
        return {}
    end
    local out = {}
    local seen = {}
    for k in pairs(data.components) do
        local name = normalize_component_name(k)
        if name and not seen[name] then
            seen[name] = true
            out[#out + 1] = name
        end
     end
     end
    table.sort(out)
     return {}
     return out
end
end


Строка 114: Строка 71:
     end
     end


     if dp then
     return dp.entityHasComponent(entity, compName)
        return dp.entityHasComponent(entity, compName)
    end
 
    if type(entity) ~= "table" or type(entity.components) ~= "table" then
        return false
    end
 
    return entity.components[compName] ~= nil
        or entity.components["type:" .. compName] ~= nil
        or entity.components["!type:" .. compName] ~= nil
end
end


Строка 822: Строка 769:
     local prototypeBlacklist = frame.args.prototypeBlacklist or frame.args.prototypeblacklist or ""
     local prototypeBlacklist = frame.args.prototypeBlacklist or frame.args.prototypeblacklist or ""


     local prototypeStoreDefs = load_cached("prototype_store.json")
     local prototypeStoreDefs = dp.loadCachedData("prototype_store.json")
     if not prototypeStoreDefs then
     if not prototypeStoreDefs then
         return false
         return false
Строка 867: Строка 814:
         local paramNames = get_template_params(tplPath, content)
         local paramNames = get_template_params(tplPath, content)
         if dp then
         if dp then
             local dataPage = tplPath .. ".json"
             local dataPage = kind .. "/" .. dp.ucfirst(name) .. ".json"
             extra = get_selective_extra(id, dataPage, paramNames)
             extra = get_selective_extra(id, dataPage, paramNames)
         end
         end
Строка 891: Строка 838:
     end
     end


     local componentStoreDefs = load_cached("component_store.json")
     local componentStoreDefs = dp.loadCachedData("component_store.json")
     if type(componentStoreDefs) == "table" and (not anyEntityWhitelist or compHasWhitelist) then
     if type(componentStoreDefs) == "table" and (not anyEntityWhitelist or compHasWhitelist) then
         local compStore = componentStoreDefs[id]
         local compStore = componentStoreDefs[id]