Модуль:IanComradeBot/prototypes/fills/Item.json/data: различия между версиями

мНет описания правки
Нет описания правки
Метка: ручная отмена
Строка 1: Строка 1:
local title = mw.title.new("Участник:IanComradeBot/prototypes/fills/Item.json")
local title = mw.title.new("Участник:IanComradeBot/prototypes/fills/Item.json")
local jsonData = title and title:getContent() or ""
local jsonData = title and title:getContent() or ""
local success, data = pcall(mw.text.jsonDecode, jsonData)
local success, data = pcall(mw.text.jsonDecode, jsonData)
 
return (success and type(data) == "table") and data or {}
if not success or type(data) ~= "table" then
    return {}
end
 
local function normalizeData(item)
    if type(item) ~= "table" then return item end
   
    if item.id and not next(item, "id") then
        for _, fullItem in ipairs(data) do
            if fullItem.id == item.id then
                return fullItem
            end
        end
    end
 
    for k, v in pairs(item) do
        item[k] = normalizeData(v)
    end
   
    return item
end
 
for i, item in ipairs(data) do
    data[i] = normalizeData(item)
end
 
return data