Module:Fabricator: Difference between revisions
From Fisk's Superheroes Wiki
More actions
m 1 revision imported |
DeathRealms (talk | contribs) mNo edit summary |
||
| Line 1: | Line 1: | ||
local p = {} | local p = {} | ||
function | local function isUrl(value) | ||
local function | return type(value) == "string" and value:match("^https?://") | ||
end | |||
local function isHtmlImg(value) | |||
return type(value) == "string" and value:match("^<img") | |||
end | |||
local function resolveImage(value) | |||
if not value then return nil end | |||
if isUrl(value) then | |||
if not value:match("[?&]dl=1") then | |||
if value:match("%?") then | |||
value = value .. "&dl=1" | |||
else | |||
value = value .. "?dl=1" | |||
end | |||
end | end | ||
return | return value | ||
end | end | ||
if isHtmlImg(value) then | |||
return | return value | ||
end | end | ||
return mw.getCurrentFrame():callParserFunction("filepath", value) | |||
end | |||
local function split(str, sep) | |||
if (str == nil) then return {} end | |||
local result = {} | |||
for match in (str..sep):gmatch("([^"..sep.."]+)") do | |||
table.insert(result, match) | |||
end | |||
return result | |||
end | |||
function p.gui(frame) | |||
local args = frame.args | local args = frame.args | ||
local scale = tonumber(args.scale) or 1 | local scale = tonumber(args.scale) or 1 | ||
| Line 29: | Line 54: | ||
html:tag("img") | html:tag("img") | ||
:attr("src", | :attr("src", resolveImage("Fabricator.png")) | ||
:css{ | :css{ | ||
["image-rendering"] = "pixelated", | ["image-rendering"] = "pixelated", | ||
| Line 36: | Line 61: | ||
display = "block" | display = "block" | ||
} | } | ||
for i = 1, 10 do | for i = 1, 10 do | ||
local item = args[ | local item = args["I"..i] | ||
if | |||
if item then | |||
local amount = | local itemParts = split(item, ";") | ||
local amount = itemParts[2] or 1 | |||
local filename = itemParts[1] | |||
local xOffset | local xOffset | ||
if | if i == 1 or i == 6 then | ||
xOffset = 30 * scale | xOffset = 30 * scale | ||
else | else | ||
xOffset = (30 + ((i - 1) % 5) * 18) * scale | xOffset = (30 + ((i - 1) % 5) * 18) * scale | ||
end | end | ||
local yOffset | |||
local yOffset = (i > 5) and (25 * scale) or (7 * scale) | |||
local container = mw.html.create("div") | local container = mw.html.create("div") | ||
| Line 67: | Line 90: | ||
container:tag("img") | container:tag("img") | ||
:attr("src", | :attr("src", resolveImage(filename)) | ||
:css{ | :css{ | ||
["image-rendering"] = "pixelated", | ["image-rendering"] = "pixelated", | ||
| Line 74: | Line 97: | ||
} | } | ||
container:tag("span") | container:tag("span") | ||
:attr("class", "micro-5-regular") | :attr("class", "micro-5-regular") | ||
| Line 92: | Line 114: | ||
end | end | ||
if | if args.output then | ||
html:tag("img") | html:tag("img") | ||
:attr("src", | :attr("src", resolveImage(args.output)) | ||
:css{ | :css{ | ||
position = "absolute", | position = "absolute", | ||
| Line 106: | Line 128: | ||
html:tag("img") | html:tag("img") | ||
:attr("src", | :attr("src", resolveImage(args.drive or "Suit_Data_Drive_Black_Active.gif")) | ||
:css{ | :css{ | ||
position = "absolute", | position = "absolute", | ||
| Line 117: | Line 139: | ||
html:tag("img") | html:tag("img") | ||
:attr("src", | :attr("src", resolveImage(args.core or "Suit_Core.png")) | ||
:css{ | :css{ | ||
position = "absolute", | position = "absolute", | ||
| Line 129: | Line 151: | ||
local tooltip = mw.html.create("div") | local tooltip = mw.html.create("div") | ||
:attr("id", "item-tooltip") | :attr("id", "item-tooltip") | ||
:css{ | :css{ display = "none" } | ||
tooltip:tag("span") | tooltip:tag("span") | ||
:attr("class", "micro-5-regular") | :attr("class", "micro-5-regular") | ||
| Line 141: | Line 161: | ||
} | } | ||
:wikitext("Test") | :wikitext("Test") | ||
html:node(tooltip) | html:node(tooltip) | ||
Latest revision as of 21:38, 15 November 2025
Documentation for this module may be created at Module:Fabricator/doc
local p = {}
local function isUrl(value)
return type(value) == "string" and value:match("^https?://")
end
local function isHtmlImg(value)
return type(value) == "string" and value:match("^<img")
end
local function resolveImage(value)
if not value then return nil end
if isUrl(value) then
if not value:match("[?&]dl=1") then
if value:match("%?") then
value = value .. "&dl=1"
else
value = value .. "?dl=1"
end
end
return value
end
if isHtmlImg(value) then
return value
end
return mw.getCurrentFrame():callParserFunction("filepath", value)
end
local function split(str, sep)
if (str == nil) then return {} end
local result = {}
for match in (str..sep):gmatch("([^"..sep.."]+)") do
table.insert(result, match)
end
return result
end
function p.gui(frame)
local args = frame.args
local scale = tonumber(args.scale) or 1
local html = mw.html.create("div")
:attr("class", "frame")
:css{
position = "relative",
width = 166 * scale .. "px",
height = 48 * scale .. "px",
display = "inline-block",
overflow = "hidden"
}
html:tag("img")
:attr("src", resolveImage("Fabricator.png"))
:css{
["image-rendering"] = "pixelated",
width = "100%",
height = "100%",
display = "block"
}
for i = 1, 10 do
local item = args["I"..i]
if item then
local itemParts = split(item, ";")
local amount = itemParts[2] or 1
local filename = itemParts[1]
local xOffset
if i == 1 or i == 6 then
xOffset = 30 * scale
else
xOffset = (30 + ((i - 1) % 5) * 18) * scale
end
local yOffset = (i > 5) and (25 * scale) or (7 * scale)
local container = mw.html.create("div")
:attr("class", "item")
:css{
position = "absolute",
left = xOffset .. "px",
top = yOffset .. "px",
width = 16 * scale .. "px",
height = 16 * scale .. "px"
}
container:tag("img")
:attr("src", resolveImage(filename))
:css{
["image-rendering"] = "pixelated",
width = 16 * scale .. "px",
height = 16 * scale .. "px"
}
container:tag("span")
:attr("class", "micro-5-regular")
:wikitext(amount)
:css{
position = "absolute",
right = 0,
bottom = 0,
["font-size"] = (12 * scale) .. "px",
["line-height"] = (12 * scale) - (scale * 4) .. "px",
color = "#FFFFFF",
["-webkit-text-stroke"] = math.max(1, scale / 2) .. "px #000000",
}
html:node(container)
end
end
if args.output then
html:tag("img")
:attr("src", resolveImage(args.output))
:css{
position = "absolute",
left = 142 * scale .. "px",
top = 16 * scale .. "px",
width = 16 * scale .. "px",
height = 16 * scale .. "px",
["image-rendering"] = "pixelated",
}
end
html:tag("img")
:attr("src", resolveImage(args.drive or "Suit_Data_Drive_Black_Active.gif"))
:css{
position = "absolute",
left = 8 * scale .. "px",
top = 7 * scale .. "px",
width = 16 * scale .. "px",
height = 16 * scale .. "px",
["image-rendering"] = "pixelated",
}
html:tag("img")
:attr("src", resolveImage(args.core or "Suit_Core.png"))
:css{
position = "absolute",
left = 8 * scale .. "px",
top = 25 * scale .. "px",
width = 16 * scale .. "px",
height = 16 * scale .. "px",
["image-rendering"] = "pixelated",
}
local tooltip = mw.html.create("div")
:attr("id", "item-tooltip")
:css{ display = "none" }
tooltip:tag("span")
:attr("class", "micro-5-regular")
:css{
["font-size"] = (12 * scale) .. "px",
["line-height"] = (12 * scale) - (scale * 4) .. "px",
color = "#FFFFFF"
}
:wikitext("Test")
html:node(tooltip)
return frame:extensionTag("html", tostring(html))
end
return p