2023年政策修订增补工作正在进行中,欢迎参与!
Module:Sandbox/公的驱逐舰/Akitem
跳转到导航
跳转到搜索
-- This is a reimplementation of T:Akitem
-- that also cuts out Akmat, Akskin, Akcon, and Akfur.
-- Everything is doable through one module, nice!
-- Crappy code originally by U:公的驱逐舰 (One-Six) of Moegirlpedia.
-- Gotta praise the Crocc.
local getArgs = require('Module:Arguments').getArgs
local wrapperArray = { 'Template:Akitem', 'Template:Akmat', 'Template:Akskin', 'Template:Akcon', 'Template:Akfur', 'Template:沙盒' }
local defaults = { size = 75, unit = 'px' }
-- F: is string empty?
local function isEmpty( s )
return (s == nil or s == '')
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
-- F: same as getArgFromAlias, but will also ignore empty strings. Default return is still nil, check compatibility.
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
-- F: round using string.format, keeping string output.
function roundToString(num, numDecimalPlaces)
return string.format("%." .. (numDecimalPlaces or 0) .. "f", num)
end
local function argsPreprocess ( args )
local a = args
a.name = a.name or a[1]
a.size = tonumber(a.size) or defaults.size
a.unit = a.unit or defaults.unit
a.num = tonumber(num)
return a
end
local p = {}
-- F: a Lua implimentation of {{Akdrop}}; returns nil if freq is not legal.
-- No direct use yet so no need for a separate module; still usable in other modules via require.
function p.akdrop ( freq, size )
local sz = size or '75%'
local freqTable = {
['固定掉落'] = '.6em;background:#313131;color:#FFF',
['罕见'] = '.9em;background:#A40000;color:#FEFBFB',
['小概率'] = '.6em;background:#DDD; color:#333',
['大概率'] = '.6em;background:#707070;color:#FFF',
['概率掉落'] = '.6em;background:#7A7A7A;color:#FEFEFE',
['三星获得'] = '.6em;background:#FFCF00;color:#5B5127',
['首次掉落'] = '.6em;background:#01B3FC;color:#FFF'
}
if freqTable[freq] then
return table.concat {
[[<span style="padding:2em ]],
freqTable[freq],
[[;font-size:]],
sz,
[[;font-weight:bold;line-height:1;text-align:center;white-space:nowrap;vertical-align:baseline;border-radius:.25em;display:inline-block;">]],
freq,
[[</span>]]
}
else
return nil
end
end
function p.main ( frame )
return p._main ( getArgs( frame, { wrappers = wrapperArray } ) )
end
function p._main ( args )
local index = '_'..args:remove(1):lower()
if p.index then
return p[index] ( argsPreprocess ( args ) )
else
error ( 'Error: Akitem: the item type passed by argument 1 is not defined.' , 2 )
end
end
-- akmat.
-- expected argument: args = { name=string, [size=num, unit=str, link=str, dt=str] }
function p._mat ( args )
local numstuff = ''
if args.num then numstuff = table.concat {
'<div><span style="bottom:',
roundToString ( args.size/25, 2 ),
args.unit,
';right:',
roundToString ( args.size/25, 2 ),
args.unit,
';position:absolute;white-space:nowrap;color:black!important;text-shadow: -1px -1px 0 #FFF, 1px -1px 0 #FFF, -1px 1px 0 #FFF, 1px 1px 0 #FFF, -2px -2px 4px #FFF, 2px -2px 4px #FFF, -2px 2px 4px #FFF, 2px 2px 4px #FFF;font-weight:bold;font-size:',
roundToString ( 16*(args.size/75), 2 ),
args.unit,
';">',
args.num,
'</span></div>'
}
end
return table.concat {
'<div style="display:inline-block;position:relative">[[文件:明日方舟道具_带框_',
args.name,
".png|",
args.size,
args.unit,
'|link=明日方舟/材料#',
(args.link or args.name),
'|',
args.name,
']]',
numstuff,
'<span style="position:absolute;top:-3px;white-space:nowrap;color:black!important;font-weight:bold;font-size:small;left:50%; transform: translateX(-50%);">',
p.akdrop ( args.dt ),
'</span></div>'
}
end
return p