置顶公告:【置顶】关于临时开启评论区所有功能的公告(2022.10.22) | 【置顶】关于本站Widget恢复使用的公告
  • 你好~!欢迎来到萌娘百科镜像站!如需查看或编辑,请联系本站管理员注册账号。
  • 本镜像站和其他萌娘百科的镜像站无关,请注意分别。

Module:Akcharinfo

贴贴♀百科,万娘皆可贴的百科全书!转载请标注来源页面的网页链接,并声明引自贴贴百科。内容不可商用。
跳到导航 跳到搜索
Template-info.svg 模块文档  [查看] [编辑] [历史] [刷新]

本模块用来整理实现Template:Akcharinfo;请参考该模板的文档。

-- This is to to make T:Akcharinfo slightly less dirty.
-- Crappy code originally by U:公的驱逐舰(One-Six) of Moegirlpedia.
-- Gotta praise the Crocc. 
local p = {}

-- 使函数从全局变量变成upvalue,加快速度
local ipairs = ipairs
local tonumber = tonumber
local format = string.format

local getArgs = require('Module:Arguments').getArgs
local disam = require('Module:Akdisam').disam

local function roundToString(num, numDecimalPlaces)
  return format("%."..(numDecimalPlaces or 0).."f", num)
end


--- get arguments, alias-aware. Aliases towards the front of the array have priority.
-- @param args table[string | number, string] 参数表
-- @param aliasArray table[string] 参数别名表
-- @param denyEmptyString boolean 是否将空字符串当作nil
local function getArgFromAlias(args, aliasArray, denyEmptyString)
	for _, argsAlias in ipairs(aliasArray) do
		local arg = args[argsAlias]
		if arg and not (denyEmptyString and arg == '') then
			return arg
		end
	end
	return nil
end


function p.main(frame)
	local args = getArgs(frame, {wrappers = {"Template:沙盒", "Template:Akcharinfo"}})
	return p._main(frame, args)
end


