No edit summary |
No edit summary |
||
(77 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
− | ------ |
||
− | -- LUA script for processing multiple items in a string |
||
− | -- separated by "!" |
||
− | -- |
||
− | -- Parameters: |
||
− | -- 1: Items List |
||
− | -- 2: File prefix |
||
− | -- 3: Size (optional: default 50) |
||
− | -- 4: File Suffix (optional) |
||
− | -- |
||
− | -- any characters in the list ' are stripped |
||
− | -- |
||
− | -- if the item name has "(non digit characters)" at the end, |
||
− | -- it is replaced with "-non digit characters" |
||
− | -- |
||
− | -- Plain version is returned if Event version is not in data. |
||
− | ------ |
||
− | |||
local p = {} |
local p = {} |
||
+ | local util = require("Module:Utility") |
||
⚫ | |||
+ | local EC = require("Module:EC").getEC |
||
+ | local TOK = require("Module:CharacterToken").getTokenDirect |
||
+ | local CHEST = require("Module:EnchantedChest").getChest |
||
+ | local cData = mw.loadData( 'Module:ItemCollection/data' ) |
||
+ | local date = require("Dev:Date") |
||
+ | local today = os.date("%Y/%m/%d %H:%M:%S") |
||
+ | |||
⚫ | |||
+ | |||
+ | local function ITEM(iData, iName, iDisp, count, size) |
||
+ | local conv = { |
||
+ | ["ch"] = "cp", |
||
+ | ["cos"] = "cp", |
||
+ | } |
||
+ | |||
+ | iDisp = iDisp or iName:gsub("^([^%(]-)%/([^%(]-)$", "%2") |
||
+ | |||
⚫ | |||
+ | if iDisp and tonumber(iDisp) then iDisp = iName end |
||
+ | return table.concat({"[[", iName, "|", (iDisp or iName), "]]"}) |
||
⚫ | |||
+ | size = size + 5 |
||
⚫ | |||
+ | fname = fname:gsub(" ", "_") |
||
+ | if iData[2] == "pf" then |
||
+ | fname = fname:gsub("_float$", "") |
||
+ | else |
||
⚫ | |||
⚫ | |||
⚫ | |||
+ | |||
+ | if iDisp and tonumber(iDisp) and iName ~= iDisp then |
||
+ | fname = fname .. "-" .. iDisp |
||
+ | iDisp = iName |
||
⚫ | |||
+ | |||
+ | local tItemData = { "", "[[File:", string.gsub(iData[2], ".+", conv), "-", fname, |
||
+ | ".png|", math.ceil(size*1.5), "x", size, "px|", |
||
+ | "link=", iName, "|", (iDisp or iName), "]]", "" |
||
+ | } |
||
+ | |||
+ | if iData["C"] and cData["Categories"][iData["C"]] then |
||
+ | local category = iData["C"] |
||
+ | tItemData[1] = '<div style="position: relative; margin: auto; width: ' .. math.ceil(size*1.5+5) .. 'px;">' |
||
+ | tItemData[16] = '<span class="hidden" id="dmk-icon-cat" style="position: absolute; top: -5px; right: ' .. (size==47 and "-15" or "-5") .. 'px;">[[File:cat-' .. category:lower():gsub(" stand$", "") .. '.png|x25px|' .. category .. '|link=Category:' .. cData["Categories"][category][2] .. ']]</span>' |
||
+ | if tostring(count):match("^%+%d$") then |
||
+ | tItemData[16] = tItemData[16] .. '<span class="hidden" style="position: absolute; bottom: 0px; right: ' .. (size==47 and "-15" or "-5") .. 'px;">[[File:Home-enchantable.png|x25px|' .. count .. ' Enchantment Level]]</span>' |
||
⚫ | |||
+ | tItem[3] = '</div><small>' |
||
+ | end |
||
+ | |||
+ | return table.concat(tItemData) |
||
+ | end |
||
+ | end |
||
+ | |||
+ | function p.getOneItem(item, count, size, withName, tRewards, type) |
||
+ | if not item or item=="" or not count or count=="" then return "" end |
||
+ | local nCount = 2 |
||
+ | local sCount = count |
||
+ | if not tostring(count):match("%d[,/-]%d") then |
||
+ | nCount = tonumber(count) or 0 |
||
+ | sCount = util.th_comma(nCount) |
||
+ | end |
||
+ | |||
+ | tItem = {"", (type and "" or (" " .. sCount)), |
||
+ | (withName and "<br /><small>" or ""), |
||
+ | "", "", |
||
+ | (withName and "</small>" or ""), |
||
+ | } |
||
+ | local iName = item |
||
− | local tArgs |
||
+ | local iDisp = nil |
||
+ | local iData = cData.Items[iName] |
||
+ | if iData == nil then |
||
+ | iName, iDisp = mw.ustring.match(item, "^(.-)%-(.-)$") |
||
+ | if iName == nil then iName = item end |
||
+ | iData = cData["Items"][iName] |
||
+ | end |
||
+ | if iName:match("Chests") and not iName:match("Wacky Lunch Chests") then |
||
− | if frame == mw.getCurrentFrame() then |
||
+ | if withName then |
||
− | fParent = frame:getParent() |
||
+ | tItem = {CHEST({item .. ("#" .. count), "P"})} |
||
− | tArgs = fParent.args |
||
+ | else |
||
+ | tItem = {CHEST({item .. ("#" .. count), (size or 42)})} |
||
+ | end |
||
+ | item = "CHEST-" .. item |
||
+ | elseif iData and iData[2] then |
||
+ | tItem[1] = ITEM(iData, iName, iDisp, count, (size or 42)) |
||
+ | tItem[2] = "" |
||
+ | if withName then tItem[4] = ITEM(iData, iName, iDisp, nCount, "L") end |
||
+ | item = "ZITM-" .. item |
||
+ | elseif item:match("^EC") then |
||
+ | tItem[1] = EC({item, nil, nil, (size and "I" or "E"), (size or 35)}) |
||
+ | if withName then tItem[4] = EC({item, "L", S=(nCount==1)}) end |
||
+ | else |
||
+ | tItem[1] = TOK(item, (size or 35)) |
||
⚫ | |||
+ | if withName then |
||
+ | tItem[4] = TOK(item, "L") |
||
+ | if nCount > 1 then tItem[5] = "s" end |
||
⚫ | |||
+ | item = "TOK-" .. item |
||
+ | else |
||
+ | tItem[2] = "" |
||
+ | end |
||
⚫ | |||
+ | if nCount == 0 then tItem[2] = " ?" end |
||
− | if (fParent.args[1]) then |
||
− | tArgs = fParent.args |
||
− | else |
||
− | tArgs = frame.args |
||
⚫ | |||
⚫ | |||
− | tArgs = frame |
||
⚫ | |||
+ | if tRewards and type then |
||
− | local items = tArgs[1] or "" |
||
+ | if not tRewards[item] then tRewards[item] = {I = table.concat(tItem)} end |
||
− | local prefix = tArgs[2] or "" |
||
+ | if not tRewards[item][type] then |
||
− | local size = tArgs[3] |
||
+ | tRewards[item][type] = nCount |
||
− | local suffix = tArgs[4] or "" |
||
+ | else |
||
+ | tRewards[item][type] = (tRewards[item][type] + nCount) |
||
+ | end |
||
+ | return tRewards |
||
+ | end |
||
+ | return table.concat(tItem) |
||
⚫ | |||
+ | end |
||
− | size = "50" |
||
⚫ | |||
⚫ | |||
⚫ | |||
+ | if item:match("^EC") then |
||
+ | item = EC({item, "T"}) |
||
+ | elseif item:match("Chests") and not item:match("Wacky Lunch Chests") then |
||
+ | item = CHEST({item, "T"}) |
||
+ | else |
||
+ | local iData = cData.Items[item] |
||
+ | if not iData then |
||
+ | iName, iDisp = mw.ustring.match(item, "^(.-)%-(.-)$") |
||
+ | iData = cData["Items"][(iName or item)] |
||
+ | if iData then |
||
+ | item = (iName or item) |
||
+ | else |
||
+ | item = TOK(item, "T") |
||
+ | end |
||
+ | end |
||
+ | end |
||
+ | return item |
||
⚫ | |||
+ | end |
||
⚫ | |||
+ | function p.getCost(costData, cardFormat) |
||
⚫ | |||
+ | local tOut = {} |
||
⚫ | |||
⚫ | |||
⚫ | |||
+ | local costName, costNumb = mw.ustring.match(costItem, "^(.-)%s*^%s*(.-)$") |
||
− | |||
− | + | if not costName then costName = costItem end |
|
+ | table.insert(tOut, space) |
||
⚫ | |||
+ | if costName:match("^EC-") then |
||
+ | local curName, curNumb = mw.ustring.match(costName, "^([^,]-)%s*#%s*(.-)$") |
||
+ | if not curName then curName = costName end |
||
+ | if not curNumb then curNumb = "1" end |
||
+ | local cNumb, sNumb = mw.ustring.match(curNumb, "^([^,]-)%s*-%s*(.-)$") |
||
− | itemsFile = itemsFile .. space |
||
+ | if not cNumb then cNumb = count end |
||
− | .. "[[File:" |
||
− | .. prefix |
||
− | .. "-" |
||
− | .. lcIt |
||
− | .. ".png|x" |
||
− | .. size |
||
− | .. "px|link=" |
||
− | .. it |
||
− | |||
⚫ | |||
− | itemsFile = itemsFile .. " " .. suffix |
||
⚫ | |||
+ | if sNumb then |
||
− | itemsFile = itemsFile .. "]]" |
||
+ | cNumb = tonumber((string.gsub(cNumb or "", "[,]", ""))) |
||
+ | sNumb = tonumber((string.gsub(sNumb or "", "[,]", ""))) |
||
+ | if cardFormat then table.insert(tOut, "<big>") end |
||
⚫ | |||
+ | table.insert(tOut, EC({(curName .. " #" .. util.th_comma(sNumb)), nil, nil, nil, 30})) |
||
⚫ | |||
+ | if cardFormat then table.insert(tOut, "</big>") end |
||
+ | if cardFormat then |
||
+ | table.insert(tOut, ' <i style="text-decoration: line-through 2px red;color: transparent;">') |
||
+ | else |
||
+ | table.insert(tOut, ' <i style="text-decoration: line-through 2px red;color: #000000ad;">') |
||
+ | end |
||
+ | table.insert(tOut, util.th_comma(cNumb)) |
||
+ | table.insert(tOut, '</i><span style="white-space: nowrap;"><small style="border-radius: 10px 0 0 10px;padding: 2px 3px 2px 3px;background: #f20d07;box-shadow: 0 0 5px 0 #494444;border: 1px solid #feb226;outline: 1px solid #f20d07;margin-left: 5px; color: white;white-space: nowrap;"><b> -') |
||
+ | table.insert(tOut, (100-(string.format("%.2f", (sNumb/cNumb))*100))) |
||
+ | table.insert(tOut, '%</b></small>') |
||
+ | else |
||
+ | if cardFormat then table.insert(tOut, "<big>") end |
||
+ | table.insert(tOut, EC({costName, nil, nil, nil, 30})) |
||
+ | if cardFormat then table.insert(tOut, "</big>") end |
||
+ | end |
||
+ | else |
||
+ | table.insert(tOut, costName) |
||
+ | end |
||
+ | table.insert(tOut, (costNumb and (" <small>(" .. costNumb .. ")</small>") or "")) |
||
⚫ | |||
+ | end |
||
− | + | return table.concat(tOut) |
|
end |
end |
||
Latest revision as of 08:33, 1 April 2024
Description
This module provides display functions for use in other modules.
local p = {}
local util = require("Module:Utility")
local EC = require("Module:EC").getEC
local TOK = require("Module:CharacterToken").getTokenDirect
local CHEST = require("Module:EnchantedChest").getChest
local cData = mw.loadData( 'Module:ItemCollection/data' )
local date = require("Dev:Date")
local today = os.date("%Y/%m/%d %H:%M:%S")
local tItem = {}
local function ITEM(iData, iName, iDisp, count, size)
local conv = {
["ch"] = "cp",
["cos"] = "cp",
}
iDisp = iDisp or iName:gsub("^([^%(]-)%/([^%(]-)$", "%2")
if size=="L" then
if iDisp and tonumber(iDisp) then iDisp = iName end
return table.concat({"[[", iName, "|", (iDisp or iName), "]]"})
else
size = size + 5
local fname = mw.ustring.gsub(mw.ustring.lower(iName), "[':\"%,%.*]", "")
fname = fname:gsub(" ", "_")
if iData[2] == "pf" then
fname = fname:gsub("_float$", "")
else
fname = fname:gsub("^([^%(]-)%/([^%(]-)$", "%1-%2")
fname = mw.ustring.gsub(fname, "^([^%(]-) *%(([^%(]-)%)$", "%1_%2")
end
if iDisp and tonumber(iDisp) and iName ~= iDisp then
fname = fname .. "-" .. iDisp
iDisp = iName
end
local tItemData = { "", "[[File:", string.gsub(iData[2], ".+", conv), "-", fname,
".png|", math.ceil(size*1.5), "x", size, "px|",
"link=", iName, "|", (iDisp or iName), "]]", ""
}
if iData["C"] and cData["Categories"][iData["C"]] then
local category = iData["C"]
tItemData[1] = '<div style="position: relative; margin: auto; width: ' .. math.ceil(size*1.5+5) .. 'px;">'
tItemData[16] = '<span class="hidden" id="dmk-icon-cat" style="position: absolute; top: -5px; right: ' .. (size==47 and "-15" or "-5") .. 'px;">[[File:cat-' .. category:lower():gsub(" stand$", "") .. '.png|x25px|' .. category .. '|link=Category:' .. cData["Categories"][category][2] .. ']]</span>'
if tostring(count):match("^%+%d$") then
tItemData[16] = tItemData[16] .. '<span class="hidden" style="position: absolute; bottom: 0px; right: ' .. (size==47 and "-15" or "-5") .. 'px;">[[File:Home-enchantable.png|x25px|' .. count .. ' Enchantment Level]]</span>'
end
tItem[3] = '</div><small>'
end
return table.concat(tItemData)
end
end
function p.getOneItem(item, count, size, withName, tRewards, type)
if not item or item=="" or not count or count=="" then return "" end
local nCount = 2
local sCount = count
if not tostring(count):match("%d[,/-]%d") then
nCount = tonumber(count) or 0
sCount = util.th_comma(nCount)
end
tItem = {"", (type and "" or (" " .. sCount)),
(withName and "<br /><small>" or ""),
"", "",
(withName and "</small>" or ""),
}
local iName = item
local iDisp = nil
local iData = cData.Items[iName]
if iData == nil then
iName, iDisp = mw.ustring.match(item, "^(.-)%-(.-)$")
if iName == nil then iName = item end
iData = cData["Items"][iName]
end
if iName:match("Chests") and not iName:match("Wacky Lunch Chests") then
if withName then
tItem = {CHEST({item .. ("#" .. count), "P"})}
else
tItem = {CHEST({item .. ("#" .. count), (size or 42)})}
end
item = "CHEST-" .. item
elseif iData and iData[2] then
tItem[1] = ITEM(iData, iName, iDisp, count, (size or 42))
tItem[2] = ""
if withName then tItem[4] = ITEM(iData, iName, iDisp, nCount, "L") end
item = "ZITM-" .. item
elseif item:match("^EC") then
tItem[1] = EC({item, nil, nil, (size and "I" or "E"), (size or 35)})
if withName then tItem[4] = EC({item, "L", S=(nCount==1)}) end
else
tItem[1] = TOK(item, (size or 35))
if tItem[1] ~= "" then
if withName then
tItem[4] = TOK(item, "L")
if nCount > 1 then tItem[5] = "s" end
end
item = "TOK-" .. item
else
tItem[2] = ""
end
end
if nCount == 0 then tItem[2] = " ?" end
if tRewards and type then
if not tRewards[item] then tRewards[item] = {I = table.concat(tItem)} end
if not tRewards[item][type] then
tRewards[item][type] = nCount
else
tRewards[item][type] = (tRewards[item][type] + nCount)
end
return tRewards
end
return table.concat(tItem)
end
function p.getPagename(item)
if item:match("^EC") then
item = EC({item, "T"})
elseif item:match("Chests") and not item:match("Wacky Lunch Chests") then
item = CHEST({item, "T"})
else
local iData = cData.Items[item]
if not iData then
iName, iDisp = mw.ustring.match(item, "^(.-)%-(.-)$")
iData = cData["Items"][(iName or item)]
if iData then
item = (iName or item)
else
item = TOK(item, "T")
end
end
end
return item
end
function p.getCost(costData, cardFormat)
local tOut = {}
local space = ""
for costItem in mw.text.gsplit(costData, "%s*$%s*") do
local costName, costNumb = mw.ustring.match(costItem, "^(.-)%s*^%s*(.-)$")
if not costName then costName = costItem end
table.insert(tOut, space)
if costName:match("^EC-") then
local curName, curNumb = mw.ustring.match(costName, "^([^,]-)%s*#%s*(.-)$")
if not curName then curName = costName end
if not curNumb then curNumb = "1" end
local cNumb, sNumb = mw.ustring.match(curNumb, "^([^,]-)%s*-%s*(.-)$")
if not cNumb then cNumb = count end
if sNumb then
cNumb = tonumber((string.gsub(cNumb or "", "[,]", "")))
sNumb = tonumber((string.gsub(sNumb or "", "[,]", "")))
if cardFormat then table.insert(tOut, "<big>") end
table.insert(tOut, EC({(curName .. " #" .. util.th_comma(sNumb)), nil, nil, nil, 30}))
if cardFormat then table.insert(tOut, "</big>") end
if cardFormat then
table.insert(tOut, ' <i style="text-decoration: line-through 2px red;color: transparent;">')
else
table.insert(tOut, ' <i style="text-decoration: line-through 2px red;color: #000000ad;">')
end
table.insert(tOut, util.th_comma(cNumb))
table.insert(tOut, '</i><span style="white-space: nowrap;"><small style="border-radius: 10px 0 0 10px;padding: 2px 3px 2px 3px;background: #f20d07;box-shadow: 0 0 5px 0 #494444;border: 1px solid #feb226;outline: 1px solid #f20d07;margin-left: 5px; color: white;white-space: nowrap;"><b> -')
table.insert(tOut, (100-(string.format("%.2f", (sNumb/cNumb))*100)))
table.insert(tOut, '%</b></small>')
else
if cardFormat then table.insert(tOut, "<big>") end
table.insert(tOut, EC({costName, nil, nil, nil, 30}))
if cardFormat then table.insert(tOut, "</big>") end
end
else
table.insert(tOut, costName)
end
table.insert(tOut, (costNumb and (" <small>(" .. costNumb .. ")</small>") or ""))
space = "<br/>"
end
return table.concat(tOut)
end
return p