尚不完善,欢迎查看本站wiki待办,一起参与施工!
如有建议或想法,也欢迎加入wiki学会洽谈区QQ群:471292177~
尚不完善,欢迎查看本站wiki待办,一起参与施工!也欢迎加入wiki学会洽谈区QQ群:471292177~
全站通知:

模块:卡牌图鉴

来自苏丹的游戏WIKI_BWIKI_哔哩哔哩
跳到导航 跳到搜索

此模块的文档可以在模块:卡牌图鉴/doc创建

local p = {}
local getArgs = require("Module:Arguments").getArgs

function p.renderCard(frame)
	local args = getArgs(frame)
	local ID = args.ID or ""

	local db = require("模块:数据库")
	args.ID = ID
	db["卡牌信息"](frame)

	frame:callParserFunction{ name = '#invoke', args = { 'SMW', 'setAllArgs' } }

	local getVar = function(key, fallback)
		return frame:callParserFunction("#var", key) or fallback or ""
	end

	local name = args["名字"] or getVar("名字", "未命名")
	local galleryType = args["图鉴类别"] or "卡牌"
	local cardType = args["卡面类别"] or "物品"
	local imageName = args["图片名称"] or 0
	local showGoldText = args["金色文字"] or "0"
	local hideIdentity = args["隐藏身份"] == "1"
	local hideTags = args["隐藏标签"] == "1"
	local description = args["介绍"] or getVar("卡牌介绍") or ""
	local tags = args["标签"] or getVar("标签", "卡牌")
	local equips = getVar("装备栏") or nil
	local properties = args["属性"] or getVar("属性")
	local requirement = args["要求"] or "__未填__"
	local card_title = args["身份"]
	local rarity_raw = args["品级"] or ""

	local rarity_map = {
		["1"] = "石",
		["2"] = "铜",
		["3"] = "银",
		["4"] = "金"
	}

	if rarity_raw == "" then
		rarity_raw = getVar("品级")
	end

	local rarity = rarity_map[rarity_raw] or rarity_raw

	if not card_title or card_title == "" then
	    local identity = getVar("身份")
	    if identity and identity ~= "" then
	        card_title = "“" .. identity .. "”"
	    end
	end

	local imageHTML = ""
	if cardType == "立绘" then
		imageHTML = string.format("[[file:%s-立绘.png|center|400px]]", name)
	else
		local templateArgs = {
			name,
			rarity,
			cardType
		}
		if showGoldText ~= "0" then
			templateArgs["金色文字"] = "1"
		end

		if imageName ~= 0 then
			templateArgs["图片名称"] = imageName
        else
            local imageFrame = {args={name}}
            local fetchedImageName = db["卡面图片"](imageFrame)
            if fetchedImageName and fetchedImageName ~= "" then
                templateArgs["图片名称"] = fetchedImageName
            end
		end

		imageHTML = frame:expandTemplate{
			title = "模板:卡面图鉴/sandbox",
			args = templateArgs
		}
	end

	local expandTitle = function(id, label)
        local content = frame:expandTemplate{
            title = "图鉴栏位标题",
        args = { id = id, ["栏位标题"] = label }
        }

        content = content
        :gsub("<p>%s*</p>", "")
		:gsub("<p>%s*<br%s*/?>%s*</p>", "")
		:gsub("<br%s*/?>", "")

        return content
	end

	local html = mw.html.create("table"):addClass("card-display")
		:addClass("wikitable information")
		:cssText("width:300px; text-align:center; background: transparent; border:none;")

	html:tag("tr"):tag("td")
	:attr("colspan", 2)
	:css("border", "none")
	:wikitext(string.format([[<div class="card-artbox">
%s
<div class="hr-image">%s</div>
</div>]], imageHTML, name))

	if not hideIdentity then
		html:tag("tr"):tag("td")
		:attr("colspan", 2)
		:css("border", "none")
		:tag("div"):addClass("card-title")
		:tag("span"):wikitext(card_title)
	end

    if not hideTags then
        local listItems = ""

        if tags and tags ~= "" then
            listItems = listItems .. "<li>标签:" .. tags .. "</li>"
        end

        if equips and equips ~= "" then
            listItems = listItems .. "<li>装备栏:" .. equips .. "</li>"
        end

        local combinedWikitext =
            expandTitle(galleryType .. "标签", galleryType .. "标签") ..
            "<div align='left'><ul>" .. listItems .. "</ul></div>"

        html:tag("tr"):tag("td")
            :attr("colspan", 2)
            :css("border", "none")
            :wikitext(combinedWikitext)
    end

	html:tag("tr"):tag("td")
	:attr("colspan", 2)
	:css("border", "none")
	:wikitext(
		expandTitle(galleryType .. "介绍", galleryType .. "介绍") ..
		string.format("<div align=left>%s</div>", description)
	)

	if requirement ~= "__未填__" then
		local reqTitle = args["要求名称"] or galleryType .. "要求"
		html:tag("tr"):tag("td")
        :attr("colspan", 2)
        :css("border", "none")
        :wikitext(
			expandTitle(reqTitle, reqTitle) ..
			string.format("<div align=left>%s</div>", requirement)
        )
	end

    if properties and properties ~= "" then
        local attrTitle = args["属性名称"] or galleryType .. "属性"

        local htmlTitle = mw.html.create("div")
        :addClass("custom-headline")
        :attr("id", attrTitle)
        :wikitext(attrTitle)

        local htmlCombined = mw.html.create()
        htmlCombined:node(htmlTitle)
        htmlCombined:tag("div")
        :addClass("card-attribute")
        :wikitext(properties)

        html:tag("tr"):tag("td")
        :attr("colspan", 2)
        :css("border", "none")
        :node(htmlCombined)
    end

	local css = [[
.card-display .card-artbox {
    float:left;
    text-align: center;
    width: 300px;
    margin: 0 1em 1em 1em;
}
.card-display .card-artbox .tab-btn {
    flex: 1;
}
.card-display .card-artbox .hr-image {
    background: url('https://patchwiki.biligame.com/images/sultansgame/4/48/s1pnocs3a8vqss91yaa19yp68wwp1du.png');
    display: block;
    width: 100%;
    font-family: 汉仪杰龙桃花源;
    font-size:200%;
    color:#dccf9a;
    background-size: 100% 40px;
    margin-top: 0.2em;
}
.card-display .card-title {
    text-align: center;
    width: 100%;
    font-size:150%;
    font-family: 喜鹊古字典;
}
.card-display .card-attribute .tab-btn {
    flex: 1;
}
.card-display .card-attribute .tab-group a.image img {
    margin: 0px 0px 1px 0px !important;
    max-width: 100%;
    height: auto;
}
]]

local style = frame:extensionTag{
	name = "bstyle",
	content = [[/*<pre>*/
]] .. css .. [[
/*</pre>*/]]
}

return style .. tostring(html)
end

return p