Module:Gemshop: Difference between revisions

From IdleOn MMO Wiki
mNo edit summary
Tag: Reverted
m (Undo revision 74739 by Kiokurashi (talk))
Tags: Undo Reverted
Line 45: Line 45:
local ret = {}
local ret = {}
-- itemDisplayName, mtxName, desc, maxPurchases, cost, extra stuff, total stuff
-- 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>]=]
local tr    = "<tr>"
local file  = "<td>[[File:" -- Variable 1
local filec = ".png|50px]]</td>"
local td    = "<td>" -- Variable 2 & 3
local tdc  = "</td>"
local maxp  = "<td style='text-align:center;'>" -- Vatiable 4
local base  = "<td>'''Base:''' " --Variable 5, 6, & 7
local inc  = "<br/>'''Increment:''' "
local final = "<br/>'''Final:''' "
local total = "<br/>'''Total:''' "
local trc  = "</tr>"
for _, item in pairs(data) do
for _, item in pairs(data) do
Line 71: Line 52:
end
end
local function rowstr (entry)
local function rowstr (entry)
-- local maxPurchases = entry.maxPurchases == 100000 and "∞" or entry.maxPurchases
local maxPurchases = entry.maxPurchases == 100000 and "∞" or entry.maxPurchases
-- local extra = entry.costIncrement > 0 and string.format([[<br/>'''Increment:''' %d<br/>'''Final:''' %d]], entry.costIncrement, entry.cost + entry.costIncrement * (entry.maxPurchases - 1)) or ""
local extra = entry.costIncrement > 0 and string.format([[<br/>'''Increment:''' %d<br/>'''Final:''' %d]], entry.costIncrement, entry.cost + entry.costIncrement * (entry.maxPurchases - 1)) or ""
-- local total = (1 < entry.maxPurchases and entry.maxPurchases < 100000) and string.format([[<br/>'''Total:''' %d]], ) or ""
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 ""
local namesub = string.sub(entry.name, 1, 3)
local namesub = string.sub(entry.name, 1, 3)
local image = (namesub == "Gem" or namesub == "Pda") and entry.mtxName or entry.itemDisplayName ret[#ret+1] = tr
local image = (namesub == "Gem" or namesub == "Pda") and entry.mtxName or entry.itemDisplayName
ret[#ret+1] = file
ret[#ret+1] = image -- Image
ret[#ret+1] = filec
ret[#ret+1] = td
ret[#ret+1] = entry.mtxName -- mtxName
ret[#ret+1] = tdc
ret[#ret+1] = td
ret[#ret+1] = entry.desc -- desc
ret[#ret+1] = tdc
ret[#ret+1] = maxp
ret[#ret+1] = entry.maxPurchases < 100000 and entry.maxPurchases or "∞" -- maxPurchases
ret[#ret+1] = tdc
ret[#ret+1] = base
ret[#ret+1] = entry.cost
if entry.costIncrement > 0 then
ret[#ret+1] = inc
ret[#ret+1] = entry.costIncrement
ret[#ret+1] = final
ret[#ret+1] = entry.cost + entry.costIncrement * (entry.maxPurchases - 1)
end
if 1 < entry.maxPurchases and entry.maxPurchases < 100000 then
ret[#ret+1] = total
ret[#ret+1] = (entry.maxPurchases / 2) * (entry.cost * 2 + entry.costIncrement * (entry.maxPurchases - 1))
end
ret[#ret+1] = tdc
ret[#ret+1] = trc
-- if namesub == "Gem" or namesub == "Pda" then
-- if namesub == "Gem" or namesub == "Pda" then
-- image = entry.mtxName
-- image = entry.mtxName
Line 108: Line 63:
-- end
-- end
-- return string.format(
return string.format(
    --        ROW_TEMPLATE,
            ROW_TEMPLATE,
    --      image,
            image,
    --        entry.mtxName,
            entry.mtxName,
    --        entry.desc,
            entry.desc,
    --        maxPurchases,
            maxPurchases,
    --        entry.cost,
            entry.cost,
    --        extra,
            extra,
    --        total
            total
    --    )
        )
     end
     end
for _, itemdata in pairs(tabledata) do
for _, itemdata in pairs(tabledata) do
rowstr(itemdata)
ret[#ret+1] = rowstr(itemdata)
end
end



Revision as of 13:51, 6 March 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 data = mw.loadJsonData('Module:Gemshop/data.json')
local p = {}

-- 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>]=]

-- 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
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

function p.bySections(frame)
	local args = frame.args
	local section = preprocessArg(args.section)
	local tabledata = {}
	local ret = {}
	-- itemDisplayName, mtxName, desc, maxPurchases, cost, extra stuff, total stuff
	
	for _, item in pairs(data) do
		if item.section == section then
			tabledata[#tabledata+1] = item
		end
	end
	local function rowstr (entry)
		local maxPurchases = entry.maxPurchases == 100000 and "∞" or entry.maxPurchases
		local extra = entry.costIncrement > 0 and string.format([[<br/>'''Increment:''' %d<br/>'''Final:''' %d]], entry.costIncrement, entry.cost + entry.costIncrement * (entry.maxPurchases - 1)) or ""
		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 ""
		local namesub = string.sub(entry.name, 1, 3)
		local image = (namesub == "Gem" or namesub == "Pda") and entry.mtxName or entry.itemDisplayName
	--	if namesub == "Gem" or namesub == "Pda" then
	--		image = entry.mtxName
	--	else 
	--		image = entry.itemDisplayName
	--	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

	return table.concat(ret)
	
end

return p