Module:Sandbox: Difference between revisions

From The Deadlock Wiki
Jump to navigation Jump to search
No edit summary
get all items
Line 1: Line 1:
local p = {}
local p = {}
local items_data = mw.loadJsonData("Data:ItemData.json")


function p.get_all_item_names()
function p.get_all_item_names(frame)
     local items = {}
     local item_names = {}
      
      
    -- Collect all the names of the items
     for item_key, item_data in pairs(items_data) do
     for item_key, item_data in pairs(items_data) do
         if item_data["Name"] ~= nil and item_data["IsDisabled"] == false then
         if item_data["Name"] and item_data["IsDisabled"] == false then
             local lang_code = lang_module.get_lang_code()
             table.insert(item_names, item_data["Name"])
            local item_name_local = lang_module.get_string(item_key, lang_code)
           
            if item_name_local and item_name_local ~= "" then
                table.insert(items, item_name_local)
            end
         end
         end
     end
     end
      
      
     -- Сортируем имена предметов по алфавиту
     -- Sort alphabetically
     table.sort(items)
     table.sort(item_names)
      
      
     -- Объединяем через запятую
     -- Merge with commas
     return table.concat(items, ", ")
     return table.concat(item_names, ", ")
end
end


return p
return p

Revision as of 22:08, 21 April 2025

Documentation for this module may be created at Module:Sandbox/doc

local p = {}
local items_data = mw.loadJsonData("Data:ItemData.json")

function p.get_all_item_names(frame)
    local item_names = {}
    
    -- Collect all the names of the items
    for item_key, item_data in pairs(items_data) do
        if item_data["Name"] and item_data["IsDisabled"] == false then
            table.insert(item_names, item_data["Name"])
        end
    end
    
    -- Sort alphabetically
    table.sort(item_names)
    
    -- Merge with commas
    return table.concat(item_names, ", ")
end

return p