Module:Gemshop

From IdleOn MMO Wiki
Revision as of 04:19, 4 March 2024 by Kiokurashi (talk | contribs) (Created page with "local data = mw.loadData('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>]] -- GemData format. -- { -- "section": "Hats", -- "name": "EquipmentHats46", -- "mtxName": "Strawbiggy", -- "itemDisplayName": "Strawbi...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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.loadData('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>]]

-- GemData 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 = preprocessing(args.section)
	local tabledata
	local ret = ""
	
	for item in data do
		if item[section] == section then
			tabledata[#tabledata+1] = item
		end
	end
	
	for itemdata in tabledata do
		local maxPurchases = itemdata.maxPurchases == 100000 and "∞" or itemdata.maxPurchases
		local extra = itemdata.costIncrement > 0 and string.format([[<br/>'''Increment:''' %d<br/>'''Final:''' %d]], itemdata.costIncrement, itemdata.cost + itemdata.costIncrement * (itemdata.maxPurchases - 1)) or ""
		local total = (1 < itemdata.maxPurchases < 100000) and string.format([[br/>'''Total:''' %d]], (itemdata.maxPurchases / 2) * (itemdata.cost * 2 + itemdata.costIncrement * (itemdata.maxPurchases - 1))) or ""

		ret = ret .. string.format(
            ROW_TEMPLATE,
            itemdata.itemDisplayName,
            itemdata.mtxName,
            itemdata.desc,
            maxPurchases,
            itemdata.cost,
            extra,
            total
        )
	end

	return ret
	
end


local example = [[
function p.main(frame)
    local args = frame.args
    local character = preprocessArg(args[1])
    local trait = preprocessArg(args[2])

    -- Check for blank character arguments
    if not character then
        return ''
    end

    -- Get the data for the specified character
    local characterData = data[character]
    if not characterData then
        return ''
    end

    if trait then
        -- User specified a trait, so return it
        return characterData[trait] or ''
    else
        -- Return the biography template with all the traits in it
        return string.format(
            BIO_TEMPLATE,
            character,
            characterData.Age,
            characterData.Personality
        )
    end
end
]]
return p