Module:Sandbox/User:Californ1a/T/Professions: Difference between revisions

m
no edit summary
mNo edit summary
mNo edit summary
 
(One intermediate revision by the same user not shown)
Line 11:
-- List episodes with their professions
local episodes = {
{
hopeport = {"guard", "chef", "fisher", "forager", "alchemist"},
free = true,
hopeforest = {"scout", "gatherer", "woodcutter", "carpenter"},
name = 'Hopeport',
mine = {"minefighter", "bonewright", "miner", "blacksmith", "stonemason"},
color = '#b99f46',
crenopolis = {"watchperson", "detective", "leatherworker", "merchant"}
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 = {},
},
}
 
-- Get professions levels given an episode order number
local ep_dict = {
function p.filter_by_episode(professions, episodeOrder)
hopeport = 'Hopeport',
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 episodeProfessions = episodes[episodeNameepisodeOrder].professions
 
if not episodeProfessions then
error('Invalid episode name: ' .. tostring(episodeName))
end
 
-- Add the professions and the total for the episode
for _, profession in ipairs(episodeProfessions) do
if professions[profession] ~= nil then
local val = profession
filtered[profession] = professions[profession]
if goals then
val = profession..' goal'
end
if professions[val] ~= nil then
filtered[val] = professions[val]
end
end
 
-- Add the total for the episode
local ep_name = episodes[episodeOrder].name:lower()
if professions[episodeName] ~= nil then
if professions[ep_name] ~= nil then
filtered[episodeName] = professions[episodeName]
filtered[ep_name] = professions[ep_name]
end
 
Line 73 ⟶ 76:
-- Build the professions + goals lists
for episodei, keysepisode in pairsipairs(episodes) do
local ep_name = episode.name:lower()
professions[episode] = 0
professions[ep_name] = 0
for _, key in ipairs(keys) do
for _, profession in ipairs(episode.professions) do
-- Add the profession and goal to their respective lists
professions[keyprofession] = pt.default_to(tonumber(args[keyprofession]), 0)
goals[keyprofession] = pt.default_to(tonumber(args[keyprofession..' goal']), 0)
-- Add this profession's level to the episode's total
local value = professions[keyprofession] or 0
professions[episodeep_name] = professions[episodeep_name] + value
end
-- Add this episode's total to the overall total
professions.total = professions.total + professions[episodeep_name]
end
Line 93 ⟶ 97:
free = yn(pt.default_to(args.free, false), false),
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 101 ⟶ 106:
end
 
function p.create_row(tbl, episodeepisodeOrder, professions, goals, vertical)
if vertical then
tbl:tag('tr')
Line 108 ⟶ 113:
-- Create icons
local cache = {}
for _,profession in ipairs(episodes[episodeepisodeOrder].professions) do
local PRO = pt.ucflc(profession)
local size = icon_size
Line 133 ⟶ 138:
-- Create levels
for _, profession in ipairs(episodes[episodeepisodeOrder].professions) do
local PRO = cache[profession].name
local lvl = tostring(professions[profession])
Line 155 ⟶ 160:
end
 
function p.create_episode_table(episodeepisodeOrder, professions, goals, other)
local profession_countep_professions = #episodes[episodeepisodeOrder].professions
local EPprofession_count = ep_dict[episode]#ep_professions
local EP = episodes[episodeOrder].name
local ep_name = episodes[episodeOrder].name:lower()
local out = mw.html.create('tr'):tag('td'):tag('table')
:addClass('wikitable')
:addClass('center')
:IF(other.infobox)
:css({margin='0', padding='0'})
: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('th')
:IF(other.infobox)
:css({['background-color']=ep_color[episode]})
:addClass('infobox-header')
:css({padding='0.5em'})
:ELSE()
:css({
['background-color'] = episodes[episodeOrder].color,
padding='0 0.5em',
})
:END()
: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[episodeep_name]))
:done()
:done()
out = p.create_row(out, episodeepisodeOrder, professions, goals, other.vertical)
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
 
function p.create_table(professions, goals, other)
local ep_tbl = {}
local released_episodes = getReleasedEpisodes()
for episode in pairs(episodes) do
for i in ipairs(released_episodes) do
local ep_lvls = p.filter_by_episode(professions, episode)
local ep_goalsep_lvls = p.filter_by_episode(goalsprofessions, episodei)
local ep_goals = p.filter_by_episode(goals, i)
ep_tbl[episode] = p.create_episode_table(episode, ep_lvls, ep_goals, other)
table.insert(ep_tbl, p.create_episode_table(i, ep_lvls, ep_goals, other))
end
Line 189 ⟶ 226:
: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()
for i, tbl in ipairs(ep_tbl) do
:IF(pt.has_content(other.date))
if (not other.free and episodes[i].free ~= true)
:tag('tr')
or episodes[i].free == true then
:tag('td')
out:node(tbl)
:css({['text-align']='center'})
end
:tag('small')
end
:tag('b')
:wikitext('Last Updated:')
if pt.has_content(other.date) then
:done()
out:tag('brtr'):done()
:IFtag(other.date == 'nowtd')
:css({['text-align']='center'})
:wikitext(lang:formatDate('j F Y', mw.getCurrentFrame():preprocess('{{REVISIONTIMESTAMP}}')))
:ELSEtag('small')
:wikitexttag(other.date'b')
:ENDwikitext('Last Updated:')
: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()
:ENDdone()
end
out:allDone()
7,248

edits