Module:ChapterVariables

From JoJo's Bizarre Encyclopedia - JoJo Wiki
Revision as of 19:21, 31 July 2024 by HudgynS (talk | contribs)
Jump to navigation Jump to search

Documentation for this module may be created at Module:ChapterVariables/doc

local Mag = require('Module:MagazineVariables')

local p = {}

function p.main(frame)
    local chapterVariablesText = frame.args[1]
    local chapterVariablesData = ""
    local chapterVariablesResult = ""
    local variablesSubPage = 'data'
    if frame.args[2] ~= nil then
        variablesSubPage = 'data/' .. frame.args[2]
    end
    chapterVariablesData = pcall(mw.loadData,('Module:ChapterVariables/' .. variablesSubPage))
    if not chapterVariablesData[0] or chapterVariablesData[1][chapterVariablesText] == nil then
        local magazineVariablesResult = pcall(mw.loadData,('Module:MagazineVariables/' .. variablesSubPage))
        return magazineVariablesResult[1] or chapterVariablesText or ""
    end
    if frame.args[2] == 'ja' then
        chapterVariablesResult = frame:preprocess(chapterVariablesData[chapterVariablesText])
    else
        chapterVariablesResult = chapterVariablesData[chapterVariablesText]
    end
    
    -- Special case for CDDH chapters
    if string.find(chapterVariablesText, "CDDH Chapter") then
        local chapterNumber = string.match(chapterVariablesText, "%d+")
        if chapterNumber and chapterNumber ~= "16" then
            chapterVariablesResult = "Chapter " .. chapterNumber
        end
    end
    
    return chapterVariablesResult or chapterVariablesText or ""
end

return p