◆少前百科是非盈利性、非官方的少女前线维基百科。
◆如果您发现某些内容错误/空缺,请勇于修正/添加!参与进来其实很容易!点这里 加入少前百科
◆有任何意见、建议、纠错,欢迎在 GFwiki:反馈与建议 提出和讨论。编辑事务讨论QQ群:597764980,微博@GFwiki少前百科
◆To foreigners,You can use twitter to contact us.
Icon Nyto Silver.png

模块:Sangvis info

来自少前百科GFwiki
罗瓦讨论 | 贡献2022年5月1日 (日) 19:17的版本
跳转至: 导航搜索

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

local p = {}
local args = {}
local root
local unitdata
local data = mw.loadData('Module:Sangvis info/data')
local infobox = require('Module:Infobox').infobox
local forces = {'铁血工造', '正规军', '帕拉蒂斯', '其他势力'}
local chartype = {'有甲', '无甲', '机械', '人形', '近战', '远程', [0] = '全体'}
local attrname = {'生命', '伤害', '攻速', '命中', '回避', '护甲',
	'穿甲', '暴击', '暴击伤害', '移速', '射程'}
local effectname = {'伤害', '攻速', '命中', '回避', '暴击率', [8] = '护甲'}
local sizes = {'微', '小', '中', '大', '巨'}

local function putAttrs()
	local div = root:tag('div')
	local attrs = ''
	for i = 1, 6 do attrs = attrs .. tostring(unitdata.attrs[i]) end
	div:attr{ id = 'attrs',
		['data-id'] = tostring(unitdata.id),
		['data-type'] = tostring(unitdata.type-1),
		['data-attrs'] = attrs,
		['data-grow'] = tostring(unitdata.grow),
		['data-resolution'] = unitdata.resolution }
	local control = div:tag('div'):attr('id', 'control')
	local affix = control:tag('div')
	if unitdata.type > 1 then
		local size = affix:tag('div')
		size:attr('id', 'size-control')
		for i = 1, 5 do
			size:tag('input'):attr{
				id = 'size' .. tostring(i),
				['type'] = 'radio',
				name = 'size',
				value = tostring(i-1)}
			size:tag('label'):attr('for', 'size' .. tostring(i)):wikitext(sizes[i])
		end
	end
	local form = affix:tag('div')
	form:attr('id', 'formation-control')
	if unitdata.id < 2000 or unitdata.id == 2006 or unitdata.id == 3010 then
		form:wikitext('×1')
	else for i = 1, 5 do
			form:tag('input'):attr{
				id = 'form' .. tostring(i),
				['type'] = 'radio',
				name = 'formation',
				value = tostring(i-1)}
			form:tag('label'):attr('for', 'form' .. tostring(i))
				:wikitext('×' .. tostring(i))
		end
	end
	local common = control:tag('div')
	common:tag('div'):attr('id', 'resolve-signal')
	common:tag('div'):attr('id', 'lv-control'):tag('input'):attr{
		id = 'lv-input',
		['type'] = 'number',
		['min'] = '1',
		['max'] = '100',
		value = '100'}
	local rank = common:tag('div'):attr('id', 'rank-control')
	for i = 1, 5 do
		rank:tag('img'):attr('id', 'star' .. tostring(i))
			:attr('src', '/images/0/0a/StarWhite.svg')
	end
	div:tag('div'):attr('id', 'resolve-control')
	local growing = div:tag('table')
	local thead1 = growing:tag('tr')
	local tbody1 = growing:tag('tr')
	for i = 1, 6 do
		thead1:tag('th'):attr('id', 'attr-th-' .. tostring(i)):wikitext(attrname[i])
		tbody1:tag('td'):attr('id', 'attr-td-' .. tostring(i))
	end
	local fixed = div:tag('table')
	local thead2 = fixed:tag('tr')
	local tbody2 = fixed:tag('tr')
	for i = 7, 11 do
		thead2:tag('th'):attr('id', 'attr-th-' .. tostring(i)):wikitext(attrname[i])
		tbody2:tag('td'):wikitext(unitdata.attrs[i])
	end
end

local function addInfobox()
	root:wikitext(infobox{
		above = unitdata.name,
		label1 = '初始星级',
		data1 = tostring(4 - unitdata.type),
		label2 = '所属势力',
		data2 = forces[unitdata.force],
		label3 = '战斗特性',
		data3 = chartype[unitdata.char[1]] .. ' ' ..
			chartype[unitdata.char[2]] .. ' ' .. chartype[unitdata.char[3]],
		label4 = '费用',
		data4 = tostring(unitdata.cost)
	})
end

local function _sangvisInfo()
	unitdata = data[tonumber(args[1])]
	if unitdata == nil then
		return '<p style="color:red">未找到编号对应的融合势力单位信息,请检查编号是否正确及' ..
			'<a href="/w/Module:Sangvis_info/data">模块:Sangvis info/data</a>的数据是否为最新。</p>'
	end
	root = mw.html.create()
	
	addInfobox()
	putAttrs()
	
	local templatestyles = mw.getCurrentFrame():extensionTag{
		name = 'templatestyles', args = { src = 'Module:Sangvis info/styles.css' }
	}
	return templatestyles .. tostring(root)
end

function p.sangvisInfo(frame)
	if frame == mw.getCurrentFrame() then
		args = frame:getParent().args
	else
		args = frame
	end
	return _sangvisInfo()
end

return p