Module:Equipment: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
Line 11: | Line 11: | ||
-- Parse item string and check if GIF icons are allowed | -- Parse item string and check if GIF icons are allowed | ||
local function parseItem(ret, itemString, equipSlot, stats, quantity) | local function parseItem(ret, itemString, equipSlot, stats, quantity, clickable) | ||
local itemString = itemString | local itemString = itemString | ||
local allowGif = false | local allowGif = false | ||
Line 20: | Line 20: | ||
allowGif = itemString:sub(-2) == ";g" | allowGif = itemString:sub(-2) == ";g" | ||
if allowGif then | if allowGif then | ||
itemName = itemString:sub(0, -3) | |||
else | else | ||
itemName = itemString or "" | |||
end | end | ||
end | end | ||
return ret, itemName, allowGif, equipSlot, stats, quantity | return ret, itemName, allowGif, equipSlot, stats, quantity, clickable | ||
end | end | ||
-- Formats a <div> element for items | -- Formats a <div> element for items | ||
local function makeDiv(ret, itemName, allowGif, equipSlot, stats, quantity) | local function makeDiv(ret, itemName, allowGif, equipSlot, stats, quantity, clickable) | ||
local itemName = itemName | local itemName = itemName | ||
local allowGif = allowGif | local allowGif = allowGif | ||
local topDivClass = "equipment-" .. equipSlot | local topDivClass = "equipment-" .. equipSlot | ||
local names = mw.text.split(itemName, ";") | |||
if #names <= 1 or names[2] == 'g' then | |||
names[2] = itemstats.defaultVersion(names[1]) or names[1] | |||
end | |||
local imgType = allowGif == true and "gif" or "png" | local imgType = allowGif == true and "gif" or "png" | ||
local equipSlotText = "" | local equipSlotText = "" | ||
-- Check if the item name is not empty | -- Check if the item name is not empty | ||
if itemName ~= '' then | if itemName ~= '' then | ||
if clickable then | if clickable then | ||
-- Construct a clickable link | -- Construct a clickable link | ||
equipSlotText = string.format("[[File:%s. | equipSlotText = string.format("[[File:%s.%s|%s|link=]]", names[1], imgType, names[2]) | ||
else | else | ||
-- Construct a plain image without a link | -- Construct a plain image without a link | ||
equipSlotText = string.format("[[File:%s. | equipSlotText = string.format("[[File:%s.%s|%s]]", names[1], imgType, names[2]) | ||
end | end | ||
end | end | ||
-- Create the divs | -- Create the divs | ||
Line 91: | Line 66: | ||
if quantity then | if quantity then | ||
local amt, quantclass = formatAmount(quantity) | |||
nestedDiv:tag('span') | |||
:addClass('inv-quantity-text') | |||
:addClass(quantclass) | |||
:wikitext(amt) | |||
end | |||
if stats and itemName ~= '' then | if stats and itemName ~= '' then | ||
-- Add stat-related code here if needed | |||
end | end | ||
Line 139: | Line 80: | ||
topDiv:addClass("equipment-blank") | topDiv:addClass("equipment-blank") | ||
end | end | ||
end | end | ||
Line 245: | Line 98: | ||
align = "equipment " .. align | align = "equipment " .. align | ||
local tbl = mw.html.create("table"):addClass(align):tag("tr") | |||
local ret = tbl:tag("td"):tag("div") | |||
if stats then | |||
stats = { | |||
astab = 0, | |||
aslash = 0, | |||
acrush = 0, | |||
amagic = 0, | |||
arange = 0, | |||
dstab = 0, | |||
dslash = 0, | |||
dcrush = 0, | |||
dmagic = 0, | |||
drange = 0, | |||
str = 0, | |||
rstr = 0, | |||
mdmg = 0, | |||
prayer = 0, | |||
weight = 0, | |||
ikods = {}, | |||
} | |||
end | |||
if buttons then | if buttons then | ||
Line 275: | Line 128: | ||
-- Fetch equipment and create divs | -- Fetch equipment and create divs | ||
makeDiv(parseItem(ret, args.head, "head", stats)) | makeDiv(parseItem(ret, args.head, "head", stats, nil, yesno(args.headClickable, false))) | ||
makeDiv(parseItem(ret, args.cape, "cape", stats)) | makeDiv(parseItem(ret, args.cape, "cape", stats, nil, yesno(args.capeClickable, false))) | ||
makeDiv(parseItem(ret, args.neck, "neck", stats)) | makeDiv(parseItem(ret, args.neck, "neck", stats, nil, yesno(args.neckClickable, false))) | ||
makeDiv(parseItem(ret, args.ammo, "ammo", stats, args.ammoquantity)) | makeDiv(parseItem(ret, args.ammo, "ammo", stats, args.ammoquantity, yesno(args.ammoClickable, false))) | ||
makeDiv(parseItem(ret, args.weapon, "weapon", stats, args.weaponquantity)) | makeDiv(parseItem(ret, args.weapon, "weapon", stats, args.weaponquantity, yesno(args.weaponClickable, false))) | ||
makeDiv(parseItem(ret, args.torso, "torso", stats)) | makeDiv(parseItem(ret, args.torso, "torso", stats, nil, yesno(args.torsoClickable, false))) | ||
makeDiv(parseItem(ret, args.shield, "shield", stats)) | makeDiv(parseItem(ret, args.shield, "shield", stats, nil, yesno(args.shieldClickable, false))) | ||
makeDiv(parseItem(ret, args.legs, "legs", stats)) | makeDiv(parseItem(ret, args.legs, "legs", stats, nil, yesno(args.legsClickable, false))) | ||
makeDiv(parseItem(ret, args.gloves, "gloves", stats)) | makeDiv(parseItem(ret, args.gloves, "gloves", stats, nil, yesno(args.glovesClickable, false))) | ||
makeDiv(parseItem(ret, args.hands, "gloves", stats)) | makeDiv(parseItem(ret, args.hands, "gloves", stats, nil, yesno(args.handsClickable, false))) | ||
makeDiv(parseItem(ret, args.boots, "boots", stats)) | makeDiv(parseItem(ret, args.boots, "boots", stats, nil, yesno(args.bootsClickable, false))) | ||
makeDiv(parseItem(ret, args.ring, "ring", stats | makeDiv(parseItem(ret, args.ring, "ring", stats, nil, yesno(args.ringClickable, false))) | ||
if stats then | |||
-- Add stat-related code here if needed | |||
end | |||
return tbl:done() | |||
end | end | ||
return p | return p |
Revision as of 10:51, 6 May 2024
Documentation for this module may be created at Module:Equipment/doc
-- <pre>Sandbox for testing stuff. Infoked by [[User:Joeytje50/Module]]
-- Current module being tested: Module:Equipment
local p = {}
local hasc = require('Module:Paramtest').has_content
local itemstats = require('Module:FetchItemStats')
local yesno = require('Module:Yesno')
local lang = mw.language.getContentLanguage()
local GEPrice = require('Module:Exchange')._price
-- Parse item string and check if GIF icons are allowed
local function parseItem(ret, itemString, equipSlot, stats, quantity, clickable)
local itemString = itemString
local allowGif = false
local itemName = ""
-- Look for a ;g at the end of the string and separate them
if hasc(itemString) then
allowGif = itemString:sub(-2) == ";g"
if allowGif then
itemName = itemString:sub(0, -3)
else
itemName = itemString or ""
end
end
return ret, itemName, allowGif, equipSlot, stats, quantity, clickable
end
-- Formats a <div> element for items
local function makeDiv(ret, itemName, allowGif, equipSlot, stats, quantity, clickable)
local itemName = itemName
local allowGif = allowGif
local topDivClass = "equipment-" .. equipSlot
local names = mw.text.split(itemName, ";")
if #names <= 1 or names[2] == 'g' then
names[2] = itemstats.defaultVersion(names[1]) or names[1]
end
local imgType = allowGif == true and "gif" or "png"
local equipSlotText = ""
-- Check if the item name is not empty
if itemName ~= '' then
if clickable then
-- Construct a clickable link
equipSlotText = string.format("[[File:%s.%s|%s|link=]]", names[1], imgType, names[2])
else
-- Construct a plain image without a link
equipSlotText = string.format("[[File:%s.%s|%s]]", names[1], imgType, names[2])
end
end
-- Create the divs
local topDiv = ret
:tag("div")
:addClass(topDivClass)
local nestedDiv = topDiv
:tag("div")
:addClass("equipment-plinkp")
:wikitext(equipSlotText)
if quantity then
local amt, quantclass = formatAmount(quantity)
nestedDiv:tag('span')
:addClass('inv-quantity-text')
:addClass(quantclass)
:wikitext(amt)
end
if stats and itemName ~= '' then
-- Add stat-related code here if needed
end
if itemName ~= '' then
topDiv:addClass("equipment-blank")
end
end
function p.main(frame)
local args = frame:getParent().args
local buttons = yesno(args.buttons, false)
local stats = yesno(args.stats, false)
local align
if args.align == "right" then
align = "equipment-right"
elseif args.align == "center" then
align = "equipment-center"
else
align = "equipment-left"
end
-- general 'equipment' class for the whole thing
align = "equipment " .. align
local tbl = mw.html.create("table"):addClass(align):tag("tr")
local ret = tbl:tag("td"):tag("div")
if stats then
stats = {
astab = 0,
aslash = 0,
acrush = 0,
amagic = 0,
arange = 0,
dstab = 0,
dslash = 0,
dcrush = 0,
dmagic = 0,
drange = 0,
str = 0,
rstr = 0,
mdmg = 0,
prayer = 0,
weight = 0,
ikods = {},
}
end
if buttons then
ret:addClass("equipment-div-buttons")
else
ret:addClass("equipment-div")
end
-- Fetch equipment and create divs
makeDiv(parseItem(ret, args.head, "head", stats, nil, yesno(args.headClickable, false)))
makeDiv(parseItem(ret, args.cape, "cape", stats, nil, yesno(args.capeClickable, false)))
makeDiv(parseItem(ret, args.neck, "neck", stats, nil, yesno(args.neckClickable, false)))
makeDiv(parseItem(ret, args.ammo, "ammo", stats, args.ammoquantity, yesno(args.ammoClickable, false)))
makeDiv(parseItem(ret, args.weapon, "weapon", stats, args.weaponquantity, yesno(args.weaponClickable, false)))
makeDiv(parseItem(ret, args.torso, "torso", stats, nil, yesno(args.torsoClickable, false)))
makeDiv(parseItem(ret, args.shield, "shield", stats, nil, yesno(args.shieldClickable, false)))
makeDiv(parseItem(ret, args.legs, "legs", stats, nil, yesno(args.legsClickable, false)))
makeDiv(parseItem(ret, args.gloves, "gloves", stats, nil, yesno(args.glovesClickable, false)))
makeDiv(parseItem(ret, args.hands, "gloves", stats, nil, yesno(args.handsClickable, false)))
makeDiv(parseItem(ret, args.boots, "boots", stats, nil, yesno(args.bootsClickable, false)))
makeDiv(parseItem(ret, args.ring, "ring", stats, nil, yesno(args.ringClickable, false)))
if stats then
-- Add stat-related code here if needed
end
return tbl:done()
end
return p