bugfix250107.1
全站通知:

模块:礼包数据转json

来自恋与深空WIKI_BWIKI_哔哩哔哩
跳到导航 跳到搜索

此模块的文档可以在模块:礼包数据转json/doc创建

local p = {}

function p.toJSON(frame)
    local result = {}
	
	for key, value in pairs(frame.args) do
		
        local key = key:match("^道具%-(.+)$")
        if key and value then
            result[key] = tonumber(value)
        end
	end

    return mw.text.jsonEncode(result)
end

function p.randomItemToJSON(frame)
	local parentArgs = frame:getParent().args
	local random_items = {}	

    -- for key, value in pairs(parentArgs) do
    -- 	key = tostring(key)
    -- 	if key:match("^随机道具%-") and value then
	   --     local index, name = key:match("^随机道具%-(%d+)%*(.+)$")
	   --     if name and value then
	   --         local quantity, chance = value:match("([%d%.]+)%*([%d%.]+)")
	   --         if quantity and chance then
	   --             table.insert(random_items, {
	   --                 ["名称"] = name,
	   --                 ["数量"] = tonumber(quantity),
	   --                 ["概率"] = tonumber(chance)
	   --             })
	   --         end
	   --     end
    -- 	end
    -- end
    
    -- local json = mw.text.jsonEncode(random_items)
    return parentArgs["随机道具-1*极空许愿券"]
end 

return p