Jump to content

Module:Sprite: Difference between revisions

1,833 bytes added ,  28 March 2023
m
no edit summary
imported>Ttv pedro270707
m (Scuffed module update)
imported>Ttv pedro270707
mNo edit summary
Line 3: Line 3:
function p.getSpritePosition( pos, sheetsize, size )
function p.getSpritePosition( pos, sheetsize, size )
local spritesPerRow = sheetsize / size
local spritesPerRow = sheetsize / size
local row = math.floor(pos / spritesPerRow)
local row = math.floor( pos / spritesPerRow )
local col = pos % spritesPerRow
local col = pos % spritesPerRow
local x = col * size
local x = col * size
Line 72: Line 72:
end
end


function p.doc( f )
local args = f
if f == mw.getCurrentFrame() then
args = require( 'Module:ProcessArgs' ).merge( true )
else
f = mw.getCurrentFrame()
end
local data = args.data and mw.loadData( 'Module:' .. args.data ) or {}
local settings = data.settings
local ids = data.ids
local keyedData = {}
local i = 1
for name, value in pairs(ids) do
    keyedData[i] = {
        sortKey = mw.ustring.lower( name ),
        name = name,
        value = value
    }
    i = i + 1
end
-- Sort the keyed table based on the sort key
table.sort( keyedData, function( a, b )
    return a.sortKey < b.sortKey
end )
-- Create a Lua table to store the created li elements for each unique data-spritedoc-value
local liElements = {}
local nameTable = {}
local ul = mw.html.create( 'ul' ):addClass( 'spritedoc-ul' )
for key, value in ipairs( keyedData ) do
    -- Check if the li element already exists for the current data-spritedoc-value
    local li = liElements[value.value]
    local idText = mw.html.create( 'code' ):wikitext( value.name )
    local names = nameTable[value.value]
    if not names then
        -- If it doesn't exist, create a new li element and store it in the Lua table
        li = mw.html.create( 'li' ):addClass( 'spritedoc-cell' ):attr( 'data-spritedoc-value', value.value )
        liElements[value.value] = li
        ul:node( li )
       
        local image = mw.html.create( 'span' ):addClass( 'spritedoc-image' )
    image:node( p.get( {data = args.data, id = value.name} ) )
    names = mw.html.create( 'div' ):addClass( 'spritedoc-names' )
    nameTable[value.value] = names
    li:wikitext( tostring(image) .. ' ' .. tostring(names) )
    else
    li:wikitext( tostring(names) )
    end
    names:node( idText )
end
return tostring( ul )
end
return p
return p