模块:Hydrogina/sandbox/WeedyJsonDecode

可在模块:Hydrogina/sandbox/WeedyJsonDecode/doc创建此模块的帮助文档

p={}

publicframe=nil

strtemplate=[[{{高级凭证区商品一览
|当期6星=##s_op_1##
|当期5星=##s_op_2##
|当期中坚6星=##k_op_1##
|当期中坚5星=##k_op_2##
|当期5星信物1=##5token_1##
|当期5星信物2=##5token_2##
|当期6星信物1=##6token_1##
|当期6星信物2=##6token_2##
|当期素材1=##mat_1##
|当期素材2=##mat_2##
|当期素材3=##mat_3##
|当期素材4=##mat_4##
|当期素材5=##mat_5##
|当期素材6=##mat_6##
|寻访池开启时间=##s_st##
|寻访池关闭时间=##s_et##
|中坚寻访池开启时间=##k_st##
|中坚寻访池关闭时间=##k_et##
|启用中坚甄选=##k_select##
}}
]]

local k_select = false

function usetemplate_shop_high(goodList,s_st,s_et,k_st,k_et)
	
	local rtn=strtemplate
	
	local replaceData = {}
	local f_5token = nil
	
	for k, good in pairs(goodList) do
		--s
		if k<=2 then
			replaceData["s_op_"..k] = good["displayName"]
		end
		--k
		if k==3 or k==4 then
			if string.find(good["displayName"], "中坚甄选") then
				k_select = true
				replaceData["k_op_"..k-2] = good["displayName"]
			elseif good["goodType"]=="PROGRESS" then
				replaceData["k_op_"..k-2] = "NONE"
			elseif good["item"]["type"] == "CHAR" then
				replaceData["k_op_"..k-2] = good["displayName"]
			else
				replaceData["k_op_"..k-2] = "NONE"
			end
		end
		--mark 5token
		if good["displayName"] and string.find(good["displayName"], "遗产信物") and not f_5token then
			f_5token = k
		end
		--5token so on
		if f_5token and k>=f_5token then
			local delta = k-f_5token+1
			if delta<=2 then
				--5token
				replaceData["5token_"..delta] = string.gsub(good["displayName"],"遗产信物","")
			elseif delta==3 or delta==4 then
				--6token
				replaceData["6token_"..delta-2] = string.gsub(good["displayName"],"皇家信物","")
			elseif delta>4 then
				--mat
				replaceData["mat_"..delta-4] = good["displayName"]
			end
		end
	end
	
	for k,v in pairs(replaceData) do
		rtn=string.gsub(rtn,"##"..k.."##", v)
	end
	
	rtn=string.gsub(rtn,"##s_st##",s_st)
	rtn=string.gsub(rtn,"##s_et##",s_et)
	rtn=string.gsub(rtn,"##k_st##",k_st)
	rtn=string.gsub(rtn,"##k_et##",k_et)
	rtn=string.gsub(rtn,"##k_select##", k_select and "true" or "false")
	rtn=string.gsub(rtn,"##.-##","")
	
	return rtn
end

function p.shop_high(frame)
	local args = (frame == mw.getCurrentFrame() and frame.args) or frame
	local rtn=""
	publicframe=frame
	
	local s=args[1]
	
	if(args["s"])then
		s=args["s"]
	end
	
	if(args["s_st"])then s_st=args["s_st"] else s_st="" end
	if(args["s_et"])then s_et=args["s_et"] else s_et="" end
	if(args["k_st"])then k_st=args["k_st"] else k_st="" end
	if(args["k_et"])then k_et=args["k_et"] else k_et="" end
	
	local jsontable=mw.text.jsonDecode(s)
	
	local goodList=jsontable["goodList"]
	
	rtn=rtn..usetemplate_shop_high(goodList,s_st,s_et,k_st,k_et)
	
	if(args["run"])then
		rtn=frame:preprocess( rtn )
	end
	
	return rtn
end

announcement_head='<tabber>\n'
announcement_end='</tabber>\n'
announcement_template=[[|-|
##i##=
==##title##==
{{#widget:Iframe
|url=##webUrl##
|width=800
|height=436
|border=0
}}
]]

function usetemplate_announcement(announceList,targetgroup)
	
	local rtn=''
	
	for i = 1, #announceList do

		local announce=announceList[i]
		local webUrl=announce['webUrl']
		local title=announce['title']
		title=string.gsub(title,'\n','')
		local group=announce['group']
		
		if(targetgroup=="" or targetgroup==group)then
			local temp=announcement_template
			
			temp=string.gsub(temp,'##i##',tostring(i))
			temp=string.gsub(temp,'##title##',title)
			temp=string.gsub(temp,'##webUrl##',webUrl)
			
			rtn=rtn..temp
		end
	end
	
	rtn=string.gsub(rtn,"##.-##","")
	
	rtn=announcement_head..rtn..announcement_end
	
	return rtn
end

function p.announcement(frame)
	local args = (frame == mw.getCurrentFrame() and frame.args) or frame
	local rtn=""
	publicframe=frame
	
	local s=args[1]
	
	if(args["s"])then
		s=args["s"]
	end
	
	local targetgroup=""
	if(args["targetgroup"])then
		targetgroup=args["targetgroup"]
	end
	
	local jsontable=mw.text.jsonDecode(s)
	
	local announceList=jsontable["announceList"]
	
	rtn=rtn..usetemplate_announcement(announceList,targetgroup)
	
	if(args["run"])then
		rtn=frame:preprocess( rtn )
	end
	
	return rtn
end

function p.announce_event_new(frame)
	local args = (frame == mw.getCurrentFrame() and frame.args) or frame
	local rtn=""
	publicframe=frame
	
	local s=args[1]
	
	if(args["s"])then
		s=args["s"]
	end
	
	local key="活动"
	if(args["key"])then
		key=args["key"]
	end
	
	keylist=mw.text.split( key, ',', true )
	
	local jsontable=mw.text.jsonDecode(s)
	
	local announceList=jsontable["announceList"]
	
	for i = 1, #announceList do

		local announce=announceList[i]
		local webUrl=announce['webUrl']
		local title=announce['title']
		
		for j = 1, #keylist do
			local key=keylist[j]
			
			if(string.find(title,key))then
				rtn=webUrl
				return rtn
			end
		end
		
	end
	
	return rtn
end

function p.announce_event_decode(frame)
	local args = (frame == mw.getCurrentFrame() and frame.args) or frame
	local rtn=""
	publicframe=frame
	
	local s=args[1]
	
	if(args["s"])then
		s=args["s"]
	end
	
	raw=s
	
	str=string.match(raw,'<div class="main">.*</div>')

	str=string.gsub(str,'    ','')

	str=string.gsub(str,'<p>','')
	str=string.gsub(str,'</p>','\n\n')

	str=string.gsub(str,'<strong>',[[''']])
	str=string.gsub(str,'</strong>',[[''']])

	--str=string.gsub(str,'<img.->','')
	str=string.gsub(str,'<br/>','##temp##')
	str=string.gsub(str,'/>',' width="800"/>')
	str=string.gsub(str,'##temp##','<br/>')
	
	rtn=str
	
	return rtn
end

return p