Module:Gemshop: Difference between revisions

From IdleOn MMO Wiki
mNo edit summary
Tag: Reverted
mNo edit summary
 
(5 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
Line 10: Line 12:
<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 = ""
-- itemDisplayName, mtxName, desc, maxPurchases, cost, extra stuff, total stuff
    local data = mtxinfo_to_2dtable(mtxinfo)
for _, item in pairs(data) do
for _, item in pairs(data) do
if item.section == section then
if item.tabno == tab_number and item.sectionno == section_number and item.display ~= "Blank" then
tabledata[#tabledata+1] = item
            local maxPurchases = item.maxPurchases == 100000 and "∞" or item.maxPurchases
end
            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 ""
local function rowstr (entry)
           
local maxPurchases = entry.maxPurchases == 100000 and "∞" or entry.maxPurchases
            ret = ret .. string.format(
local extra = entry.costIncrement > 0 and string.format([[<br/>'''Increment:''' %d<br/>'''Final:''' %d]], entry.costIncrement, entry.cost + entry.costIncrement * (entry.maxPurchases - 1)) or ""
                ROW_TEMPLATE,
local total = (1 < entry.maxPurchases and entry.maxPurchases < 100000) and string.format([[<br/>'''Total:''' %d]], (entry.maxPurchases / 2) * (entry.cost * 2 + entry.costIncrement * (entry.maxPurchases - 1))) or ""
                item.display,
local namesub = string.sub(entry.name, 1, 3)
                item.name,
local image = (namesub == "Gem" or namesub == "Pda") and entry.mtxName or entry.itemDisplayName
                item.description,
-- if namesub == "Gem" or namesub == "Pda" then
                maxPurchases,
-- image = entry.mtxName
                item.cost,
-- else
                extra,
-- image = entry.itemDisplayName
                total
-- end
            )
        end
return string.format(
            ROW_TEMPLATE,
            image,
            entry.mtxName,
            entry.desc,
            maxPurchases,
            entry.cost,
            extra,
            total
        )
    end
for _, itemdata in pairs(tabledata) do
ret[#ret+1] = rowstr(itemdata)
end
end


return table.concat(ret)
return ret
end
end


return p
return p

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