Module:SpriteTint

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 msprite = require( 'Module:Sprite/editcopy' ) local data = args.data and mw.loadData( 'Module:' .. args.data ) or {} local tdata = args.tint and mw.loadData( 'Module:' .. args.tint ) or {} local default = { scale = 1, sheetsize = 256, size = 16, pos = 1, align = 'text-top' }

local frame = mw.html.create( 'span' ):addClass( 'dyeable-frame' ) frame:cssText("display: inline-block; vertical-align: middle; position: relative;") local name = args[1] if not data.ids[name] then if not data.ids[mw.ustring.lower( name )] then name = mw.ustring.lower( name ):gsub( '[%s%+]', '-' ) else name = mw.ustring.lower( name ) end end

local base_image_name = tdata[name].base_image or name local base_mask_name = tdata[name].base_mask or (base_image_name .. "-mask") local overlay_image_name = tdata[name].overlay_image or (base_image_name .. "-overlay") local overlay_mask_name = tdata[name].overlay_mask or (overlay_image_name .. "-mask")

local icondata = data.ids[base_image_name]

local setting = function( key, icon ) return args[key] or (icon or icondata)[key] or data.settings[key] or default[key] end

local assign = function(firstTable, secondTable) local newtable = {} for k,v in pairs(firstTable) do newtable[k] = v end for k,v in pairs(secondTable) do newtable[k] = v end return newtable end

local wikitext = "" local classname = setting( 'classname' ) or mw.ustring.lower( setting( 'name' ):gsub( ' ', '-' ) ) .. '-sprite' local classname_mask = classname .. "-mask"

local main_color = args[2] or tdata[name].base_tint_color or "#FFFFFF" local sub_color = args[3] or tdata[name].overlay_tint_color or "#FFFFFF"

local width = setting( 'width' ) or setting( 'size' ) local height = setting( 'height' ) or setting( 'size' ) local scale = setting( 'scale' ) local autoScale = setting( 'autoscale' )

frame:css( 'width', width * scale .. "px" ) frame:css( 'height', height * scale .. "px" )

local mask_position = "" local textcss = "position: absolute; top: 0"

-- BASE TINT -- local sprite_setting = assign(args, {       [1] = base_image_name,        css = textcss    }) if tdata[name].base_tint then sprite_setting.css = textcss .. "; background-color:" .. main_color sprite_setting.formask = 1 end local base_image = msprite.sprite( sprite_setting ) wikitext = base_image

- BASE MASK --- if data.ids[ base_mask_name ] then local base_mask = msprite.sprite(assign(args, { [1] = base_mask_name, css = textcss }))       wikitext = wikitext .. base_mask end

if tdata[name].overlay and data.ids[ overlay_image_name ] then OVERLAY TINT -- sprite_setting = assign(args, {           [1] = overlay_image_name,            css = textcss        }) if tdata[name].overlay_tint then sprite_setting.css = textcss .. ";background-color:" .. sub_color sprite_setting.formask = 1 end local overlay_image = msprite.sprite( sprite_setting ) wikitext = wikitext .. overlay_image

OVERLAY MASK -- if data.ids[ overlay_mask_name ] then local overlay_mask = msprite.sprite(assign(args, { [1] = overlay_mask_name, css = textcss }))           wikitext = wikitext .. overlay_mask end end

frame:wikitext( wikitext ) -- Show Color Code if args['code'] then local outer = mw.html.create('span'):css('white-space', 'nowrap'):node(frame) wikitext = "" if tdata[name].base_tint then local code = mw.html.create('code'):wikitext( main_color ) wikitext = wikitext .. ' ' .. tostring(code) end if tdata[name].overlay_tint then code = mw.html.create('code'):wikitext( sub_color ) wikitext = wikitext .. ' ' .. tostring(code) end outer:wikitext( wikitext ) return tostring( outer ) end

return tostring( frame )

end

function p.doc( f ) local args = f	if f == mw.getCurrentFrame then args = f.args else f = mw.getCurrentFrame end local dataPage = mw.text.trim( args[1] ) local dataPage2 = mw.text.trim( args[2] ) local data = mw.loadData( 'Module:' .. dataPage2 ) local spriteStyle = '' local body = mw.html.create( 'div' ):attr( {		id = 'spritedoc',	} ) local sections = {} local sectionData = { name = 'Uncategorized', id = 1 } local sectionTag = body:tag( 'div' ):addClass( 'spritedoc-section' ):attr( 'data-section-id', sectionData.id ) sectionTag:tag( 'h3' ):wikitext( sectionData.name ) sections[sectionData.id] = { boxes = sectionTag:tag( 'ul' ):addClass( 'spritedoc-boxes' ) } local keyedData = {} local i = 1 for name, idData in pairs( data ) do		keyedData[i] = { sortKey = mw.ustring.lower( name ), name = name }		i = i + 1 end table.sort( keyedData, function( a, b )		return a.sortKey < b.sortKey	end ) for _, data in ipairs( keyedData ) do		local section = sections[1] local box = section.boxes:tag( 'li' ):addClass( 'spritedoc-box' ) box:tag( 'div' ):addClass( 'spritedoc-image' ) :wikitext( p.base{ [1] = data.name, data = dataPage, tint = dataPage2, nocap = 1 } ) names = box:tag( 'ul' ):addClass( 'spritedoc-names' )

local nameElem = mw.html.create( 'li' ):addClass( 'spritedoc-name' ) local codeElem = nameElem:tag( 'code' ):wikitext( data.name ) names:wikitext( tostring( nameElem ) ) end if args.refresh then return tostring( body ) end local styles = f:callParserFunction( '#widget:SpriteDoc.css' ) return styles, spriteStyle, tostring( body ) end

return p