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

local getArgs = require("Dev:Arguments").getArgs
local html = mw.html
 
local p = {}
 
local BLADE = require "Module:BladeEngine".new(p, "Module:FFRK Data")

function japanese(args)
    return require "Module:Japanese".initJ(args)
end
 
function foot(args)
    return require "Module:Foot".render(args)
end

function plusminus(num)
    if num == 0 then return "±0" end
    if num < 0 then return tostring(num) end
    return "+" .. num
end
 
 function p.Translations(frame)
    local args = getArgs(frame)
 
    local datapage = "Module:FFRK Data/" .. args[1]
 
    args[1] = args[2]
 
    local data = mw.loadData(datapage)
 
    local fields = { "name", "jpn", "rom", "lit", "category" }
 
    local querydata = BLADE.select(data, args, fields)
 
    local tbl = html.create("table")
        :addClass("FFRK full-width article-table translations")
    local thead = tbl:tag("tr")
        :addClass("a")
        :tag("th"):wikitext("Japanese"):css("width", "25%"):done()
        :tag("th"):wikitext("''Rōmaji''"):css("width", "25%"):done()
        :tag("th"):wikitext("''Lit.''"):css("width", "25%"):done()
        :tag("th"):wikitext("English"):css("width", "25%"):done()
 
    for i=1, #querydata do
        local entry = querydata[i]
 
        local tr = tbl:tag("tr"):attr("id", entry.jpn or "")
        :tag("td"):wikitext(entry.jpn or ""):addClass("b"):done()
        :tag("td"):wikitext(entry.rom or ""):done()
        :tag("td"):wikitext(entry.lit or ""):done()
        :tag("td"):wikitext(entry.name or ""):addClass("b"):done()
    end
 
    return html.create("div"):node(BLADE.dnav(datapage)):node(tbl)
end

