Module:Gemshop: Difference between revisions

From IdleOn MMO Wiki
mNo edit summary
Tag: Manual revert
mNo edit summary
 
(18 intermediate revisions by 2 users not shown)
Line 1: Line 1:
local data = mw.loadJsonData('Module:Gemshop/data.json')
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>\[\[File:%s.png|50px\]\]</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>]=]
 
-- Gemshop data format.
--    {
--        "section": "Hats",
--        "name": "EquipmentHats46",
--        "mtxName": "Strawbiggy",
--        "itemDisplayName": "Strawbiggy",
--        "desc": "This is the ACTUAL strawberry from the Buddhist story about the Tiger and the Strawberry. No wonder the dangling man thought it so tasty!",
--        "cost": 250,
--        "no": 3,
--        "maxPurchases": 100000,
--        "qty": 1,
--        "costIncrement": 0
--    },
 


-- 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 section = preprocessArg(args.section)
local tab_number = tonumber(preprocessArg(args.tab_number)) + 1
local tabledata
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
mw.logObject(item)
if item.tabno == tab_number and item.sectionno == section_number and item.display ~= "Blank" then
if item.section == section then
            local maxPurchases = item.maxPurchases == 100000 and "∞" or item.maxPurchases
tabledata[#tabledata+1] = item
            local extra = item.costIncrement > 0 and string.format([[<br/>'''Increment:''' %d<br/>'''Final:''' %d]], item.costIncrement, item.cost + item.costIncrement * (item.maxPurchases - 1)) or ""
end
            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 ""
end
           
            ret = ret .. string.format(
for itemdata in tabledata do
                ROW_TEMPLATE,
local maxPurchases = itemdata.maxPurchases == 100000 and "∞" or itemdata.maxPurchases
                item.display,
local extra = itemdata.costIncrement > 0 and string.format([[<br/>'''Increment:''' %d<br/>'''Final:''' %d]], itemdata.costIncrement, itemdata.cost + itemdata.costIncrement * (itemdata.maxPurchases - 1)) or ""
                item.name,
local total = (1 < itemdata.maxPurchases < 100000) and string.format([[br/>'''Total:''' %d]], (itemdata.maxPurchases / 2) * (itemdata.cost * 2 + itemdata.costIncrement * (itemdata.maxPurchases - 1))) or ""
                item.description,
 
                maxPurchases,
ret = ret .. string.format(
                item.cost,
            ROW_TEMPLATE,
                extra,
            itemdata.itemDisplayName,
                total
            itemdata.mtxName,
             )
            itemdata.desc,
         end
            maxPurchases,
            itemdata.cost,
            extra,
             total
         )
end
end



Latest revision as of 06:16, 29 July 2024

Data Here

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