Editing Module:ItemSources
Jump to navigation
Jump to search
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 52: | Line 52: | ||
return false |
return false |
||
end |
end |
||
end |
|||
local function parseDropJson(out, source, drop) |
|||
local dropJSON = mw.text.jsonDecode(drop or '{}') |
|||
local q2 = { |
|||
'[[:' .. dropJSON['Dropped from'] .. ']]', |
|||
'?Profession Requirement A=professionreq', |
|||
} |
|||
local sourcesmwdata = mw.smw.ask(q2) |
|||
for _, v in ipairs(sourcesmwdata) do |
|||
local professionreq = v.professionreq or 'Unknown' |
|||
local professionlevel = professionreq |
|||
if professionreq ~= 'Unknown' then |
|||
local profession, level = v.professionreq:match("([^,]+),([^,]+)") |
|||
professionlevel = pcp(profession, level) |
|||
end |
|||
local frequency = dropJSON['Frequency'] |
|||
local frequency_value |
|||
if frequencies[string.lower(tostring(frequency))] then |
|||
frequency = params.ucflc(frequency) |
|||
else |
|||
frequency_value = frequency:gsub(',','') --temp place to put this without overriding frequency |
|||
local rv1, rv2 = string.match(frequency_value, '([%d%.]+)/([%d%.]+)') |
|||
if rv1 and rv2 then |
|||
frequency = commas(rv1) .. '/' .. commas(rv2) |
|||
frequency_value = rv1/rv2 |
|||
else |
|||
frequency_value = expr(frequency) |
|||
end |
|||
end |
|||
local freq_class, freq_sort = '', nil |
|||
if frequency_value == nil then |
|||
freq_class, freq_sort = unpack(frequencies[string.lower(tostring(frequency))] or frequencies._default) |
|||
elseif frequency_value == false then |
|||
freq_class, freq_sort = unpack(frequencies._default) |
|||
else |
|||
freq_sort = 1/frequency_value |
|||
freq_class = get_frequency_class(frequency_value) |
|||
end |
|||
out:tag('tr') |
|||
:tag('td'):wikitext(source.source):done() |
|||
:tag('td'):wikitext(professionlevel):done() |
|||
:tag('td'):wikitext(dropJSON['Dropped quantity']):done() |
|||
:tag('td'):wikitext(frequency) |
|||
:attr('data-sort-value', freq_sort) |
|||
:addClass(freq_class) |
|||
:done() |
|||
:done() |
|||
end |
|||
return out |
|||
end |
end |
||
function p._main(args) |
function p._main(args) |
||
local item = args[1] or mw.title.getCurrentTitle().fullText |
local item = args[1] or mw.title.getCurrentTitle().fullText |
||
local q = { |
local q = { |
||
'[[Dropped item::' .. item .. ']]', |
'[[Dropped item::' .. item .. ']]', |
||
Line 119: | Line 63: | ||
} |
} |
||
local sourcessmwdata = mw.smw.ask(q) |
local sourcessmwdata = mw.smw.ask(q) |
||
if not sourcessmwdata then |
if not sourcessmwdata then |
||
return ":''No sources found. To force an update, click " |
return ":''No sources found. To force an update, click " |
||
Line 125: | Line 69: | ||
..".''[[Category:Empty source lists]]" |
..".''[[Category:Empty source lists]]" |
||
end |
end |
||
local out = mw.html.create('table') |
local out = mw.html.create('table') |
||
:addClass('wikitable sortable autosort=4,a align-center-2 align-center-3 align-center-4') |
:addClass('wikitable sortable autosort=4,a align-center-2 align-center-3 align-center-4') |
||
Line 134: | Line 78: | ||
:tag('th'):wikitext('Frequency'):done() |
:tag('th'):wikitext('Frequency'):done() |
||
:done() |
:done() |
||
for _, source in ipairs(sourcessmwdata) do |
for _, source in ipairs(sourcessmwdata) do |
||
local |
local dropJSON = mw.text.jsonDecode(source['Drop JSON'] or '{}') |
||
if type(drop) == 'string' then |
|||
local q2 = { |
|||
out = parseDropJson(out, source, drop) |
|||
'[[:' .. dropJSON['Dropped from'] .. ']]', |
|||
elseif type(drop) == 'table' then |
|||
'?Profession Requirement A=professionreq', |
|||
for _, v in ipairs(drop) do |
|||
} |
|||
out = parseDropJson(out, source, v) |
|||
local sourcesmwdata = mw.smw.ask(q2) |
|||
for _, v in ipairs(sourcesmwdata) do |
|||
local professionreq = v.professionreq or 'Unknown' |
|||
local professionlevel = professionreq |
|||
if professionreq ~= 'Unknown' then |
|||
local profession, level = v.professionreq:match("([^,]+),([^,]+)") |
|||
professionlevel = pcp(profession, level) |
|||
end |
end |
||
local frequency = dropJSON['Frequency'] |
|||
local frequency_value |
|||
if frequencies[string.lower(tostring(frequency))] then |
|||
frequency = params.ucflc(frequency) |
|||
else |
|||
frequency_value = frequency:gsub(',','') --temp place to put this without overriding frequency |
|||
local rv1, rv2 = string.match(frequency_value, '([%d%.]+)/([%d%.]+)') |
|||
if rv1 and rv2 then |
|||
frequency = commas(rv1) .. '/' .. commas(rv2) |
|||
frequency_value = rv1/rv2 |
|||
else |
|||
frequency_value = expr(frequency) |
|||
end |
|||
end |
|||
local freq_class, freq_sort = '', nil |
|||
if frequency_value == nil then |
|||
freq_class, freq_sort = unpack(frequencies[string.lower(tostring(frequency))] or frequencies._default) |
|||
elseif frequency_value == false then |
|||
freq_class, freq_sort = unpack(frequencies._default) |
|||
else |
|||
freq_sort = 1/frequency_value |
|||
freq_class = get_frequency_class(frequency_value) |
|||
end |
|||
out:tag('tr') |
|||
:tag('td'):wikitext(source.source):done() |
|||
:tag('td'):wikitext(professionlevel):done() |
|||
:tag('td'):wikitext(dropJSON['Dropped quantity']):done() |
|||
:tag('td'):wikitext(frequency) |
|||
:attr('data-sort-value', freq_sort) |
|||
:addClass(freq_class) |
|||
:done() |
|||
:done() |
|||
end |
end |
||
end |
end |
||
return out |
return out |
||
end |
end |