function p.Weapons(frame)
    local datapage = "Module:FFRK Data/Weapons"
    local data = mw.loadData(datapage)
    args = getArgs(frame)
 
    local parameters = { "name", "jpn", "rom", "lit", "link", "category", "rarity", "game", "image",
        "lvl1", "lvl2", "lvl3", "lvl4",
        "atk1", "atk2", "atk3", "atk4",
        "mag1", "mag2", "mag3", "mag4",
        "mnd1", "mnd2", "mnd3", "mnd4",
        "def", "res", "acc", "eva",
        "eqbonus", "rsbonus", "sb", "sbtype", "sbm", "reward", "default"
    }

    local querydata = BLADE.select(data, args, parameters)
    
    local displaycategory = (not args.displaycategory) or args.displaycategory ~= "false"
    
    local tbl = html.create("table")
        :addClass("FFRK full-width article-table")
        
    local thead = tbl:tag("tr")
        :addClass("a")
        
    local namewidth = "20%"
    local otherwidth = (80/(displaycategory and 5 or 4)) .. "%"
        
    thead:tag("th"):wikitext("Weapon"):css("width", namewidth)
    if displaycategory then
        thead:tag("th"):wikitext("Category"):css("width", otherwidth)
    end
    thead:tag("th"):wikitext("Level"):css("width", otherwidth)
    thead:tag("th"):wikitext("Attack"):css("width", otherwidth)
    thead:tag("th"):wikitext("Magic"):css("width", otherwidth)
    thead:tag("th"):wikitext("Mind"):css("width", otherwidth)
    
    for i=1, #querydata do
        local itm = querydata[i]

        local name = BLADE.formatlink(data, itm, "link", "name")
 
        if itm.lit and itm.lit ~= itm.name then
            name = name .. "<br/>(" .. BLADE.formataltjpnname(data, itm, "jpn", "rom", "lit") .. ")"
        end
        
        if itm.image then
            name = name .. '<br/>' .. BLADE.formatfield(data, itm, "image"):setWidth(112):setAlt("Rarity " .. itm.rarity)
        end
        
        local additionalinfo = {}
        local additionalstats = {}
        if itm.def ~=0 then
            table.insert(additionalstats, "Defense "
                .. BLADE.formatfield(data, itm, "def"))
        end
        if itm.res ~=0 then
            table.insert(additionalstats, "Resistance "
                .. BLADE.formatfield(data, itm, "res"))
        end
        if itm.acc ~=0 then
            table.insert(additionalstats, "Accuracy "
                .. BLADE.formatfield(data, itm, "acc"))
        end
        if itm.eva ~=0 then
            table.insert(additionalstats, "Evasion "
                .. BLADE.formatfield(data, itm, "eva"))
        end
        if additionalstats[1] then
            table.insert(additionalinfo,
                "'''Additional stats:''' "
                .. table.concat(additionalstats, ", ")
            )
        end
        if itm.eqbonus then
            table.insert(additionalinfo,
                "'''Bonus effects when equipped:''' " .. itm.eqbonus
            )
        end
        if itm.rsbonus then
            table.insert(additionalinfo,
                "'''Bonus effects with Synergy:''' " .. itm.rsbonus
            )
        end
        if itm.sb then
            local sbtype = "Soul Break"
            if itm.sbtype then
                sbtype = itm.sbtype .. " " .. sbtype
            end
            local soulbreak = "'''".. sbtype .. ":''' " .. itm.sb
            if itm.sbm then
                soulbreak = soulbreak .. ", " .. itm.sbm .. " when mastered"
            end
            table.insert(additionalinfo, soulbreak)
        end
        
        local catrowspan = 4
        local rowspan = catrowspan + (additionalinfo[1] and 1 or 0)
        local colspan = 4 + (displaycategory and 1 or 0)
        
        local tr = tbl:tag("tr"):attr("id", itm.name)
        tr:tag("th"):addClass("b"):wikitext(name)
            :attr("rowspan", rowspan)
        if displaycategory then
            tr:tag("td"):wikitext(itm.category):css("text-align", "center")
            :attr("rowspan", catrowspan)
        end
        
        tr:tag("td"):wikitext(itm.lvl1):css("text-align", "center")
        tr:tag("td"):wikitext(itm.atk1):css("text-align", "center")
        tr:tag("td"):wikitext(itm.mag1):css("text-align", "center")
        tr:tag("td"):wikitext(itm.mnd1):css("text-align", "center")

        local tr = tbl:tag("tr")
        tr:tag("td"):wikitext(itm.lvl2):css("text-align", "center")
        tr:tag("td"):wikitext(itm.atk2):css("text-align", "center")
        tr:tag("td"):wikitext(itm.mag2):css("text-align", "center")
        tr:tag("td"):wikitext(itm.mnd2):css("text-align", "center")

        local tr = tbl:tag("tr")
        tr:tag("td"):wikitext(itm.lvl3):css("text-align", "center")
        tr:tag("td"):wikitext(itm.atk3):css("text-align", "center")
        tr:tag("td"):wikitext(itm.mag3):css("text-align", "center")
        tr:tag("td"):wikitext(itm.mnd3):css("text-align", "center")

        local tr = tbl:tag("tr")
        tr:tag("td"):wikitext(itm.lvl4):css("text-align", "center")
        tr:tag("td"):wikitext(itm.atk4):css("text-align", "center")
        tr:tag("td"):wikitext(itm.mag4):css("text-align", "center")
        tr:tag("td"):wikitext(itm.mnd4):css("text-align", "center")

        if additionalinfo[1] then
            local tr = tbl:tag("tr")
            tr:tag("td")
                :wikitext(table.concat(additionalinfo, "<br/>"))
                :attr("colspan", colspan)
        end
    end

    return html.create("div"):node(BLADE.dnav(data, datapage)):node(tbl)

end

