Module:Products: Difference between revisions
m
Spaces to tabs
(x -> × simplify single value / table of values implementation; allow quantity to have a decimal point (like when it's "0.05")) |
m (Spaces to tabs) |
||
Line 1:
local p = {}
Line 7 ⟶ 9:
function p._main(args)
args = args or {}
end
function p.extractRecipeNames(products)
end
function p.getProducts(args)
end
function p.getShopBuyPrices(products)
▲ for _, product in ipairs(products) do
▲ local usesItems = product["Uses item and quantity"]
▲ if type(usesItems) == "string" then
▲ -- Single value
▲ usesItems = { usesItems }
▲ for _, item in ipairs(usesItems) do
▲ -- Extract item name and quantity from the "item,#" format
▲ local itemName, quantity = item:match("^([^,]+),([0-9.]+)$")
▲ quantity = tonumber(quantity) or 1 -- Default to 1 if quantity is missing
▲ if itemName then
▲ -- Query for the shop buy price of the item
end
▲ local shopPriceQuery = '[[:+]][[Sold item::' .. itemName .. ']]|?Shop buy price|mainlabel=' .. itemName
▲ local shopPriceResult = mw.smw.ask(shopPriceQuery) or {}
▲ local shopPrice = 0
▲ if shopPriceResult[1] and shopPriceResult[1]["Shop buy price"] then
▲ shopPrice = tonumber(shopPriceResult[1]["Shop buy price"]) or 0
▲ -- Multiply the price by the quantity
▲ local totalPrice = shopPrice * quantity
end
▲ -- Update the product with the formatted string and total price
end
▲ product[itemName .. "_Shop_buy_price"] = totalPrice > 0 and totalPrice or "N/A"
end
▲ product[itemName .. "_Formatted"] = tostring(quantity) .. " × " .. itemName
▲ end
▲ return products
end
function p.displayProductTable(products, showPrices, showValues)
▲ local currency = require('Module:Currency').parse
▲ local out = {}
▲ table.insert(out, '{| class="wikitable"')
local headerRow = {}
table.insert(headerRow, '!! Level')▼
if showValues then
end
Line 93 ⟶ 92:
if showPrices then
end
table.insert(out, table.concat(headerRow, ' '))
end
table.insert(valuesRow, '|| ' .. professionLevel)
if showValues then
end
Line 145 ⟶ 144:
if showPrices then
end
table.insert(out, table.concat(valuesRow, ' '))
--table.insert(out, '| ' .. recipe .. ' || ' .. professionLevel .. ' || ' .. value .. ' || ' .. usesItemStr .. ' || ' .. shopBuyPriceStr)▼
▲ end
table.insert(out, '|}')▼
▲
end
end
|