mNo edit summary |
mNo edit summary |
||
(27 intermediate revisions by 4 users not shown) | |||
Line 9: | Line 9: | ||
function p.getCountOfSurvivors() |
function p.getCountOfSurvivors() |
||
return utils.getCount("survivor") |
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 |
||
+ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
+ | return i |
||
+ | end |
||
⚫ | |||
+ | end |
||
+ | return 0 |
||
end |
end |
||
Line 14: | Line 32: | ||
local result = "" |
local result = "" |
||
local name |
local name |
||
⚫ | |||
− | |||
+ | |||
− | result = result .. "<div style=\" |
+ | result = result .. "<div style=\"color: #fff;\">" |
− | |||
+ | for i, survivor in ipairs(survivors) do |
||
⚫ | |||
⚫ | |||
⚫ | |||
+ | fileName = resolveSurvivorsPortraitFileNameById(survivor.id) |
||
⚫ | |||
⚫ | |||
− | --TODO |
||
+ | result = result .. "[[File:" .. fileName .. ".png|center|frameless|link=" .. survivor.name .. "]]</div>" |
||
− | --DF_charPreview_portrait |
||
+ | |||
− | result = result .. "[[File:" .. p.getSurvivorsInitialsByIndex(i) .. "_charPreview_portrait.png|center|frameless|link=" .. name .. "]]<div style=\"width:100%; margin: 0 auto; text-align:center;\">" .. name .. "</div>" |
||
− | --result = result .. "[[File:UnknownSurvivor_charPreview_portrait.png|center|frameless|link=]]<div style=\"width:100%; margin: 0 auto; text-align:center;\">" .. p.getSurvivorsInitialsByIndex(i) .. "</div>" |
||
⚫ | |||
⚫ | |||
end |
end |
||
− | |||
− | |||
result = result .. "</div>" |
result = result .. "</div>" |
||
+ | |||
− | |||
return result |
return result |
||
end |
end |
||
− | function p. |
+ | function p.resolveSurvivorsTableMainPage() |
− | + | local result = "" |
|
+ | local name |
||
⚫ | |||
+ | local fileName |
||
− | elseif type(i) == "table" then |
||
+ | |||
− | i = getSurvivorIndexByName(i.args[1]) |
||
+ | 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 |
end |
||
+ | result = result .. "</div>" |
||
+ | result = result .. "</div>" |
||
+ | |||
+ | return result |
||
+ | end |
||
+ | function resolveSurvivorsPortraitFileNameById(id) |
||
− | local firstLetter, lastLetter |
||
+ | local fileConst = "_charPreview_portrait" |
||
+ | local fileName |
||
+ | fileName = getFileNameFromTableById(id) |
||
− | firstLetter, lastLetter = survivors[i].name:match("^(%S).+ (%S).-$") |
||
+ | 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 firstLetter .. lastLetter |
||
+ | return fileName |
||
end |
end |
||
− | function |
+ | function getFileNameFromTableById(id) |
+ | mw.log(id) |
||
⚫ | |||
+ | for j, sImage in ipairs(survivorImages) do |
||
− | while survivors[i] do |
||
− | if |
+ | if sImage.id == id then |
− | return |
+ | return sImage.preview |
end |
end |
||
− | i = i + 1 |
||
end |
end |
||
− | return |
+ | return "" |
+ | end |
||
+ | |||
+ | function getDlcById(id) |
||
+ | for _, dlc in ipairs(dlcs) do |
||
+ | if dlc.id == id then return dlc end |
||
+ | end |
||
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