function p.BurstModeAbilities(frame)
    local datapage = "Module:FFRK Data/BurstModeAbilities"
    local data = mw.loadData(datapage)
    args = getArgs(frame)
 
    local querydata = BLADE.select(data, args)
    
    local displaybmo = (not args.displayburstmode) or args.displayburstmode ~= "false"
    
    local tbl = html.create("table")
        :addClass("FFRK full-width article-table")
        
    local thead = tbl:tag("tr")
        :addClass("a")
        
    local namewidth = 20
    local replacewidth = 30
    local bmowidth = 0
    if displaybmo then
        replacewidth = replacewidth/2
        bmowidth = replacewidth
    end
    local traitswidth = (100-namewidth-replacewidth-bmowidth)

    thead:tag("th")
        :wikitext(BLADE.fieldtitle(data, "name"))
        :css("width", namewidth .. "%")
    if displaybmo then
        thead:tag("th")
            :wikitext("Burst Mode")
            :css("width", bmowidth .. "%")
    end
    thead:tag("th")
        :wikitext(BLADE.fieldtitle(data, "replace"))
        :css("width", replacewidth .. "%")
    thead:tag("th")
        :wikitext("Traits")
        :css("width", traitswidth .. "%")

    for i=1, #querydata do
        local itm = querydata[i]

        local name = BLADE.formatlink(data, itm, "link", "name")
 
        if itm.lit and itm.lit ~= itm.name then
            name = name .. "<br/>(" .. BLADE.formataltjpnname(data, itm, "jpn", "rom", "lit") .. ")"
        end

        if itm.image then
            name = name .. '<br/>' .. BLADE.formatfield(data, itm, "image"):setWidth(75)
        end
        
        local replace = BLADE.formatfield(data, itm, "replace")

        local bmo
        
        local colspan = 1
        
        if displaybmo then 
            local user = BLADE.formatfield(data, itm, "user")
            bmo = BLADE.formatfield(data, itm, "bmo")
            if user then bmo = user .. ": " .. bmo end
            colspan = colspan + 1
        end

        local description = BLADE.formatfield(data, itm, "description")
        
        local traitfields = {"school", "chargetime", "target", "autotarget", "dmgformula", "type", "hits", "potency", "elements", "healing", "sgcharge", "allystatuses", "enemystatuses", "notes"}
        
        local traitfuncs = {
            potency = function(data, itm)
                local ptn = BLADE.formatfield(data, itm, "potency")
                local hit = itm.hits
                local ttl = BLADE.format(hit*itm.potency, "number", "percent")
                return ptn .. (ptn~=ttl and (" (Total: " .. ttl .. ")") or "")
            end,
            chargetime = function(data, itm)
                return BLADE.formatfield(data, itm, "chargetime") .. "s"
            end
        }
        
        local traits = {}
        for j=1, #traitfields do
            local thistrait = traitfields[j]
            if itm[thistrait] then
                local value
                if traitfuncs[thistrait] then
                    value = traitfuncs[thistrait](data, itm)
                else
                    value = BLADE.formatfield(data, itm, thistrait)
                end
                table.insert(traits,
                    BLADE.fieldtitle(data, thistrait) .. ": " .. value
                )
            end
        end

        local tr = tbl:tag("tr"):attr("id", itm.name)
        tr:tag("th")
            :addClass("b")
            :wikitext(name)
            :attr("rowspan", 2)
        if displaybmo then
            tr:tag("td")
                :wikitext(bmo)
                :css("text-align", "center")
                :attr(BLADE.cellformatfield(data, "bmo"))
        end
        tr:tag("td")
            :wikitext(replace)
            :attr(BLADE.cellformatfield(data, "replace"))
        tr:tag("td")
            :wikitext(table.concat(traits, "<br/>"))
            :attr("rowspan", 2)
        local tr = tbl:tag("tr")
        tr:tag("td")
            :attr("colspan", colspan)
            :wikitext(description)
            :attr(BLADE.cellformatfield(data, "description"))
    end

    return html.create("div"):node(BLADE.dnav(data, datapage)):node(tbl)
    
end

return p
Community content is available under CC-BY-SA unless otherwise noted.