Module:Inventory slot: Difference between revisions

m
Attempt at an inventory slot module, I hate Lua
imported>Ttv pedro270707
m (Added parseString function to take a string and treat it to generate the item with a name)
imported>Ttv pedro270707
m (Attempt at an inventory slot module, I hate Lua)
Line 2: Line 2:


function p.createSlot( f )
function p.createSlot( f )
local args = require( "Module:ProcessArgs" ).merge
local args = f
local width = args.width or "32px"
if f == mw.getCurrentFrame() then
local height = args.height or "32px"
args = require( 'Module:ProcessArgs' ).merge( true )
else
f = mw.getCurrentFrame()
end
local sprite = require( "Module:Sprite" ).get
local ids = mw.loadData( "Module:InvSprite" ).ids
local width = args.width or 32
local height = args.height or 32
local item = args.item
local item = args.item
local link = args.link
local link = args.link
local pageName = mw.title.getCurrentTitle().text
local pageName = mw.title.getCurrentTitle().text
if item ~= nil then
local slotContainerCss = {
mw.getCurrentFrame()
"width: " .. width .. "px",
"height: " .. height .. "px",
"position: relative"
}
local slotContainer = mw.html.create( "div" )
slotContainer:addClass( "inventory-slot" )
:cssText( table.concat( slotContainerCss, ";" ) )
local slotCss = {
"width: 32px",
"height: 32px",
"position: relative"
}
for i, value in ipairs(p.parseString( args.item )) do
local display = i == 1 and "display: inline-block" or "display: none"
local name = value.name
local item = value.item
local slot = mw.html.create( "div" )
slot:addClass( "minecraft-item" )
:cssText( table.concat( slotCss, ";" ) .. ";" .. display )
:attr( "data-mctitle", name )
slot:wikitext( sprite( { data = "InvSprite", id = ids[item] } ) )
slotContainer:node( slot )
end
end
local slot = mw.html.create( "div" )
slot:css( "display", "inline-block" )
:css( "width", "32px" )
:css( "height", "32px" )
:css( "position", "relative" )
local slotContainer = mw.html.create( "div" )
slot:addClass( "inventory-slot" )
:addClass( "minecraft-item" )
:css( "position", "relative" )
:css( "width", width )
:css( "height", height )
:node( slot )
return slotContainer
return slotContainer