Модуль:IanComradeBot/prototypes/fills/Item.json/data

Материал из Space Station 14 Вики

Для документации этого модуля может быть создана страница Модуль:IanComradeBot/prototypes/fills/Item.json/data/doc

local title = mw.title.new("Участник:IanComradeBot/prototypes/fills/Item.json")
local jsonData = title and title:getContent() or ""

local success, data = pcall(mw.text.jsonDecode, jsonData)

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