Editing Module:Sandbox/User:Californ1a/T/Professions

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.

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[episodeOrder].professions
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 i, episode in ipairs(episodes) do
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[profession] = pt.default_to(tonumber(args[profession]), 0)
professions[key] = pt.default_to(tonumber(args[key]), 0)
goals[profession] = pt.default_to(tonumber(args[profession..' goal']), 0)
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[profession] or 0
local value = professions[key] or 0
professions[ep_name] = professions[ep_name] + value
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[ep_name]
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, episodeOrder, professions, goals, vertical)
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[episodeOrder].professions) do
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 _, profession in ipairs(episodes[episodeOrder].professions) do
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(episodeOrder, professions, goals, other)
function p.create_episode_table(episode, professions, goals, other)
local ep_professions = episodes[episodeOrder].professions
local profession_count = #episodes[episode]
local profession_count = #ep_professions
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[ep_name]))
: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, episodeOrder, professions, goals, other.vertical)
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 ep_lvls = p.filter_by_episode(professions, i)
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
out:tag('tr')
:tag('br'):done()
:tag('td')
:IF(other.date == 'now')
:wikitext(lang:formatDate('j F Y h:i:s', mw.getCurrentFrame():preprocess('{{REVISIONTIMESTAMP}}')))
:css({['text-align']='center'})
:tag('small')
:ELSE()
:tag('b')
:wikitext(other.date)
:wikitext('Last Updated:')
: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()
: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


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