FANDOM


--[[
CHARACTER
Functions that accepts requests, asks model to get data,
and passes it to templates for rendering.
In an MVC setup, this is the "Controller" concept.
By: dragonjet
]]--
 
local getArgs = require('Module:GetArgs')
local CharacterData = require('Module:CharacterData')
local Character = {}
 
function Character:data(frame)
    local args = getArgs{ frame = frame }
    local characterObj = CharacterData:get(args[1], args[2])
    local merged = mw.clone(characterObj.info)
    if characterObj.stats then
        for k,v in pairs(characterObj.stats) do merged[k] = v end
    end
    if characterObj.wiki then
        for k,v in pairs(characterObj.wiki) do merged[k] = v end
    end
    merged.cg_file = characterObj.cg.default.file
    merged.cg_caption = characterObj.cg.default.caption
    return merged
end
 
function Character.list(frame)
    return "'''Renderer function for list not yet implemented. See [[Module:Character]].'''"
end
 
function Character.table(frame)
    return "'''Renderer function for table not yet implemented. See [[Module:Character]].'''"
end
 
function Character.infobox(frame)
    return frame:expandTemplate{
        title = "CharacterInfobox",
        args = Character:data(frame)
    }
end
 
function Character.statsbox(frame)
    return frame:expandTemplate{
        title = "CharacterStatsbox",
        args = Character:data(frame)
    }
end
 
function Character.badge(frame)
    return frame:expandTemplate{
        title = "CharacterBadge",
        args = Character:data(frame)
    }
end
 
function Character.image(frame)
    return Character:data(frame).cg_file
end
 
return Character