--[[
Module:Special allows for the the presentation of SPECIAL statistics across various formats, without requiring the use of parser hooks to handle the data input.
Tables
statistics
Holds the name of each special statistic in plain text format.
links
Holds the pipe linked name of each statistic, shortening the name to two characters in length on an article.
Variables
value
value takes the first argument as the base values of the SPECIAL statistics and stores them in a table format with numbered keys.
modifer
modifer takes the second argument as the SPECIAL modifier and stares them in a tbale format with numbered keys.
title
title stores the third argument as a string to use as a title, the third argument is non-essential.
perk
perk is a counter variable, which servers two roles. Firstly it is used to retrive values from the tables as the key value for use in table construction and secondly as an incrimentor in loops.
results
results stores the output of the module to be embedded in the article.
thisPerk
Takes the current value of value[perk] and assigns the value or 0, dependant on if there is a value present.
Functions
p.string
p.string takes the template arguments and and returns them in a string format.
p.table
p.table takes the arguments and returns them in a table format.
p.test
p.test is a debug function, which shouldn't be used in articles.
]]--
-- See [[Module:Special/doc]] for documentation
p = {}
local statistics = {
[1] = "Strength",
[2] = "Perception",
[3] = "Endurance",
[4] = "Charisma",
[5] = "Intelligence",
[6] = "Agility",
[7] = "Luck"
}
local links = {
[1] = "[[Strength|ST]]",
[2] = "[[Perception|PE]]",
[3] = "[[Endurance|EN]]",
[4] = "[[Charisma|CH]]",
[5] = "[[Intelligence|IN]]",
[6] = "[[Agility|AG]]",
[7] = "[[Luck|LK]]"
}
function tooltip(value, text)
return '<span class="va-tooltip" style="cursor: help; border-bottom: 1px dotted;" title="' .. text .. ' modified by armor and clothing">' .. value .. '</span>'
end
function p.table(frame)
local value = mw.text.split(frame.args[1], ",") -- Splits the values into an array
local modifier = mw.text.split(frame.args[2], ",") -- Splits the modifiers into an array
local title = frame.args[3] -- If a game title is declared, this will be transferred to a variable
local perk = 1 -- Used for readings the arrays
local result = "<span class='special-shell'>" -- Wrapper shell for SPECIAL stats to allow additional CSS handling
-- Adds the game title if one has been denoted, otherwise nothing is added.
if string.len(title) > 0 then
result = result .. "<div class='special-title'>" .. title .. "</div>"
end
-- Circular script that sets each stat to table cell
while perk <= 7 do
if tonumber(value[perk]) ~= nil then
thisPerk = tonumber(value[perk])
else
thisPerk = 0
end
if perk == 1 then
result = result .. '<table><tr>'
elseif perk == 5 then
result = result .. '</tr></table><table><tr>'
end
result = result .. '<td class="'
-- Classes are required for CSS alignment of stats
if perk > 4 then
result = result .. 'special-bottom">' -- Bottom row
else
result = result .. 'special-top">' -- Top row
end
-- Checks for if the stat is modified by armor/clothing and calls the tooltip function
if modifier[perk] ~= nil and modifier[perk] ~= "" then
result = result .. tooltip( thisPerk + tonumber(modifier[perk]), statistics[perk] ) .. " "
else
result = result .. thisPerk .. " "
end
result = result .. links[perk] .. "</td> "
perk = perk + 1
end
result = result .. "</tr></table></div>"
return result
end
function p.string(frame)
local value = mw.text.split(frame.args[1], ",") -- Splits the values into an array
local modifier = mw.text.split(frame.args[2], ",") -- Splits the modifiers into an array
local title = frame.args[3] -- If a game title is declared, this will be transfered to a variable
local maximum = mw.text.split(frame.args[4], ",") --
local perk = 1 -- Used for readings the arrays
local result = "<span class='special-shell'>" -- Wrapper shell for SPECIAL stats to allow additional CSS handling
-- Adds the game title if one has been denoted, otherwise nothing is added.
if title ~= nil or title ~= "" then
result = result .. "<div class='special-title'>" .. title .. "</div>"
end
while perk <= 7 do
if tonumber(value[perk]) ~= nil then
thisPerk = tonumber(value[perk])
else
thisPerk = 0
end
if tonumber(value[perk]) ~= nil then
perkMax = tonumber(maximum[perk])
else
perkMax = 0
end
if perkMax > thisPerk then
perkArr = " → "
else
perkArr = " ← "
end
if modifier[perk] ~= nil and modifier[perk] ~= "" then
if perkMax ~= 0 then
perkString = thisPerk + tonumber(modifier[perk]) .. perkArr .. perkMax + tonumber(modifier[perk])
else
perkString = thisPerk + tonumber(modifier[perk])
end
result = result .. tooltip( perkString, statistics[perk] ) .. " "
else
if perkMax ~= 0 then
perkString = thisPerk .. perkArr .. perkMax
else
perkString = thisPerk
end
result = result .. perkString .. " "
end
result = result .. links[perk]
if perk <7 then
result = result .. ", "
end
perk = perk + 1
end
result = result .. "</span>"
return result
end
function p.test(frame)
return string.len(tostring(frame.args[3]))
end
return p