Editing
Module:Sandbox/User:Microbrews/Variants
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
require('Module:Mw.html extension') local p = {} function sort_entries(entry1, entry2) -- Sort the variants based on the sum of the profession levels local entry1_value = (entry1['Profession Level A'] or 0) + (entry1['Profession Level B'] or 0) local entry2_value = (entry2['Profession Level A'] or 0) + (entry2['Profession Level B'] or 0) return entry1_value < entry2_value end function get_table_info(args, get_images) local variant_name = args.variant or mw.title.getCurrentTitle().fullText local query = { '[[Variant of::'..variant_name..']]', '?#-=page', '?Profession A #', -- Adding a # to this query makes it return plaintext instead of a link '?Profession B #', '?Profession Level A', '?Profession Level B', '?Profession Level A High', '?Profession Level B High', get_images and '?Image#64px;x64px = Image' or nil, limit = args.limit or 500, } local smw_data = mw.smw.ask(query) if not smw_data then return nil end table.sort(smw_data, sort_entries) return smw_data end function p.variants_header(args) local smw_data = get_table_info(args) local main_variant = args[1]:gsub('%(', '%%%('):gsub('%)', '%%%)') -- it's going to be a pattern, so escape the parentheses local contents if smw_data then local formatted = {} for _, entry in ipairs(smw_data) do local name = entry['page'] local variant_name = name:gsub(main_variant, '', 1) variant_name = variant_name:gsub('^%s*(.-)%s*$', '%1') -- trim whitespace variant_name = variant_name:gsub('%((.-)%)$', '%1') -- trim parentheses variant_name = variant_name:gsub("^%l", string.upper) -- capitalize first letter table.insert(formatted, '[[' .. name .. '|' .. variant_name .. ']]') end contents = table.concat(formatted, ' β’ ') else contents = '[[Category:Empty variant list]]' end return mw.html.create('div') :addClass('variants-header') :wikitext(contents) :done() end function p.main(frame) local args = frame:getParent().args args.variant = args[1] or args.variant return p.variants_header(args) end function p.variants_table(args) local smw_data = get_table_info(args, true) if not smw_data then return ':No variants found.' end local profession_b_flag = false for _, entry in ipairs(smw_data) do if entry['Profession B'] or entry['Profession Level B'] then profession_b_flag = true end break end local table = mw.html.create('table') :addClass('sortable wikitable') :tag('tr') :tag('th') :attr{ colspan = '2' } :wikitext('Item') :done() :tag('th') :wikitext('Level') :attrIf(profession_b_flag, 'colspan', 2) :done() :done() local function formatProfessionLevel(profession, level, high) if not (profession or level) then return nil end profession = profession or 'Unknown profession' local level_text = tostring(level or '?') if high then level_text = ('%sβ¨%d'):format(level_text, high) end return ('%s [[File:%s small icon.png|21x21px|link=%s]]'):format(level_text, profession, profession) end for _, entry in ipairs(smw_data) do local profession_level_a = entry['Profession Level A'] or '?' local profession_level_b = entry['Profession Level B'] or '?' local profession_a = entry['Profession A'] or '' local profession_b = entry['Profession B'] or '' table :tag('tr') :tag('td') :css{ ['border-right'] = 'none' } :wikitext(entry.Image) :done() :tag('td') :css{ ['border-left'] = 'none' } :wikitext('[['..entry['page']..']]') :done() :tag('td') :css{ ['text-align'] = 'right' } :wikitext(formatProfessionLevel(entry['Profession A'], entry['Profession Level A'], entry['Profession Level A High'])) :IF(profession_b_flag) :tag('td') :IF(entry['Profession B']) :css{ ['text-align'] = 'right' } :wikitext(formatProfessionLevel(entry['Profession B'], entry['Profession Level B'], entry['Profession Level B High'])) :done() :END() :done() end return table end function p.main_table(frame) local args = frame:getParent().args args.variant = args[1] or args.variant return p.variants_table(args) end return p
Summary:
Please note that all contributions to Brighter Shores Wiki are considered to be released under the CC BY-NC-SA 3.0 (see
Brighter Shores:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Preview page with this template
Template used on this page:
Module:Sandbox/User:Microbrews/Variants/doc
(
view source
)
Navigation menu
Personal tools
Not logged in
Talk
Contributions
Create account
Log in
Namespaces
Module
Discussion
English
Views
Read
Edit source
View history
More
Refresh
Search
Discord
Discord
Navigation
About us
User help
Random page
Recent changes
Slothful Bug
5m
ago
-
Atramentous
Lowburrow Bug
5m
ago
-
Atramentous
Pine Bug
5m
ago
-
Atramentous
Blood Bug
5m
ago
-
Atramentous
Show more...
Brighter Shores
Professions
Factions
Episodes
Premium Pass
Monsters
Quests
Community
Policies
Tools
What links here
Related changes
Special pages
Page information