Модуль:GetField: различия между версиями

мНет описания правки
мНет описания правки
Строка 112: Строка 112:
         end
         end
     end
     end
end
local function resolve_entry(data, id)
    if type(data) ~= "table" then
        return nil
    end
    if id and id ~= "" then
        local direct = data[id]
        if direct ~= nil then
            return direct
        end
        local idsTable = data.id
        if type(idsTable) == "table" then
            local specific = idsTable[id]
            if type(specific) == "table" then
                local base = data["default"]
                if type(base) == "table" then
                    local merged = deep_copy(base)
                    deep_merge(merged, specific)
                    return merged
                end
                return deep_copy(specific)
            end
        end
    end
    local base = data["default"]
    if type(base) == "table" then
        return deep_copy(base)
    end
    return nil
end
end


Строка 175: Строка 208:
     end
     end


     local entry = data[id]
     local entry = resolve_entry(data, id) or {}
 
    if entry == nil then
        local idsTable = data.id
        if type(idsTable) == "table" then
            local specific = idsTable[id]
            if type(specific) == "table" then
                local base = data["default"]
                if type(base) == "table" then
                    local merged = deep_copy(base)
                    deep_merge(merged, specific)
                    entry = merged
                else
                    entry = deep_copy(specific)
                end
            end
        end
    end
 
    if entry == nil then
        local base = data["default"]
        if type(base) == "table" then
            entry = deep_copy(base)
        else
            entry = {}
        end
    end


     if type(entry) ~= "table" then return "" end
     if type(entry) ~= "table" then return "" end
Строка 259: Строка 266:
     local entry = entryCache[entryKey]
     local entry = entryCache[entryKey]
     if not entry then
     if not entry then
         if id ~= "" then entry = data[id] end
         entry = resolve_entry(data, id)
        if entry == nil then entry = data["default"] end
         entryCache[entryKey] = entry
         entryCache[entryKey] = entry
     end
     end