function p._main(frame, args)
	local name = getArgFromAlias(args, {"name", "干员名", "1", 1})
	assert(name, "干员名不能为空")
	local elv = tonumber(getArgFromAlias(args, {"elite-lv", "精英等级", "elite", "精英", "2", 2})) or 0
	local skill = getArgFromAlias(args, {"skill", "技能", "3", 3}, true) or "无技能"
	local sklv = tonumber(getArgFromAlias(args, {"skill-lv", "技能等级", "sklv", "4", 4})) or 0
	local oplv = tonumber(getArgFromAlias(args, {"level", "干员等级", "lv", "等级", "5", 5})) or 1
	local pot = tonumber(getArgFromAlias(args, {"potential", "潜能", "pot", "6", 6})) or 0
	local support = string.lower(getArgFromAlias(args, {"support", "支援", "7", 7}) or "") == "true" and true or false
	local width = tonumber(getArgFromAlias(args, {"width", "size", "8", 8})) or 100
	local skin = getArgFromAlias(args, {"skin", "皮肤", "9", 9}, true)
	
	local output = {}
	local n = 0  -- 缓存 output 长度,避免频繁调用 #output

	--- 将所有参数加入 output 表中
	-- @param ... string | number
	local function append(...)
		local elems = {...}
		for i, v in ipairs(elems) do
			output[n + i] = v
		end
		n = n + #elems
	end

	append('<div style="width:', width, 'px;height:', width * 1.2, 'px;position:relative;display:inline-block">')

	-- 头像背景
	append(
		'<span style="',
			'position:absolute;top:0;left:0;',
			'width:', width, 'px;',
			'height:', width, 'px;',
			'background:linear-gradient(to right,', support and '#c81, #543' or '#555, #333',')',
		'"></span>'
	)
	-- 头像图片
	local avatarFileNameSuffix = ''
	if skin then
		avatarFileNameSuffix = '_'..skin
	elseif elv == 2 then
		avatarFileNameSuffix = '_2'
	end
	append(
		'<span style="position:absolute;top:0;left:0">',
			'[[File:明日方舟 tx ', name, avatarFileNameSuffix, '.png|',
			roundToString(width, 0), 'px|link=', disam(name), ']]',
		'</span>'
	)

	-- 信息背景
	append(
		'<span style="',
			'position:absolute;top:', width * 0.7, 'px;left:0;width:', width, 'px;height:', width * 0.5,
			'px;background:linear-gradient(to bottom, transparent, rgba(0,0,0,.8) 60%, black 60%)',
		'"></span>'
	)

	-- 技能图标
	append(
		'<span style="position:absolute;bottom:', width * 0.05, 'px;left:', width * 0.05, 'px">',
			'[[File:明日方舟技能 ', skill, '.png|', roundToString(width * 0.25, 0), 'px|link=]]',
		'</span>'
	)

	-- 精英等级
	local fileNameElv = ({[0] = '1', [1] = '1+', [2] = '2'})[elv] or ''
	append(
		'<span style="position:absolute;bottom:', width * 0.05, 'px;left:', width * 0.33, 'px">',
			'[[File:精英', fileNameElv, '_图标.png|', roundToString(width * 0.2, 0), 'px|link=]]',
		'</span>'
	)

	-- 干员等级
	append(
		'<span style="',
			'position:absolute;top:', width * 0.965, 'px;left:', width * 0.635,
			'px;width:max-content;font-weight:bold;color:#ccc;font-size:30px;transform:translate(-50%,-50%) scale(',
			width * 0.002,
			')',
		'">L V</span>'
	)
	append(
		'<span style="position:absolute;bottom:0;left:', width * 0.53, 'px;width:', width * 0.2,
		'px;text-align:center;vertical-align:bottom;color:white;font-size:', width * 0.16, 'px">', oplv, '</span>'
	)

	-- 技能等级
	local smallTextRefererWidth = width >= 100 and width or 100
	if sklv >= 1 and sklv <= 7 then
		append(
			'<span style="position:absolute;bottom:', width * 0.24, 'px;left:0;width:', smallTextRefererWidth * 0.12,
			'px;height:', smallTextRefererWidth * 0.12, 'px;background:#333;color:white;font-size:',
			smallTextRefererWidth * 0.07, 'px;text-align:center;line-height:', smallTextRefererWidth * 0.12,
			'px;font-weight:bold;">', sklv, '</span>'
		)
	elseif sklv >= 8 and sklv <= 10 then
		append(
			'<div style="position:absolute;bottom:', width * 0.24, 'px;left:0;width:', smallTextRefererWidth * 0.12,
			'px;height:', smallTextRefererWidth * 0.12, 'px;overflow:hidden;">',
			'<img style="position:absolute;height:', smallTextRefererWidth * 0.12, 'px;top:0;left:',
			(8 - sklv) * 0.12 * smallTextRefererWidth, 'px;" src="',
			frame:callParserFunction("filepath:AkSkillMasterDots.svg", {}),
			'"><div style="display:none;">[[File:AkSkillMasterDots.svg]]</div></div>'
		)
	end

	-- 潜能
	if pot >= 1 and pot <= 5 then
		append(
			'<span style="',
				'position:absolute;bottom:', width * 0.05, 'px;right:', width * 0.25, 'px;width:', width * 0.01,
				'px;height:', width * 0.2,
				'px;background:linear-gradient(to bottom, transparent, white 50%, rgba(255,255,255,.8)',
			'"></span>'
		)
	end
	append('<span style="position:absolute;bottom:', width * 0.05, 'px;right:', width * 0.03, 'px">')
	if pot >= 1 and pot <= 5 then
		append('[[File:明日方舟潜能_', pot, '.png|', roundToString(width * 0.2, 0), 'px|link=]]')
	end
	append('</span>')

	append('</div>')

	return table.concat(output)
end


return p