Module:Sandbox/User:Californ1a/T/Professions: Difference between revisions
Module:Sandbox/User:Californ1a/T/Professions (edit)
Revision as of 03:05, 6 January 2025
, Monday at 03:05no edit summary
Californ1a (talk | contribs) (Created page with "require('strict') require('Module:Mw.html extension') local pt = require('Module:Paramtest') local yn = require('Module:Yesno') local lang = mw.language.getContentLanguage() local p = {} local icon_size = 20 local ep_icon_size = 16 -- List episodes with their professions local episodes = { hopeport = {"guard", "chef", "fisher", "forager", "alchemist"}, hopeforest = {"scout", "gatherer", "woodcutter", "carpenter"}, mine = {"minefighter", "bonewright", "miner", "black...") |
Californ1a (talk | contribs) mNo edit summary |
||
(3 intermediate revisions by the same user not shown) | |||
Line 11:
-- List episodes with their professions
local episodes = {
{
free = true,
name = 'Hopeport',
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 = {},
},
}
-- Get professions levels given an episode order number
function p.filter_by_episode(professions, episodeOrder)
local filtered = {}
local episodeProfessions = episodes[
-- Add the professions and the total for the episode
for _, profession in ipairs(episodeProfessions) do
if professions[profession] ~= nil then
filtered[profession] = professions[profession]
end
end
-- Add the total for the episode
local ep_name = episodes[episodeOrder].name:lower()
if professions[ep_name] ~= nil then
filtered[ep_name] = professions[ep_name]
end
Line 73 ⟶ 76:
-- Build the professions + goals lists
for
local ep_name = episode.name:lower()
professions[ep_name] = 0
for _, profession in ipairs(episode.professions) do
-- Add the profession and goal to their respective lists
professions[
goals[
-- Add this profession's level to the episode's total
local value = professions[
professions[
end
-- Add this episode's total to the overall total
professions.total = professions.total + professions[
end
Line 92 ⟶ 96:
vertical = yn(pt.default_to(args.vertical, true), true),
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 100 ⟶ 106:
end
function p.create_row(tbl,
if vertical then
tbl:tag('tr')
Line 107 ⟶ 113:
-- Create icons
local cache = {}
for _,profession in ipairs(episodes[
local PRO = pt.ucflc(profession)
local size = icon_size
Line 132 ⟶ 138:
-- Create levels
for _, profession in ipairs(episodes[
local PRO = cache[profession].name
local lvl = tostring(professions[profession])
Line 154 ⟶ 160:
end
function p.create_episode_table(
local
local
local EP = episodes[episodeOrder].name
local ep_name = episodes[episodeOrder].name:lower()
local out = mw.html.create('tr'):tag('td'):tag('table')
:addClass('center')
: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('th')
: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})
:wikitext(mw.ustring.format('[[File:%s episode icon.png|link=%s|%spx]] [[%s]] (%s)', EP, EP, ep_icon_size, EP, professions[
:done()
:done()
out = p.create_row(out,
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 i in ipairs(released_episodes) do
local
local ep_goals = p.filter_by_episode(goals, i)
table.insert(ep_tbl, p.create_episode_table(i, ep_lvls, ep_goals, other))
end
Line 188 ⟶ 226:
:done()
for i, tbl in ipairs(ep_tbl) do
if (not other.free and episodes[i].free ~= true)
or episodes[i].free == true then
out:node(tbl)
end
end
if pt.has_content(other.date) then
:css({['text-align']='center'})
:
: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()
:
end
local div = out
if other.right then
div = mw.html.create('div')
:css({float='right'})
:node(out)
:done()
end
return div
end
|