Module:Gemshop: Difference between revisions
From IdleOn MMO Wiki
Kiokurashi (talk | contribs) mNo edit summary Tag: Manual revert |
mNo edit summary |
||
(18 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
local | local mtxinfo = mw.loadJsonData('Module:Gemshop/MTXinfo.json') | ||
local p = {} | local p = {} | ||
-- Gemshop/data.json is return value of ha.MTXinfo() in N.js without any conversion | |||
-- itemDisplayName, mtxName, desc, maxPurchases, cost, extra stuff, total stuff | -- itemDisplayName, mtxName, desc, maxPurchases, cost, extra stuff, total stuff | ||
local ROW_TEMPLATE = [[<tr> | local ROW_TEMPLATE = [=[<tr> | ||
<td> | <td>[[File:%s.png|50px]]</td> | ||
<td>%s</td> | <td>%s</td> | ||
<td>%s</td> | <td>%s</td> | ||
<td style="text-align:center;">%s</td> | <td style="text-align:center;">%s</td> | ||
<td>'''Base:''' %d%s%s</td> | <td>'''Base:''' %d%s%s</td> | ||
</tr>]] | </tr>]=] | ||
-- Trim whitespace from args, and treat blank args as nil | -- Trim whitespace from args, and treat blank args as nil | ||
Line 37: | Line 24: | ||
return s | return s | ||
end | end | ||
end | |||
-- Convert underscores to spaces | |||
local function underscore_to_space(s) | |||
return s:gsub('_+', ' ') | |||
end | |||
-- Convert to title capitalization | |||
local function toTitleCase(str) | |||
return (str:gsub("(%a)([%w_']*)", function(first, rest) return first:upper()..rest:lower() end)) | |||
end | |||
-- Convert raw 4d MTXinfo to 2d table | |||
local function mtxinfo_to_2dtable(mtxinfo) | |||
local data = {} | |||
local index = 1 | |||
for tabno, tab in ipairs(mtxinfo) do | |||
for sectionno, section in ipairs(tab) do | |||
for itemno, item in ipairs(section) do | |||
data[index] = { | |||
tabno = tabno, | |||
sectionno = sectionno, | |||
itemno = itemno, | |||
display = item[1], | |||
name = toTitleCase(underscore_to_space(item[2])), | |||
description = underscore_to_space(item[3]), | |||
cost = tonumber(item[4]), | |||
no = tonumber(item[5]), | |||
maxPurchases = tonumber(item[6]), | |||
qty = tonumber(item[7]), | |||
costIncrement = tonumber(item[8]) | |||
} | |||
index = index + 1 | |||
end | |||
end | |||
end | |||
return data | |||
end | end | ||
function p.bySections(frame) | function p.bySections(frame) | ||
local args = frame.args | local args = frame.args | ||
local | local tab_number = tonumber(preprocessArg(args.tab_number)) + 1 | ||
local | local section_number = tonumber(preprocessArg(args.section_number)) | ||
local ret = "" | local ret = "" | ||
local data = mtxinfo_to_2dtable(mtxinfo) | |||
for _, item in pairs(data) do | for _, item in pairs(data) do | ||
if item.tabno == tab_number and item.sectionno == section_number and item.display ~= "Blank" then | |||
if item. | local maxPurchases = item.maxPurchases == 100000 and "∞" or item.maxPurchases | ||
local extra = item.costIncrement > 0 and string.format([[<br/>'''Increment:''' %d<br/>'''Final:''' %d]], item.costIncrement, item.cost + item.costIncrement * (item.maxPurchases - 1)) or "" | |||
local total = (1 < item.maxPurchases and item.maxPurchases < 100000) and string.format([[<br/>'''Total:''' %d]], (item.maxPurchases / 2) * (item.cost * 2 + item.costIncrement * (item.maxPurchases - 1))) or "" | |||
ret = ret .. string.format( | |||
ROW_TEMPLATE, | |||
item.display, | |||
item.name, | |||
item.description, | |||
maxPurchases, | |||
item.cost, | |||
extra, | |||
total | |||
) | |||
end | |||
end | end | ||
Latest revision as of 06:16, 29 July 2024
The data is raw data without any conversion
Maintenance Procedure: simply update the return value of ha.MTXinfo() in N.js
local mtxinfo = mw.loadJsonData('Module:Gemshop/MTXinfo.json')
local p = {}
-- Gemshop/data.json is return value of ha.MTXinfo() in N.js without any conversion
-- itemDisplayName, mtxName, desc, maxPurchases, cost, extra stuff, total stuff
local ROW_TEMPLATE = [=[<tr>
<td>[[File:%s.png|50px]]</td>
<td>%s</td>
<td>%s</td>
<td style="text-align:center;">%s</td>
<td>'''Base:''' %d%s%s</td>
</tr>]=]
-- Trim whitespace from args, and treat blank args as nil
local function preprocessArg(s)
if not s then
return nil
end
s = s:match('^%s*(.-)%s*$') -- trim whitespace
if s == '' then
return nil
else
return s
end
end
-- Convert underscores to spaces
local function underscore_to_space(s)
return s:gsub('_+', ' ')
end
-- Convert to title capitalization
local function toTitleCase(str)
return (str:gsub("(%a)([%w_']*)", function(first, rest) return first:upper()..rest:lower() end))
end
-- Convert raw 4d MTXinfo to 2d table
local function mtxinfo_to_2dtable(mtxinfo)
local data = {}
local index = 1
for tabno, tab in ipairs(mtxinfo) do
for sectionno, section in ipairs(tab) do
for itemno, item in ipairs(section) do
data[index] = {
tabno = tabno,
sectionno = sectionno,
itemno = itemno,
display = item[1],
name = toTitleCase(underscore_to_space(item[2])),
description = underscore_to_space(item[3]),
cost = tonumber(item[4]),
no = tonumber(item[5]),
maxPurchases = tonumber(item[6]),
qty = tonumber(item[7]),
costIncrement = tonumber(item[8])
}
index = index + 1
end
end
end
return data
end
function p.bySections(frame)
local args = frame.args
local tab_number = tonumber(preprocessArg(args.tab_number)) + 1
local section_number = tonumber(preprocessArg(args.section_number))
local ret = ""
local data = mtxinfo_to_2dtable(mtxinfo)
for _, item in pairs(data) do
if item.tabno == tab_number and item.sectionno == section_number and item.display ~= "Blank" then
local maxPurchases = item.maxPurchases == 100000 and "∞" or item.maxPurchases
local extra = item.costIncrement > 0 and string.format([[<br/>'''Increment:''' %d<br/>'''Final:''' %d]], item.costIncrement, item.cost + item.costIncrement * (item.maxPurchases - 1)) or ""
local total = (1 < item.maxPurchases and item.maxPurchases < 100000) and string.format([[<br/>'''Total:''' %d]], (item.maxPurchases / 2) * (item.cost * 2 + item.costIncrement * (item.maxPurchases - 1))) or ""
ret = ret .. string.format(
ROW_TEMPLATE,
item.display,
item.name,
item.description,
maxPurchases,
item.cost,
extra,
total
)
end
end
return ret
end
return p