mNo edit summary |
mNo edit summary |
||
Line 46: | Line 46: | ||
if type(param) == "table" and param.args[1] ~= nil then |
if type(param) == "table" and param.args[1] ~= nil then |
||
return tonumber(param.args[1]) |
return tonumber(param.args[1]) |
||
+ | else |
||
+ | return param |
||
+ | end |
||
+ | end |
||
+ | |||
+ | function ResolveStringParam(param) |
||
+ | if type(param) == "table" and param.args[1] ~= nil then |
||
+ | return tostring(param.args[1]) |
||
+ | elseif param == nil then |
||
+ | return mw.title.getCurrentTitle().text |
||
else |
else |
||
return param |
return param |
||
Line 103: | Line 113: | ||
mw.log(perkDesc.teachDesc[1]) |
mw.log(perkDesc.teachDesc[1]) |
||
return perkDesc.teachDesc[1] |
return perkDesc.teachDesc[1] |
||
+ | end |
||
+ | end |
||
+ | end |
||
+ | |||
+ | function p.getPerkDescriptionByName(name) |
||
+ | name = ResolveStringParam(name) |
||
+ | |||
+ | for _, perk in ipairs(perks) do |
||
+ | if perk.name == name then |
||
+ | return p.getPerkDescription(perk.id) |
||
end |
end |
||
end |
end |
Revision as of 16:18, 1 September 2020
local p = {}
local frame = mw.getCurrentFrame()
--local data = require("Module:Datatable")
local dataPerks = require("Module:Datatable/Perks")
local utils = require("Module:Utils")
local bar = "|" -- code for |
local nl = "\n"
local ntl = "|-" -- new table line
local strings = {
perkValuesNotFound = "The Values for the perk wasn't found",
unitNotFound = "The Unit value wasn't found"
}
function getUnusedPerksCount()
local result = 0
for _, perk in ipairs(perks) do
if perk.unused == true then result = result + 1 end
end
return result
end
function getCommonPerksCount()
local result = 0
for _, perk in ipairs(perks) do
if perk.character == nil and perk.unused ~= true then result = result + 1 end
end
return result
end
local _unusedPerksCount = getUnusedPerksCount()
local _commonPerksCount = getCommonPerksCount()
local _uniquePerksCount = table.getn(perks) - _unusedPerksCount - _commonPerksCount
function p.getPerksCount()
return _uniquePerksCount + _commonPerksCount
end
function ResolveIntParam(param)
if type(param) == "table" and param.args[1] ~= nil then
return tonumber(param.args[1])
else
return param
end
end
function ResolveStringParam(param)
if type(param) == "table" and param.args[1] ~= nil then
return tostring(param.args[1])
elseif param == nil then
return mw.title.getCurrentTitle().text
else
return param
end
end
function getUnitById(id)
mw.log(id)
for _,unit in ipairs(units) do
if unit.id == id then return unit.value end
end
return unitNotFound
end
--Function that actually returns string that will replace the placeholder
function pl(id, tripplet)
tripplet = tonumber(tripplet)
for _,perk in ipairs(perks) do
if perk.id == id then
local index = 1 + ((tripplet - 1) * 3) --tripplet is an offset, +1 is indexing from 1 in LUA, * 3 is because every values are grouped by 3 values/tiers
return "'''" .. utils.clr(perk.values[index], perk.baseLevel) .. "'''/'''" .. utils.clr(perk.values[index + 1], perk.baseLevel + 1) .. "'''/'''" .. utils.clr(perk.values[index + 2], perk.baseLevel + 2) .. "''' "
.. getUnitById(perk.units[tripplet]) --Units, Tripplet is an index in 'units' list
end
end
return "'''" .. strings.perkValuesNotFound .. "''"
end
--Function replaces "#pl(x)" string with tripplet value of according number in brackets
function subValues(perkDesc)
local result
local regexString = "#pl%((%d)%)" -- looking and extracting number from "#pl(x)"
for m in perkDesc.desc[1][1]:gmatch(regexString) do --TODO the first index shouldn't be hardcoded due to history log (if the description will be copied, then it won't be the first)
mw.log(mw.dumpObject(m))
result = perkDesc.desc[1][1]:gsub(regexString, pl(perkDesc.id, m))
mw.log(result)
end
--mw.log("PL: " .. pl)
return result
end
function p.getPerkDescription(id)
id = ResolveIntParam(id)
for _, perkDesc in ipairs(perkDescription) do
if perkDesc.id == id then
mw.log(subValues(perkDesc))
return subValues(perkDesc)
end
end
end
function p.getPerkTeachableDescription(id)
id = ResolveIntParam(id)
for _, perkDesc in ipairs(perkDescription) do
if perkDesc.id == id then
mw.log(perkDesc.teachDesc[1])
return perkDesc.teachDesc[1]
end
end
end
function p.getPerkDescriptionByName(name)
name = ResolveStringParam(name)
for _, perk in ipairs(perks) do
if perk.name == name then
return p.getPerkDescription(perk.id)
end
end
end
return p