Module:EnemyNav: Difference between revisions
From IdleOn MMO Wiki
Kiokurashi (talk | contribs) mNo edit summary |
Kiokurashi (talk | contribs) mNo edit summary |
||
(27 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
local p = {} | local p = {} | ||
local Lists = mw.loadData("Module:EnemyNav/data") | local Lists = mw.loadData("Module:EnemyNav/data") | ||
local function formatNav(prevEnemy, nextEnemy) | |||
-- construct output. | |||
local navBar = [[<div class='EnemyNav'><div class='EnemyNavLeft'>%s</div><div class='EnemyNavCenter'>Enemies</div><div class='EnemyNavRight'>%s</div></div>]] | |||
local enemySect = "[[File:%s_icon.png|16px|link=%s]] [[%s]]" | |||
local pFormat = prevEnemy ~= '' and string.format("[[File:ArrowLeft.png|15px|link=%s]]" .. enemySect, prevEnemy, prevEnemy, prevEnemy, prevEnemy) or '' | |||
local nFormat = nextEnemy ~= '' and string.format(enemySect .. "[[File:ArrowRight.png|15px|link=%s]]", nextEnemy, nextEnemy, nextEnemy, nextEnemy) or '' | |||
return string.format(navBar, pFormat, nFormat) | |||
end | |||
function p.BuildNav( frame ) | function p.BuildNav( frame ) | ||
Line 8: | Line 18: | ||
-- branch data load based on type | -- branch data load based on type | ||
if enemyType == 'Normal' then navList = Lists.enemyList | if enemyType == 'Normal' then | ||
elseif enemyType == 'Boss' then navList = Lists.bossList | navList = Lists.enemyList | ||
elseif enemyType == 'Event' then navList = Lists.eventList | elseif enemyType == 'Boss' then | ||
elseif enemyType == 'Dungeon' then navList = Lists.dungeonList | navList = Lists.bossList | ||
elseif enemyType == 'Rift' then navList = Lists.riftList | elseif enemyType == 'Event' then | ||
navList = Lists.eventList | |||
elseif enemyType == 'Dungeon' then | |||
-- Iterate until self found. | navList = Lists.dungeonList | ||
local i | elseif enemyType == 'Rift' then | ||
for | navList = Lists.riftList | ||
if | elseif enemyType == 'Special' then | ||
return '' | |||
elseif enemyType == 'Undefined' then | |||
return midEnemy .. " doesn't have an associated Navigation list.[[Category:EnemyNav Type Error]]" | |||
else | |||
return '' | |||
end | |||
-- Iterate until self found, and through to the end for list size. | |||
local i = 0 | |||
local size = 0 | |||
for n,v in ipairs(navList) do | |||
size = size + 1 | |||
if v == midEnemy then i = n end | |||
end | end | ||
if i == 0 then return "This enemy is not in the " .. enemyType .. " list." end | |||
-- Using self-index get previous and next enemies, if they exist. | -- Using self-index get previous and next enemies, if they exist. | ||
local prevEnemy = | local prevEnemy = i ~= 1 and navList[i-1] or '' | ||
local nextEnemy = | local nextEnemy = i ~= size and navList[i+1] or '' | ||
return formatNav(prevEnemy, nextEnemy) | |||
return | |||
end | end | ||
return p |
Latest revision as of 05:46, 6 April 2024
Documentation for this module may be created at Module:EnemyNav/doc
local p = {}
local Lists = mw.loadData("Module:EnemyNav/data")
local function formatNav(prevEnemy, nextEnemy)
-- construct output.
local navBar = [[<div class='EnemyNav'><div class='EnemyNavLeft'>%s</div><div class='EnemyNavCenter'>Enemies</div><div class='EnemyNavRight'>%s</div></div>]]
local enemySect = "[[File:%s_icon.png|16px|link=%s]] [[%s]]"
local pFormat = prevEnemy ~= '' and string.format("[[File:ArrowLeft.png|15px|link=%s]]" .. enemySect, prevEnemy, prevEnemy, prevEnemy, prevEnemy) or ''
local nFormat = nextEnemy ~= '' and string.format(enemySect .. "[[File:ArrowRight.png|15px|link=%s]]", nextEnemy, nextEnemy, nextEnemy, nextEnemy) or ''
return string.format(navBar, pFormat, nFormat)
end
function p.BuildNav( frame )
local enemyType = frame.args.Type
local midEnemy = frame.args.Enemy -- Pagename
local navList = {}
-- branch data load based on type
if enemyType == 'Normal' then
navList = Lists.enemyList
elseif enemyType == 'Boss' then
navList = Lists.bossList
elseif enemyType == 'Event' then
navList = Lists.eventList
elseif enemyType == 'Dungeon' then
navList = Lists.dungeonList
elseif enemyType == 'Rift' then
navList = Lists.riftList
elseif enemyType == 'Special' then
return ''
elseif enemyType == 'Undefined' then
return midEnemy .. " doesn't have an associated Navigation list.[[Category:EnemyNav Type Error]]"
else
return ''
end
-- Iterate until self found, and through to the end for list size.
local i = 0
local size = 0
for n,v in ipairs(navList) do
size = size + 1
if v == midEnemy then i = n end
end
if i == 0 then return "This enemy is not in the " .. enemyType .. " list." end
-- Using self-index get previous and next enemies, if they exist.
local prevEnemy = i ~= 1 and navList[i-1] or ''
local nextEnemy = i ~= size and navList[i+1] or ''
return formatNav(prevEnemy, nextEnemy)
end
return p