mNo edit summary |
mNo edit summary |
||
Line 40: | Line 40: | ||
fileName = resolveSurvivorsPortraitFileNameById(survivor.id) |
fileName = resolveSurvivorsPortraitFileNameById(survivor.id) |
||
− | result = result .. "<div style=\"display: inline-block; text-align:center;\">[[" .. survivor.name .. "]]" |
+ | result = result .. "<div style=\"display: inline-block; text-align:center; margin: 10px\">[[" .. survivor.name .. "]]" |
result = result .. "[[File:" .. fileName .. ".png|center|frameless|link=" .. survivor.name .. "]]</div>" |
result = result .. "[[File:" .. fileName .. ".png|center|frameless|link=" .. survivor.name .. "]]</div>" |
||
Revision as of 21:30, 14 May 2020
local p = {}
local data = require("Module:Datatable")
local mathOps = require("Module:MathOps")
local utils = require("Module:Utils")
local frame = mw.getCurrentFrame()
local bar = "|" -- code for |
local nl = "\n"
function p.getCountOfSurvivors()
return utils.getCount("survivor")
end
function getSurvivorIndexById(id)
for i, s in ipairs(survivors) do
if s.id == id then return i end
end
return 0
end
function getSurvivorIndexByName(name) --not used
local i = 1
while survivors[i] do
if survivors[i].name == name then
return i
end
i = i + 1
end
return 0
end
function p.resolveSurvivorsTable()
local result = ""
local name
local fileName
result = result .. "<div style=\"color: #fff;\">"
for i, survivor in ipairs(survivors) do
fileName = resolveSurvivorsPortraitFileNameById(survivor.id)
result = result .. "<div style=\"display: inline-block; text-align:center; margin: 10px\">[[" .. survivor.name .. "]]"
result = result .. "[[File:" .. fileName .. ".png|center|frameless|link=" .. survivor.name .. "]]</div>"
end
result = result .. "</div>"
return result
end
function resolveSurvivorsPortraitFileNameById(id)
i = getSurvivorIndexById(id)
local fileConst = "_charPreview_portrait"
local fileName
fileName = getFileNameFromTableById(id)
if isValidFileName(fileName .. fileConst) then --looking for new convention fileName
fileName = resolveNewInitialsByIndex(i)
end
if isValidFileName(fileName .. fileConst) then --looking for old convention fileName
mw.log("File not found. Looking further...")
fileName = getSurvivorsInitialsByIndex(i)
end
if isValidFileName(fileName .. fileConst) then --File not Found
fileName = "UnknownSurvivor"
end
fileName = fileName .. fileConst
mw.log(fileName)
return fileName
end
function isValidFileName(name)
return name == "" or not mw.title.new("File:" .. name .. ".png").exists
end
function getFileNameFromTableById(id)
for j, sImage in ipairs(survivorImages) do
if sImage.id == id then
return sImage.preview
end
end
return ""
end
function resolveNewInitialsByIndex(i)
if survivors[i] == nil then
return ""
end
local s = survivors
local initials = getSurvivorsInitialsByIndex(i)
local dlcCodeName =""
if s[i].dlc ~= nil then
dlcCodeName = getDlcById(s[i].dlc).codeName
end
local dlcInitial = dlcCodeName:match("^(%S).+$") or "A" --A is for characters from original game as they don't have any DLC code Name nor DLC id
mw.log(dlcInitial .. initials .. "S")
return dlcInitial .. initials .. "S"
end
function getSurvivorsInitialsByIndex(i)
if survivors[i] == nil then
return ""
end
local firstLetter, lastLetter
firstLetter, lastLetter = survivors[i].name:match("^(%S).+ (%S).-$")
return firstLetter .. lastLetter
end
function getDlcById(id)
for _, dlc in ipairs(dlcs) do
if dlc.id == id then return dlc end
end
end
return p