(My mistake, sorry) Tag: Undo |
mNo edit summary |
||
(7 intermediate revisions by 3 users not shown) | |||
Line 71: | Line 71: | ||
function resolveSurvivorsPortraitFileNameById(id) |
function resolveSurvivorsPortraitFileNameById(id) |
||
− | i = getSurvivorIndexById(id) |
||
local fileConst = "_charPreview_portrait" |
local fileConst = "_charPreview_portrait" |
||
local fileName |
local fileName |
||
fileName = getFileNameFromTableById(id) |
fileName = getFileNameFromTableById(id) |
||
− | if not isValidFileName(fileName) then -- |
+ | if not utils.isValidFileName(fileName) then --S{ID}_charPreview_portrait |
− | fileName = |
+ | fileName = "S" .. string.format("%02d", id) .. fileConst |
end |
end |
||
− | if not isValidFileName(fileName) then -- |
+ | if not utils.isValidFileName(fileName) then --File not Found |
− | mw.log("File not found. Looking further...") |
||
− | fileName = getSurvivorsInitialsByIndex(i) .. fileConst |
||
− | end |
||
− | if not isValidFileName(fileName) then --File not Found |
||
fileName = "UnknownSurvivor" .. fileConst |
fileName = "UnknownSurvivor" .. fileConst |
||
end |
end |
||
− | fileName = fileName |
||
mw.log(fileName) |
mw.log(fileName) |
||
return fileName |
return fileName |
||
− | end |
||
− | |||
− | function isValidFileName(name) |
||
− | return not (name == "" or not mw.title.new("File:" .. name .. ".png").exists) |
||
end |
end |
||
Line 104: | Line 94: | ||
end |
end |
||
return "" |
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 and dlcs[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 .. "S " .. initials) |
||
− | return dlcInitial .. "S " .. initials |
||
− | 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 |
end |
||
Revision as of 13:41, 12 November 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 p.resolveSurvivorsTableMainPage()
local result = ""
local name
local fileName
result = result .. "<div class=\"fpbox\" id=\"fpsurvivors\" style=\"text-align: center;\">"
result = result .. "<div class=\"heading\">The [[Survivors]] [[File:IconHelpLoading survivor.png|32px]]</div>"
result = result .. "<div class=\"fplinks\">"
for i, survivor in ipairs(survivors) do
name = survivor.shortName or survivor.name
fileName = resolveSurvivorsPortraitFileNameById(survivor.id)
result = result .. "<div class=\"fplink plainlinks image\"><div class=\"box\"><div class=\"row\"><div class=\"cell\">"
result = result .. "<div class=\"image\">[[File:" .. fileName .. ".png|link=" .. name .. "]]</div>"
result = result .. "<div class=\"link\">[[" .. name .. "]]</div></div></div></div></div>"
end
result = result .. "</div>"
result = result .. "</div>"
return result
end
function resolveSurvivorsPortraitFileNameById(id)
local fileConst = "_charPreview_portrait"
local fileName
fileName = getFileNameFromTableById(id)
if not utils.isValidFileName(fileName) then --S{ID}_charPreview_portrait
fileName = "S" .. string.format("%02d", id) .. fileConst
end
if not utils.isValidFileName(fileName) then --File not Found
fileName = "UnknownSurvivor" .. fileConst
end
mw.log(fileName)
return fileName
end
function getFileNameFromTableById(id)
mw.log(id)
for j, sImage in ipairs(survivorImages) do
if sImage.id == id then
return sImage.preview
end
end
return ""
end
function getDlcById(id)
for _, dlc in ipairs(dlcs) do
if dlc.id == id then return dlc end
end
end
return p