Editing Module:Sandbox/User:Californ1a/T/Professions
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 11: | Line 11: | ||
-- List episodes with their professions |
-- List episodes with their professions |
||
local episodes = { |
local episodes = { |
||
hopeport = {"guard", "chef", "fisher", "forager", "alchemist"}, |
|||
{ |
|||
hopeforest = {"scout", "gatherer", "woodcutter", "carpenter"}, |
|||
free = true, |
|||
mine = {"minefighter", "bonewright", "miner", "blacksmith", "stonemason"}, |
|||
name = 'Hopeport', |
|||
crenopolis = {"watchperson", "detective", "leatherworker", "merchant"} |
|||
color = '#b99f46', |
|||
professions = {'guard', 'chef', 'fisher', 'forager', 'alchemist'}, |
|||
}, { |
|||
free = true, |
|||
name = 'Hopeforest', |
|||
color = '#84b876', |
|||
professions = {'scout', 'gatherer', 'woodcutter', 'carpenter'}, |
|||
}, { |
|||
name = 'Mine of Mantuban', |
|||
color = '#68ABF1', |
|||
professions = {'minefighter', 'bonewright', 'miner', 'blacksmith', 'stonemason'}, |
|||
}, { |
|||
name = 'Crenopolis', |
|||
color = '#979797', |
|||
professions = {'watchperson', 'detective', 'leatherworker', 'merchant'}, |
|||
}, { |
|||
released = false, |
|||
name = 'Stonemaw Hill', |
|||
color = '#C57F41', |
|||
professions = {'shieldbearer', 'builder', 'armorer', 'delver'}, |
|||
}, { |
|||
released = false, |
|||
name = 'Bleakholm Crags', |
|||
color = '#68ABF1', |
|||
professions = {}, |
|||
}, |
|||
} |
} |
||
local ep_dict = { |
|||
-- Get professions levels given an episode order number |
|||
hopeport = 'Hopeport', |
|||
function p.filter_by_episode(professions, episodeOrder) |
|||
hopeforest = 'Hopeforest', |
|||
mine = 'Mine of Mantuban', |
|||
crenopolis = 'Crenopolis' |
|||
} |
|||
local ep_color = { |
|||
hopeport = '#b99f46', |
|||
hopeforest = '#84b876', |
|||
mine = '#68ABF1', |
|||
crenopolis = '#979797' |
|||
} |
|||
-- Get professions levels given an episode name |
|||
function p.filter_by_episode(professions, episodeName, goals) |
|||
goals = goals or false |
|||
local filtered = {} |
local filtered = {} |
||
local episodeProfessions = episodes[ |
local episodeProfessions = episodes[episodeName] |
||
if not episodeProfessions then |
|||
error('Invalid episode name: ' .. tostring(episodeName)) |
|||
end |
|||
-- Add the professions and the total for the episode |
-- Add the professions and the total for the episode |
||
for _, profession in ipairs(episodeProfessions) do |
for _, profession in ipairs(episodeProfessions) do |
||
local val = profession |
|||
if professions[profession] ~= nil then |
|||
if goals then |
|||
filtered[profession] = professions[profession] |
|||
val = profession..' goal' |
|||
end |
|||
if professions[val] ~= nil then |
|||
filtered[val] = professions[val] |
|||
end |
end |
||
end |
end |
||
-- Add the total for the episode |
-- Add the total for the episode |
||
if professions[episodeName] ~= nil then |
|||
local ep_name = episodes[episodeOrder].name:lower() |
|||
filtered[episodeName] = professions[episodeName] |
|||
if professions[ep_name] ~= nil then |
|||
filtered[ep_name] = professions[ep_name] |
|||
end |
end |
||
Line 76: | Line 73: | ||
-- Build the professions + goals lists |
-- Build the professions + goals lists |
||
for |
for episode, keys in pairs(episodes) do |
||
professions[episode] = 0 |
|||
local ep_name = episode.name:lower() |
|||
for _, key in ipairs(keys) do |
|||
professions[ep_name] = 0 |
|||
for _, profession in ipairs(episode.professions) do |
|||
-- Add the profession and goal to their respective lists |
-- Add the profession and goal to their respective lists |
||
professions[ |
professions[key] = pt.default_to(tonumber(args[key]), 0) |
||
goals[ |
goals[key] = pt.default_to(tonumber(args[key..' goal']), 0) |
||
-- Add this profession's level to the episode's total |
-- Add this profession's level to the episode's total |
||
local value = professions[ |
local value = professions[key] or 0 |
||
professions[ |
professions[episode] = professions[episode] + value |
||
end |
end |
||
-- Add this episode's total to the overall total |
-- Add this episode's total to the overall total |
||
professions.total = professions.total + professions[ |
professions.total = professions.total + professions[episode] |
||
end |
end |
||
Line 96: | Line 92: | ||
vertical = yn(pt.default_to(args.vertical, true), true), |
vertical = yn(pt.default_to(args.vertical, true), true), |
||
free = yn(pt.default_to(args.free, false), false), |
free = yn(pt.default_to(args.free, false), false), |
||
date = pt.default_to(args.date, '') |
date = pt.default_to(args.date, '') |
||
right = yn(pt.default_to(args.right, false), false), |
|||
infobox = yn(pt.default_to(args.infobox, false), false), |
|||
} |
} |
||
Line 106: | Line 100: | ||
end |
end |
||
function p.create_row(tbl, |
function p.create_row(tbl, episode, professions, goals, vertical) |
||
if vertical then |
if vertical then |
||
tbl:tag('tr') |
tbl:tag('tr') |
||
Line 113: | Line 107: | ||
-- Create icons |
-- Create icons |
||
local cache = {} |
local cache = {} |
||
for _,profession in ipairs(episodes[ |
for _,profession in ipairs(episodes[episode]) do |
||
local PRO = pt.ucflc(profession) |
local PRO = pt.ucflc(profession) |
||
local size = icon_size |
local size = icon_size |
||
Line 138: | Line 132: | ||
-- Create levels |
-- Create levels |
||
for _, |
for _,profession in ipairs(episodes[episode]) do |
||
local PRO = cache[profession].name |
local PRO = cache[profession].name |
||
local lvl = tostring(professions[profession]) |
local lvl = tostring(professions[profession]) |
||
Line 160: | Line 154: | ||
end |
end |
||
function p.create_episode_table( |
function p.create_episode_table(episode, professions, goals, other) |
||
local |
local profession_count = #episodes[episode] |
||
local |
local EP = ep_dict[episode] |
||
local EP = episodes[episodeOrder].name |
|||
local ep_name = episodes[episodeOrder].name:lower() |
|||
local out = mw.html.create('tr'):tag('td'):tag('table') |
local out = mw.html.create('tr'):tag('td'):tag('table') |
||
:addClass('wikitable') |
|||
:addClass('center') |
:addClass('center') |
||
:css({margin='0', padding='0'}) |
|||
:IF(other.infobox) |
|||
:addClass('infobox') |
|||
:addClass('infobox-'..EP:gsub(' ', '_')) |
|||
:css({ |
|||
margin = '0', |
|||
['table-layout'] = 'auto', |
|||
width = '100%', |
|||
float = 'unset', |
|||
}) |
|||
:ELSE() |
|||
:addClass('wikitable') |
|||
:css({margin='0', padding='0'}) |
|||
:END() |
|||
:tag('tr') |
:tag('tr') |
||
:tag('th') |
:tag('th') |
||
:css({['background-color']=ep_color[episode]}) |
|||
:IF(other.infobox) |
|||
:addClass('infobox-header') |
|||
:css({padding='0.5em'}) |
|||
:ELSE() |
|||
:css({ |
|||
['background-color'] = episodes[episodeOrder].color, |
|||
padding='0 0.5em', |
|||
}) |
|||
:END() |
|||
:attr({colspan = profession_count}) |
:attr({colspan = profession_count}) |
||
:wikitext(mw.ustring.format('[[File:%s episode icon.png|link=%s|%spx]] [[%s]] (%s)', EP, EP, ep_icon_size, EP, professions[ |
:wikitext(mw.ustring.format('[[File:%s episode icon.png|link=%s|%spx]] [[%s]] (%s)', EP, EP, ep_icon_size, EP, professions[episode])) |
||
:done() |
:done() |
||
:done() |
:done() |
||
out = p.create_row(out, |
out = p.create_row(out, episode, professions, goals, other.vertical) |
||
return out:done():done():done() -- /table /td /tr |
return out:done():done():done() -- /table /td /tr |
||
end |
|||
local function getReleasedEpisodes() |
|||
local filtered = {} |
|||
for i, episode in ipairs(episodes) do |
|||
if episode.released ~= false then |
|||
table.insert(filtered, episode) |
|||
end |
|||
end |
|||
return filtered |
|||
end |
end |
||
function p.create_table(professions, goals, other) |
function p.create_table(professions, goals, other) |
||
local ep_tbl = {} |
local ep_tbl = {} |
||
for episode in pairs(episodes) do |
|||
local released_episodes = getReleasedEpisodes() |
|||
local ep_lvls = p.filter_by_episode(professions, episode) |
|||
for i in ipairs(released_episodes) do |
|||
local |
local ep_goals = p.filter_by_episode(goals, episode) |
||
ep_tbl[episode] = p.create_episode_table(episode, ep_lvls, ep_goals, other) |
|||
local ep_goals = p.filter_by_episode(goals, i) |
|||
table.insert(ep_tbl, p.create_episode_table(i, ep_lvls, ep_goals, other)) |
|||
end |
end |
||
Line 226: | Line 188: | ||
:done() |
:done() |
||
-- Inner episode tables |
|||
:node(ep_tbl.hopeport) |
|||
:node(ep_tbl.hopeforest) |
|||
:IF(not other.free) |
|||
:node(ep_tbl.mine) |
|||
:node(ep_tbl.crenopolis) |
|||
:END() |
|||
:IF(pt.has_content(other.date)) |
|||
for i, tbl in ipairs(ep_tbl) do |
|||
:tag('tr') |
|||
if (not other.free and episodes[i].free ~= true) |
|||
:tag('td') |
|||
or episodes[i].free == true then |
|||
:css({['text-align']='center'}) |
|||
out:node(tbl) |
|||
:tag('small') |
|||
end |
|||
:tag('b') |
|||
end |
|||
:wikitext('Last Updated:') |
|||
:done() |
|||
if pt.has_content(other.date) then |
|||
:tag('br'):done() |
|||
: |
:IF(other.date == 'now') |
||
:wikitext(lang:formatDate('j F Y h:i:s', mw.getCurrentFrame():preprocess('{{REVISIONTIMESTAMP}}'))) |
|||
:css({['text-align']='center'}) |
|||
: |
:ELSE() |
||
: |
:wikitext(other.date) |
||
: |
:END() |
||
:done() |
:done() |
||
:tag('br'):done() |
|||
:IF(other.date == 'now') |
|||
:wikitext(lang:formatDate('j F Y', mw.getCurrentFrame():preprocess('{{REVISIONTIMESTAMP}}'))) |
|||
:ELSE() |
|||
:wikitext(other.date) |
|||
:END() |
|||
:done() |
:done() |
||
:done() |
:done() |
||
: |
:END() |
||
end |
|||
out:allDone() |
return out:allDone() |
||
local div = out |
|||
if other.right then |
|||
div = mw.html.create('div') |
|||
:css({float='right'}) |
|||
:node(out) |
|||
:done() |
|||
end |
|||
return div |
|||
end |
end |
||