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

Module:Sandbox/公的驱逐舰/Akcharinfo

贴贴♀百科,万娘皆可贴的百科全书!转载请标注来源页面的网页链接,并声明引自贴贴百科。内容不可商用。
跳到导航 跳到搜索
Template-info.svg 模块文档  [创建] [刷新]
-- This is the mw.HTML version of M:Akcharinfo.
-- Crappy code originally by U:公的驱逐舰 (One-Six) of Moegirlpedia.
-- Gotta praise the Crocc. 
local p = {}

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

local function isEmpty( s )
	return (s == nil or s == '')
end

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

-- F: get arguments, alias-aware. Aliases towards the front of the array have priority.
local function getArgFromAlias ( args, argsAliasArray, defaultReturn )
	for i = 1, #argsAliasArray do
		if ( args[argsAliasArray[i]] ~= nil ) then
			return args[argsAliasArray[i]]
		end
	end
	return defaultReturn
end

local function getNonEmptyArgs ( args, argsAliasArray, defaultReturn )
	for i = 1, #argsAliasArray do
		if ( not isEmpty ( args[argsAliasArray[i]] ) ) then
			return args[argsAliasArray[i]]
		end
	end
	return defaultReturn
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 d = {
		name	= getArgFromAlias ( args, {"name", "干员名", "1", 1} ),
		elv 	= ( tonumber ( getArgFromAlias ( args, {"elite-lv", "精英等级", "elite", "精英", "2", 2} ) ) or 0 ),
		skill	= getNonEmptyArgs ( args, {"skill", "技能", "3", 3}, '无技能' ),
		sklv	= ( tonumber ( getArgFromAlias ( args, {"skill-lv", "技能等级", "sklv", "4", 4} ) ) or 0 ),
		oplv	= ( tonumber ( getArgFromAlias ( args, {"level", "干员等级", "lv", "等级", "5", 5} ) ) or 1 ),
		pot 	= ( tonumber ( getArgFromAlias ( args, {"potential", "潜能", "pot", "6", 6} ) ) or 0 ),
		support = ( string.lower( getArgFromAlias ( args, {"support", "支援", "7", 7} ) or '' ) == 'true' ),
		width	= ( tonumber ( getArgFromAlias ( args, {"width", "size", "8", 8} ) ) or 100 ),
		skin	= getArgFromAlias ( args, {"skin", "皮肤", "9", 9} )
	}
	
	local html = mw.html.create('div')	-- parent div
		:css({
			width	= d.width..'px', 
			height	= (d.width*1.2)..'px',
			position= 'relative',
			display	= 'inline-block'
		})
		:newline()
		:tag('div')						-- primary background
			:css({
				position	= 'absolute',
				top			= '0px',
				left		= '0px',
				width		= d.width..'px',
				height		= d.width..'px',
				background	= 'linear-gradient(to right,'..(d.support and '#c81, #543' or '#555, #333')..')'
			})
		:done()
		:newline()
		:tag('div')						-- avatar
			:css({
				position= 'absolute',
				top		= '0px',
				left	= '0px'
			})
			:wikitext( table.concat({
				'[[File:明日方舟_tx_',
				d.name,
				( isEmpty( d.skin ) and ( d.elv == 2 and '_2' or '' ) or ('_'..d.skin) ),
				'.png|',
				d.name,
				'头像|',
				roundToString(d.width, 0),
				'px|link=明日方舟:',
				d.name,
				']]'
			}) )
		:done()
		:newline()
		:tag('div')						-- bottom gradient
			:css({
				position	= 'absolute',
				top			= (d.width*0.7)..'px',
				left		= '0px',
				width		= d.width..'px',
				height		= (d.width*0.5)..'px',
				background	= 'linear-gradient(to bottom, transparent, rgba(0,0,0,.8) 60%, black 60%)'
			})
		:done()
		:newline()
		:tag('div')						-- skill icon
			:css({
				position	= 'absolute',
				bottom		= (d.width*0.05)..'px',
				left		= (d.width*0.05)..'px'
			})
			:wikitext( table.concat({
				'[[File:明日方舟技能_',
				d.skill,
				'.png|技能图标-',
				d.skill,
				'|',
				roundToString(d.width*0.25, 0),
				'px|link=]]'
			}) )
		:done()
		:newline()
		:tag('div')						-- elite level icon
			:css({
				position	= 'absolute',
				bottom		= (d.width*0.05)..'px',
				left		= (d.width*0.33)..'px'
			})
			:wikitext( table.concat({
				'[[File:精英',
				( d.elv == 0 and '1' or ( d.elv == 1 and '1+' or d.elv ) ),
				'_图标.png|精英等级',
				d.elv,
				'|',
				roundToString(d.width*0.2, 0),
				'px|link=]]'
			}) )
		:done()
		:newline()
		:tag('div')						-- level indicator
			:css({
				position		= 'absolute',
				top			= (d.width*0.965)..'px',
				left			= (d.width*0.635)..'px',
				width			= 'max-content',
				['font-weight']	= 'bold',
				color			= '#ccc',
				['font-size']	= '30px',
				transform		= 'translate(-50%,-50%) scale('..(d.width*0.002)..')'
			})
			:wikitext('L V')
		:done()
		:newline()
		:tag('div')						-- level number
			:css({
				position		= 'absolute',
				bottom			= '0',
				left			= (d.width*0.53)..'px',
				width			= (d.width*0.2 )..'px',
				['text-align']	= 'center',
				['font-weight']	= 'bold',
				color			= '#fff',
				['font-size']	= (d.width*0.16)..'px'
			})
			:wikitext(d.oplv)
		:done()
		:newline()
		
	local smallTextRefererWidth = d.width < 100 and 12 or d.width*0.12
	if ( d.sklv >= 1 and d.sklv <= 7 ) then
		html
			:tag('div')
				:css({
					position		= 'absolute',
					bottom			= (d.width*0.24)..'px',
					left			= '0',
					width			= smallTextRefererWidth..'px',
					height			= smallTextRefererWidth..'px',
					background		= '#333',
					color			= '#fff',
					['font-size']	= (smallTextRefererWidth*0.5833)..'px',
					['text-align']	= 'center',
					['font-weight']	= 'bold',
					['line-height']	= smallTextRefererWidth..'px'
				})
				:wikitext(d.sklv)
			:done()
			:newline()
	elseif ( d.sklv >= 8 and d.sklv <= 10 ) then
		html
			:tag('div')
				:css({
					position		= 'absolute',
					bottom			= (d.width*0.24)..'px',
					left			= '0',
					width			= smallTextRefererWidth..'px',
					height			= smallTextRefererWidth..'px',
					overflow		= 'hidden'
				})
				:tag('img')
					:css({
						position		= 'absolute',
						top				= '0',
						left			= ( (8-d.sklv)*smallTextRefererWidth )..'px',
						height			= smallTextRefererWidth..'px',
						overflow		= 'hidden'
					})
					:attr( 'src', 'https://img.moegirl.org.cn/common/2/23/AkSkillMasterDots.svg' )
					:done()
				:tag('div'):css({display='none'}):wikitext('[[File:AkSkillMasterDots.svg]]')
				:done()
			:done()
			:newline()
	--else error('illegal skill level - 技能等级不合法;expected integer between 1 and 10, got'..(d.sklv or 'nil'))
	end
	smallTextRefererWidth = nil
	
	local legalPot = ( d.pot >= 1 and d.pot <= 5 )
	if ( legalPot ) then
			html
			:tag('div')
				:css({
					position	= 'absolute',
					bottom		= (d.width*0.05)..'px',
					right		= (d.width*0.25)..'px',
					width		= (d.width*0.01)..'px',
					height		= (d.width*0.2)..'px',
					background	= 'linear-gradient(to bottom, transparent, white 50%, rgba(255,255,255,.8))'
				})
			:done()
			:newline()
	end
	html
		:tag('div')
			:css({
				position= 'absolute',
				bottom	= (d.width*0.05)..'px',
				right	= (d.width*0.03)..'px',
			})
			:wikitext( ( legalPot and table.concat ({
				'[[File:明日方舟潜能_',
				d.pot,
				'.png|潜能',
				d.pot,
				'|',
				roundToString(d.width*0.2, 0),
				'px|link=]]'
			}) or '' ) )
		:allDone()
	return tostring ( html )
end

return p