Module:Inventory slot: Difference between revisions

m
no edit summary
imported>Ttv pedro270707
m (Added count to non-sets too)
imported>Ttv pedro270707
mNo edit summary
Line 53: Line 53:
local width = args.width or 32
local width = args.width or 32
local height = args.height or 32
local height = args.height or 32
local item = args.item
local item = args.item or ""
local pageName = mw.title.getCurrentTitle().text
local pageName = mw.title.getCurrentTitle().text
Line 138: Line 138:


function p.parseString(input)
function p.parseString(input)
    local strings = {}
if input then
    for str in input:gmatch("[^;]+") do
    local strings = {}
        table.insert(strings, str:match("^%s*(.-)%s*$"))
    for str in input:gmatch("[^;]+") do
    end
        table.insert(strings, str:match("^%s*(.-)%s*$"))
   
    end
    local result = {}
   
   
    local result = {}
    for _, str in ipairs(strings) do
   
        local name, item, count = str:match("^%[(.-)%](.-),?(%d*)$")
    for _, str in ipairs(strings) do
        if name then
        local name, item, count = str:match("^%[(.-)%](.-),?(%d*)$")
            table.insert(result, { name = name:gsub("^%s*(.-)%s*$", "%1"), item = item:gsub("^%s*(.-)%s*$", "%1"), count = tonumber(count) })
        if name then
        else
            table.insert(result, { name = name:gsub("^%s*(.-)%s*$", "%1"), item = item:gsub("^%s*(.-)%s*$", "%1"), count = tonumber(count) })
            item, count = str:match("(.-),?(%d*)$")
        else
            table.insert(result, { name = nil, item = item:gsub("^%s*(.-)%s*$", "%1"), count = tonumber(count) })
            item, count = str:match("(.-),?(%d*)$")
        end
            table.insert(result, { name = nil, item = item:gsub("^%s*(.-)%s*$", "%1"), count = tonumber(count) })
    end
        end
   
    end
    return result
   
    return result
else
return {}
end
end
end


return p
return p