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