Game of Thrones: Ascent Wiki
Advertisement

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

--<pre>
-- http://dev.wikia.com/wiki/Lua_templating/Reference_manual/Scribunto_libraries
-- http://dev.wikia.com/wiki/Lua_reference_manual/Standard_libraries
local base = _G
local util = base.require("Dev:Utility") -- http://dev.wikia.com/wiki/Module:Utility
local table = base.require("table")
local string = base.require("string")

local p = {}

--- Renders the header
function p.header(frame)
    local args = util.getArgs(frame)
    return frame:expandTemplate{title = "Quest", args = args}
end

--- Renders the character list
function p.characters(frame)
    local args = util.getArgs(frame)
    
    local out = {}
    table.insert(out, "==Characters==\n")
    
    local i = 1
    while args[i] do
        table.insert(out, "* " .. args[i] .. "\n")
        i = i + 1
    end
    
    return table.concat(out)
end

--- Renders a single option
function p.option(frame)
    local args = util.getArgs(frame)
    return frame:expandTemplate{title = "Quest/option", args = args}
end

--- Renders the options
-- Arguments have the format "index:argument", with index starting at 1
function p.options(frame)
    local args = util.getArgs(frame)
    local options = {}
    
    for k, value in base.pairs(args) do
        local i, name = string.match(k, "^(%d+):(.*)$")
        if i ~= nil and name ~= nil then
            i = base.tonumber(i)
            if options[i] == nil then
                options[i] = {}
            end
            
            options[i][name] = value
        end
    end

    local out = {}
    table.insert(out, "==Options==\n")
    for i, args in base.ipairs(options) do
        local txt = frame:expandTemplate{title = "Quest/option", args = args}
        table.insert(out, txt)
    end
    
    return table.concat(out, "\n\n")
end

function p.test(frame)
    return '<pre>' .. base.require("Dev:Inspect").inspect(util.getArgs(frame)) .. '</pre>'
end

return p
--</pre>
-- [[Category:Lua modules]]
Advertisement