欢迎大家来到沙石镇时光中文维基!本站编辑权限开放,欢迎加入中文维基 QQ 群「沙海时光」:372816689
目前正在进行全站数据更新,期间可能会存在显示异常的问题。

全站通知:

模块:MailTemplateData

来自沙石镇时光维基
跳到导航 跳到搜索

此模块的文档可以在模块:MailTemplateData/doc创建

local Helper = require("Module:Helper")
local ItemHelper = require("Module:ItemHelper")
local ItemPrototype = Helper.LazyLoad("Module:AssetItemPrototypeItem")
local Text = Helper.LoadAsset("Module:AssetItemChinese")
local MailTemplateDatas = Helper.LazyLoad("Module:AssetMailTemplateDatas")

local p = {}

p.mail = function(frame)
    local mailId = frame.args[1]

    if (mailId) then
        local mailTemplateData = MailTemplateDatas[tonumber(mailId)]

        if (mailTemplateData) then
            local a = {
                type = "mission",
                title = p.getText(mailTemplateData.title),
                from = p.getText(mailTemplateData.sender),
                content = "",
                attachment = ""
            }

            for _, c in pairs(mailTemplateData.content) do
                a.content = a.content .. (p.getText(c):gsub("^%s*(.-)%s*$", "%1")) .. "<br>"
            end

            a.content = string.gsub(a.content, "<color=#(%w+)>(.-)</color>", "<span style=\"color: #%1;\">%2</span>")
            a.content = string.gsub(a.content, "%[Player%<Name%]", "Player")

            if (a.from) then
                a.content = a.content .. "<div class='text-end py-1 my-1'>" .. a.from .. "</div>"
            else
            end

            if (mailTemplateData.attachData) then
                for _, attachData in pairs(mailTemplateData.attachData) do
                    if (attachData.type == "Money") then
                        a.attachment = a.attachment .. Helper.ExpandTemplate("I2", {
                            [1] = "金币",
                            [2] = attachData.data.id
                        })
                    elseif (attachData.type == "Item") then
                        local itemPrototype = ItemPrototype[attachData.data.id]

                        if (itemPrototype) then
                            local itemPrototypeName = ItemHelper.getName(attachData.data.id)

                            if (itemPrototypeName) then
                                a.attachment = a.attachment .. Helper.ExpandTemplate("I2", {
                                    [1] = itemPrototypeName,
                                    [2] = attachData.data.count
                                })
                            else
                            end
                        else
                        end
                    else
                        error("attachData.type: " .. attachData.type .. " is unhandled.")
                    end
                end
            else
            end

            return mw.getCurrentFrame():preprocess("<span id='mailTemplateData" .. mailId .. "'>"
                                                       .. Helper.ExpandTemplate("Letter", a) .. "</span>")
        else
        end
    else
    end
end

p.getText = function(id)
    if (Text[id]) then
        return Text[id]
    end
end

p.debug = function()
    mw.log(p.mail({
        args = {
            "565"
        }
    }))
end

return p