Module:Stonecutting: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
| Line 17: | Line 17: | ||
end | end | ||
-- one GUI frame | -- build one GUI frame | ||
local function buildFrame(args, idx, count) | local function buildFrame(args, idx, count) | ||
local inL = args.input or args[1] or '' | local inL = args.input or args[1] or '' | ||
local inI = args['input-image'] or '' | local inI = args['input-image'] or '' | ||
local inLn= args['input-link'] | local inLn = args['input-link'] or '' | ||
local outL = args['output' .. idx] or args[idx+1] or '' | local outL = args['output' .. idx] or args[idx+1] or '' | ||
| Line 29: | Line 29: | ||
local frame = mw.html.create('div'):addClass('sc-frame') | local frame = mw.html.create('div'):addClass('sc-frame') | ||
if count > 1 then | if count > 1 then | ||
frame:css('animation-duration', (count * 4) .. 's') | |||
frame:css('animation-duration', | |||
:css('animation-delay', (idx-1)*4 .. 's') | :css('animation-delay', (idx-1)*4 .. 's') | ||
else | else | ||
frame:addClass('sc-static') -- no animation | |||
frame:addClass('sc-static') | |||
end | end | ||
| Line 56: | Line 53: | ||
end | end | ||
-- main entry | ------------------------------------------------------------------------ | ||
-- main entry – {{#invoke:Stonecutting|carousel}} | |||
------------------------------------------------------------------------ | |||
function p.carousel(frame) | function p.carousel(frame) | ||
local args = getArgs(frame, {removeBlanks = false}) | local args = getArgs(frame, {removeBlanks = false}) | ||
-- count outputs | -- count non-blank outputs | ||
local count = 0 | local count = 0 | ||
while true do | while true do | ||
| Line 71: | Line 70: | ||
end | end | ||
-- wrapper | -- outer wrapper | ||
local outer = mw.html.create('div') | local outer = mw.html.create('div') | ||
:addClass('stonecutting-carousel') | :addClass('stonecutting-carousel') | ||
:css{width='180px', height='131px', position='relative'} | :css{width='180px', height='131px', position='relative'} | ||
for i = 1, count do | for i = 1, count do | ||
outer:wikitext(buildFrame(args, i, count)) | outer:wikitext(buildFrame(args, i, count)) | ||
end | end | ||
-- static stylesheet | -- static stylesheet | ||
outer:wikitext('<templatestyles src="Stonecutting/styles.css" />') | outer:wikitext('<templatestyles src="Stonecutting/styles.css" />') | ||
---- | -- per-call key-frames (only if more than one output) | ||
if count > 1 then | |||
local pct = 100 / count | |||
local css = string.format( | |||
'@keyframes sc-cycle{0%%{opacity:1;visibility:visible;} %.2f%%{opacity:1;visibility:visible;} %.2f%%{opacity:0;visibility:hidden;} 100%%{opacity:0;visibility:hidden;}}', | |||
pct - 0.01, pct | |||
) | |||
outer:wikitext( | |||
frame:extensionTag('templatestyles', css, {lang = 'css'}) | |||
) | |||
end | |||
return tostring(outer) | return tostring(outer) | ||
Revision as of 04:06, 14 June 2025
Documentation for this module may be created at Module:Stonecutting/doc
------------------------------------------------------------
-- Module:Stonecutting – animated stone-cutter carousel
------------------------------------------------------------
local p = {}
local getArgs = require('Module:Arguments').getArgs
local trim = mw.text.trim
-- helper: thumbnail slot
local function slotImage(label, image, link)
if not label or label == '' then return '' end
local file = (image ~= '' and image) or ('Grid_' .. label .. '.png')
local tgt = (link ~= '' and link ) or label
return string.format(
'[[File:%s|32px|class=pixelated|link=%s|alt=%s]]',
file, tgt, label
)
end
-- build one GUI frame
local function buildFrame(args, idx, count)
local inL = args.input or args[1] or ''
local inI = args['input-image'] or ''
local inLn = args['input-link'] or ''
local outL = args['output' .. idx] or args[idx+1] or ''
local outI = args['output' .. idx .. '-image'] or ''
local outLn = args['output' .. idx .. '-link'] or ''
local frame = mw.html.create('div'):addClass('sc-frame')
if count > 1 then
frame:css('animation-duration', (count * 4) .. 's')
:css('animation-delay', (idx-1)*4 .. 's')
else
frame:addClass('sc-static') -- no animation
end
frame:wikitext('[[File:StonecutterGUI.png|180px|link=|alt=]]')
frame:tag('div'):addClass('sc-slot')
:css{left='11px', top='50px'}
:wikitext(slotImage(inL, inI, inLn))
frame:tag('div'):addClass('sc-slot')
:css{left='56.5px', top='23px'}
:wikitext(slotImage(outL, outI, outLn))
frame:tag('div'):addClass('sc-slot')
:css{left='127px', top='50px'}
:wikitext(slotImage(outL, outI, outLn))
return tostring(frame)
end
------------------------------------------------------------------------
-- main entry – {{#invoke:Stonecutting|carousel}}
------------------------------------------------------------------------
function p.carousel(frame)
local args = getArgs(frame, {removeBlanks = false})
-- count non-blank outputs
local count = 0
while true do
local raw = args['output' .. (count+1)] or args[count+2]
if not raw or trim(tostring(raw)) == '' then break end
count = count + 1
end
if count == 0 then
return '<span style="color:red">Stonecutting: no outputs supplied</span>'
end
-- outer wrapper
local outer = mw.html.create('div')
:addClass('stonecutting-carousel')
:css{width='180px', height='131px', position='relative'}
for i = 1, count do
outer:wikitext(buildFrame(args, i, count))
end
-- static stylesheet
outer:wikitext('<templatestyles src="Stonecutting/styles.css" />')
-- per-call key-frames (only if more than one output)
if count > 1 then
local pct = 100 / count
local css = string.format(
'@keyframes sc-cycle{0%%{opacity:1;visibility:visible;} %.2f%%{opacity:1;visibility:visible;} %.2f%%{opacity:0;visibility:hidden;} 100%%{opacity:0;visibility:hidden;}}',
pct - 0.01, pct
)
outer:wikitext(
frame:extensionTag('templatestyles', css, {lang = 'css'})
)
end
return tostring(outer)
end
return p