モジュール:Slot
ナビゲーションに移動
検索に移動
このモジュールについての説明文ページを モジュール:Slot/doc に作成できます
local p = {}
function p.base( f )
local args = f
if f == mw.getCurrentFrame() then
args = require( 'Module:ProcessArgs' ).merge( true )
else
f = mw.getCurrentFrame()
end
local jsprite = require( 'Module:JSprite' )
local animate = require( 'Module:AnimateFrame' )
local div = mw.html.create("span")
div:addClass('slot')
if args['nobg'] then
div:css("background-image", "none")
end
----- generate sprite -----
local function convertSprite( slot )
if mw.text.trim(slot or '') ~= 'blank' then
if mw.ustring.match(slot, "[%w%s'(),:]+") ~= slot then
slot = mw.text.trim(slot or '')
else
local sprite = {args={}}
local sprite_other = string.find(slot, ":")
local isPotion = false -- string.find(string.lower(slot), "potion of")
if sprite_other or isPotion then
if sprite_other then
sprite.title = string.sub(slot, 1, sprite_other-1)
sprite.args[1] = string.sub(slot, sprite_other+1)
else
sprite.title="EnchantSprite"
sprite.args[1] = slot
end
if not mw.title.new("Template:" .. sprite.title).exists and mw.title.new("Template:" .. sprite.title .. "Sprite").exists then
sprite.title = sprite.title .. "Sprite"
end
slot = f:expandTemplate(sprite)
else
sprite.args[1] = slot
sprite.args.sheet = "InvSprite"
slot = jsprite.base( sprite.args )
end
end
else
slot = ''
end
return slot
end
-------------
local slot = args[1]
if slot then
if not slot:match("<.*>") and string.find(slot, ";") then
local items = mw.text.split(slot, ";")
for i, v in pairs(items) do
items[i] = convertSprite(items[i])
end
div:wikitext(
animate.base( items )
)
else
div:wikitext( convertSprite( slot ) )
end
local amount = tonumber(args["amount"]) or 1
if amount ~= 1 or args['num'] then
local sub_overlay = div:tag("span")
sub_overlay:addClass('gui-nfr')
local num_len = string.len(tostring(amount))
for j=1, num_len, 1 do
local chr = string.sub(tostring(amount), j, j)
local num = tonumber(chr) or 10
local overlay_num = sub_overlay:tag("span")
overlay_num
:addClass('sprite')
:addClass('gui-num')
:css({
["background-position"] = "-" .. tostring(num * 12) .. "px -0px",
["margin-bottom"] = "0",
["margin-right"] = "0",
})
end
end
end
return tostring(div)
end
return p