Module:DLCs

local p = {} local data = require("Module:Datatable") local mathOps = require("Module:MathOps") local utils = require("Module:Utils") local c = utils -- As there is onlny one function relevant to colors I make only alias to utils Module to convenient naming "c - color" local frame = mw.getCurrentFrame local bar = "&#124;" -- code for | local nl = "\n" local ntl = "|-" -- new table line local strings = { noDLC = "DLC wasn't found in DLC table in Datatable Module", noSpecialTheme = "No special Theme Music", noSteamLink = "No linked Store Page", sp = "Store Page", rd = "Release Date", cat = "Category", cost = "Cost", theme = "Theme Music", chapter = "CHAPTER", file = "File" }

fileSuffixes = { "", --Undefined "_main_header", --DLC Image " Theme Music" --DLC Theme music }

function p.getCallTable(parameter) return mw.dumpObject(parameter) end

function getShortenedFileName(name) name = utils.RemoveSpecialCharacters(name) return getShortName(name) end

function getShortName(name) if name:match(":") ~= nil then return name:match(".*: *(.+)") else return name end end

function resolveDlcParameter(dlc) if dlc == nil then return getDlcByName(getShortName(mw.title.getCurrentTitle.text)) or getDlcByName(mw.title.getCurrentTitle.text) elseif type(dlc) == "table" then if dlc.args[1] == nil then return getDlcByName(getShortName(mw.title.getCurrentTitle.text)) or getDlcByName(mw.title.getCurrentTitle.text) --none parameter, calling from page end if type(dlc.args[1]) == nil then return getDlcByName(getShortName(mw.title.getCurrentTitle.text)) elseif type(dlc.args[1]) == "string" then if tonumber(dlc.args[1]) == nil then return getDlcByName(dlc.args[1]) else return getDlcById(tonumber(dlc.args[1])) end end elseif type(dlc) == "string" then return getDlcByName(dlc) elseif type(dlc) == "number" then return getDlcById(dlc) end end

function getDlcByName(name) for _, dlcItem in ipairs(dlcs) do		if name == dlcItem.name then return dlcItem end end end

function getDlcById(id) for _, dlcItem in ipairs(dlcs) do		if id == dlcItem.id then return dlcItem end end end

function p.getCountOfDlcs return utils.getCount("dlc") end

function p.getCountOfChapters return utils.getCount("chapter") end

function p.getCountOfParagraphs return utils.getCount("paragraph") end

function p.getCountOfClothingDlcs return utils.getCount("clothing") end

function p.getCountOfSoundtracks return utils.getCount("ost") end

function p.getCountOfCharacterDlcs return utils.getCount("character") end

function getCountOfCosts(dlc) for i, _ in ipairs(dlc.cost) do end return i end

function getCostTable(dlc) local result = "" if type(dlc.cost) == "string" then return "| " .. dlc.cost end for i, cost in ipairs(dlc.cost) do		local ccy = getCurrencyById(cost.ccy) if cost.value == 0 then cost.value = "-" end result = result .. "| " 		if ccy.gc then result = result .. utils.commaFormat(cost.value) .. " " .. frame:expandTemplate{ title = "IconLink", args = { ccy.name .. "s"} } -- #1: calling IconLink template #2: the 's' makes plural version of currency, else result = result .. ccy.symbol .. cost.value end if dlc.cost[i + 1] ~= nil then result = result .. nl .. ntl .. nl		end end return result end

function getCountDlcCosts(dlc) if type(dlc.cost) == "string" then return 1 end return #dlc.cost end

function getCurrencyById(id) for _, ccyItem in ipairs(ccy) do		if ccyItem.id == id then return ccyItem end end end

function resolveCurrency(ccy) if ccy.gc then return else end end

function p.resolveThemeMusic resolveThemeMusic(getDlcById(15)) end --dev remove

--Stranger Things Theme Music.ogg function resolveThemeMusic(dlc) local name = strings.file .. ":" .. getShortenedFileName(dlc.name) .. fileSuffixes[3] --remake it -dev TODO mw.log(name) mw.log(mw.title.new( name .. ".ogg").exists) if mw.title.new( name .. ".mp3").exists then return "" .. name .. ".mp3" end if mw.title.new( name .. ".ogg").exists then return "" .. name .. ".ogg" end for i, theme in ipairs(dlcThemes) do		if theme.id == dlc.id then if mw.title.new(strings.file .. ":" .. theme.fileName .. ".mp3").exists then return "" .. strings.file .. ":" .. theme.fileName .. ".mp3" end if mw.title.new(strings.file .. ":" .. theme.fileName .. ".ogg").exists then return "" .. strings.file .. ":" .. theme.fileName .. ".ogg" end break end end return strings.noSpecialTheme end

function resolveShopLink(dlc) if dlc.link ~= nil then return "[https://store.steampowered.com/app/" .. dlc.link .. " " .. strings.sp .. "]"	end return strings.noSteamLink end

function p.getImageFileNameByDlc(id) mw.log(getImageFileNameByDlc(getDlcById(id))) end --dev remove

function getImageFileNameByDlc(dlc) for _, dlcImage in ipairs(dlcImages) do		if dlc.id == dlcImage.id then return utils.resolveImageName(dlcImage.cover) end end return utils.resolveImageName(utils.resolveFileName(dlc.name) .. fileSuffixes[2]) end

function p.resolveDlcTable(dlc) dlc = resolveDlcParameter(dlc) if dlc == nil then return "'''" .. frame:expandTemplate{title = "clr", args = { "gold", strings.noDlc}} .. "'''" .. nl end local result = ""

result = result .. "{|class=\"wikitable\" style=\"float:right;\"" .. nl result = result .. "|- style=\"font-size: 24px;\"" .. nl result = result .. "! width=\"300px\" align=\"center\" colspan=\"2\" | '''" .. dlc.name .. "'''" .. nl result = result .. ntl .. nl result = result .. "| align=\"center\" width=\"300px\" height=\"50px\" colspan=\"2\" |300px" .. nl result = result .. ntl .. nl result = result .. "| width=\"100px\" | '''" .. strings.rd .. "'''|| width=\"200px\" | " .. utils.resolveDateTime(dlc.rDate) .. nl result = result .. ntl .. nl result = result .. "| width=\"100px\" | '''" .. strings.cat .. "'''|| width=\"200px\" | " .. dlcCategories[dlc.category] .. nl result = result .. ntl .. nl result = result .. "| width=\"100px\" rowspan = " .. getCountDlcCosts(dlc) .. " | '''" .. strings.cost .. "''' || width=\"200px\" " .. getCostTable(dlc) .. nl result = result .. ntl .. nl result = result .. "| width=\"100px\" | '''" .. strings.theme .. "'''|| width=\"200px\" |" .. resolveThemeMusic(dlc) .. nl result = result .. ntl .. nl result = result .. "! width=\"300px\" align=\"center\" colspan=\"2\" | " .. resolveShopLink(dlc) .. nl result = result .. "|}"

mw.log(mw.dumpObject(result)) return result end

--DEV function try(f, catch_f) local status, exception = pcall(f) if not status then catch_f(exception) end end

function p.getListOfDlcChapters local result = ""; local counter = 1; for _, dlcItem in ipairs(dlcs) do		if dlcItem.category == 1 then result = result .. "* " .. strings.chapter .. " " .. ToRomanNumerals(counter) .. ": " .. dlcItem.name .. "" .. nl			counter = counter + 1 end end mw.log(result) return result end

return p