Module:Sandbox/Mistiryshak3
Jump to navigation
Jump to search
Documentation for this module may be created at Module:Sandbox/Mistiryshak3/doc
local getArgument = require('Module:Arguments').getArgument
local p = {}
function trim(s) -- Allows removing of whitespace from inputs; adapted from (https://www.lua.org/manual/2.4/node32.html)
local l = 1
while string.sub(s,l,l) == ' ' do
l = l+1
end
local r = string.len(s)
while string.sub(s,r,r) == ' ' do
r = r-1
end
return string.sub(s,l,r)
end
function p.Main(frame)
local args = frame.args
local input = args[1]:lower()
local getSkill = mw.loadData('Module:Data/Skill/dx2').skill
local getIcon = mw.loadData('Module:Data/Icon/dx2').icon
if not getSkill[input] then
error("Skill \"" .. input .. "\" not defined for Dx2")
end
if getSkill[input] and getSkill[input].link then -- Check if an alternate link for a page is set in skill data
name = '[[' .. getSkill[input].link .. '|' .. getSkill[input].name .. ']]<span id="' .. getSkill[input].name .. '"></span>'
else
name = '[[' .. getSkill[input].name .. ']]<span id="' .. getSkill[input].name .. '"></span>'
end
if getSkill[input] and getSkill[input].name_note then
namenote = frame:expandTemplate{ title = 'exp', args = { getSkill[input].name_note } }
else
namenote = ''
end
local iconOverride = ''
if getSkill[input].attribute then
attribute = getSkill[input].attribute:lower()
else
attribute = ''
end
if getSkill[input]["icon"] then
iconOverride = getSkill[input]["icon"]:lower()
end
if getIcon[attribute] ~= '' and getIcon[attribute] ~= nil then
if getIcon[iconOverride] then --Check for manual override for icon
name = '\n|style="text-align:left; white-space:nowrap;"|' .. getIcon[iconOverride] .. ' ' .. name .. namenote -- Set icon
elseif getIcon[attribute] then -- Check if attribute is set in icon data
name = '\n|style="text-align:left; white-space:nowrap;"|' .. getIcon[attribute] .. ' ' .. name .. namenote -- Set icon
else
name = '\n|style="text-align:center; white-space:nowrap;"|' .. name .. namenote
end
elseif getSkill[input].multi and getSkill[input].multi ~= '' and getSkill[input].multi ~= nil then
local iconsTemp = getSkill[input].multi
local Init = 0
local multIcons = ''
repeat
local stringEnd = string.find(iconsTemp, ',', Init)
if stringEnd ~= nil then
local currentMulti = trim(string.sub(iconsTemp, Init, stringEnd - 1)):lower()
if getIcon[currentMulti] ~= nil then
multIcons = multIcons .. getIcon[currentMulti]
end
Init = stringEnd + 1
else
local currentMulti = trim(string.sub(iconsTemp, Init, -1)):lower()
if getIcon[currentMulti] ~= nil then
multIcons = multIcons .. getIcon[currentMulti]
end
stringEnd = nil
end
until stringEnd == nil
name = '\n|style="text-align:left; white-space:nowrap;"|' .. multIcons .. ' ' .. name .. namenote
else
name = '\n|style="text-align:center; white-space:nowrap;"|' .. name .. namenote
end
if getSkill[input].rarity then
rarity = '\n|style="text-align:center;"|' .. frame:expandTemplate{ title = 'Star', args = { getSkill[input].rarity } }
else
rarity = ''
end
if getSkill[input].component then
component = '\n|style="text-align:center; white-space:nowrap"|' .. getSkill[input].component
elseif getSkill[input].mainapt then
component = '\n|style="text-align:center; white-space:nowrap"|—'
else
component = ''
end
if getSkill[input].mainapt then
mainapt = '\n|style="text-align:left; white-space:nowrap"|' .. getIcon[getSkill[input].mainapt:lower()] .. ' ' .. getSkill[input].maintype
else
mainapt = ''
end
if getSkill[input].subapt then
subapt = '\n|style="text-align:left; white-space:nowrap"|' .. getIcon[getSkill[input].subapt:lower()] .. ' ' .. getSkill[input].subtype
elseif mainapt ~= '' then
subapt = '\n|style="text-align:center;"|—'
else
subapt = ''
end
if getSkill[input].attribute ~= 'passive' and not getSkill[input].mainapt and getSkill[input].cost and getSkill[input].costtype then
cost = '\n|style="text-align:center;"|' .. getSkill[input].cost .. ' ' .. getSkill[input].costtype
elseif getSkill[input].attribute ~= 'passive' and not getSkill[input].mainapt and getSkill[input].cost then
cost = '\n|style="text-align:center;"|' .. getSkill[input].cost
else
cost = ''
end
if getSkill[input].hit then
if getSkill[input].attribute and getSkill[input].attribute:lower() == 'bad status' and getSkill[input].armname then
hit = ''
else
hit = '\n|style="text-align:center;"|' .. getSkill[input].hit
if getSkill[input].hit_note then
hit = hit .. frame:expandTemplate{ title = 'Exp', args = { getSkill[input].hit_note } }
end
end
else
hit = ''
end
if getSkill[input].target then
target = '\n|style="text-align:center;"|' .. getSkill[input].target
else
target = ''
end
if getSkill[input].pow then
if getSkill[input].attribute and getSkill[input].attribute:lower() == 'healing' and getSkill[input].armname then
power = ''
else
power = '\n|style="text-align:center;"|' .. getSkill[input].pow
end
else
power = ''
end
if getSkill[input].use then
use = '\n|style="text-align:center;"|' .. getSkill[input].use
else
use = ''
end
if getSkill[input].description then
description = '\n|style="text-align:left;"|' .. getSkill[input].description
else
description = ''
end
if getSkill[input].level then
level = '\n|style="text-align:left;"|' .. getSkill[input].level
else
level = ''
end
if not getSkill[input].unique and getSkill[input].skillpoints then
skillpoints = '\n|style="text-align:left;"|' .. getSkill[input].skillpoints
else
skillpoints = ''
end
if getSkill[input].unique then
unique = '\n|style="text-align:left;"|' .. getSkill[input].unique
else
unique = ''
end
if getSkill[input].armname then
armname = '\n|style="text-align:left;"|' .. getSkill[input].armname
else
armname = ''
end
if getSkill[input].armdemon then
armdemon = '\n|style="text-align:left;"|' .. getSkill[input].armdemon
else
armdemon = ''
end
if getSkill[input].notes then
notes = '\n|style="text-align:center;"|' .. getSkill[input].notes
else
notes = ''
end
local output = name .. rarity .. component .. mainapt .. subapt .. cost .. hit .. target .. power .. use .. description
.. level .. skillpoints .. unique .. armname .. armdemon .. notes .. '\n|-'
return output
end
return p