-- 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