Module:CraftingTable: Difference between revisions

From Ylvapedia
(新規)
 
mNo edit summary
Line 201: Line 201:
local Skills = ''
local Skills = ''


if Craftingskill == '' then
if not Craftingskill then
Skills = '?'..data[lang]['TitleSkill']
Skills = '?'..data[lang]['TitleSkill']
else
else
Line 210: Line 210:
Skills = Skills .. ' '
Skills = Skills .. ' '


if CraftingskillLv == '' then
if not CraftingskillLv then
Skills = Skills .. 'Lv.?'
Skills = Skills .. 'Lv.?'
else
else

Revision as of 16:53, 6 February 2025

Documentation for this module may be created at Module:CraftingTable/doc

local p = {}

function p.crafttable(f)

	local args = f:getParent().args
	local lang = f.args[1]
	local data = mw.loadData('Module:CraftingTable/i18n')

--Recipe1
	local CSs = ''
	if not args[data[lang]['CraftingStation']] then
		error( data[lang]['ErrorCraftingStation'] )
	else
		f:callParserFunction( '#Set', 'CraftingStation', args[data[lang]['CraftingStation']] )
		local v = {} ; v = mw.text.split(args[data[lang]['CraftingStation']], "%s*,%s*")
		for i, item in ipairs(v) do
			if i > 1 then CSs = CSs .. '<br />' end
			if item ~= '' then
				CSs = CSs .. f:expandTemplate{ title = data[lang]['TemplateName'], args = { item } }
			else
				CSs = CSs .. data[lang]['BlankValue']
			end
		end
	end

	local Ings = ''
	if not args[data[lang]['Ingredient']] then
		error( data[lang]['ErrorIngredient'] )
	else
		f:callParserFunction( '#Set', 'Ingredient', args[data[lang]['Ingredient']] )
		local v = {} ; v = mw.text.split(args[data[lang]['Ingredient']], "%s*,%s*")
		if not args[data[lang]['IngredientNum']] then
			error( data[lang]['ErrorIngredientNum'] )
		else
			f:callParserFunction( '#Set', 'IngredientNum', args[data[lang]['IngredientNum']] )
			local x = {} ; x = mw.text.split(args[data[lang]['IngredientNum']], "%s*,%s*")
			local y = {}
			local check
			if args[data[lang]['IngredientExtra']] then
				f:callParserFunction( '#Set', 'IngredientExtra', args[data[lang]['IngredientExtra']] )
				y = mw.text.split(args[data[lang]['IngredientExtra']], "%s*,%s*")
			end
			for i, item in ipairs(v) do
				if i > 1 and check == false then Ings = Ings .. '<br />' end
				check = false
				if item ~= '' then
					local z = string.find(item, "%s*/%s*")
					if z then
						local z = {} ; z = mw.text.split(item, "%s*/%s*")
						local z2 = {} ; z2 = mw.text.split(x[i], "%s*/%s*") or 1
						for i2, item2 in ipairs(z) do
							if i2 > 1 then Ings = Ings .. '<div class="or-separator">or</div>' end
							Ings = Ings .. f:expandTemplate{ title = data[lang]['TemplateName'], args = { item2,z2[i2] } }
						end
						Ings = Ings .. '<div class="separator">&nbsp;</div>'
						check = true
					else
						Ings = Ings .. f:expandTemplate{ title = data[lang]['TemplateName'], args = { item,x[i] } }
					end
					
					if y[i] == data[lang]['TitleExtra'] then
						Ings = Ings .. data[lang]['TextExtra']
					elseif y[i] == data[lang]['TitleGourmet'] then
						Ings = Ings .. data[lang]['TextGourmet']
					end
				else
					Ings = Ings .. data[lang]['BlankValue']
				end
			end
		end
	end
--Recipe2
	local CSs2 = ''
	if not args[data[lang]['CraftingStation']..'2'] then
	else
		f:callParserFunction( '#Set', 'CraftingStation2', args[data[lang]['CraftingStation']..'2'] )
		local v = {} ; v = mw.text.split(args[data[lang]['CraftingStation']..'2'], "%s*,%s*")
		for i, item in ipairs(v) do
			if i > 1 then CSs2 = CSs2 .. '<br />' end
			if item ~= '' then
				CSs2 = CSs2 .. f:expandTemplate{ title = data[lang]['TemplateName'], args = { item } }
			else
				CSs2 = CSs2 .. data[lang]['BlankValue']
			end
		end
	end

	local Ings2 = ''
	if not args[data[lang]['Ingredient']..'2'] then
	else
		f:callParserFunction( '#Set', 'Ingredient2', args[data[lang]['Ingredient']..'2'] )
		local v = {} ; v = mw.text.split(args[data[lang]['Ingredient']..'2'], "%s*,%s*")
		if not args[data[lang]['IngredientNum']..'2'] then
		else
			f:callParserFunction( '#Set', 'IngredientNum2', args[data[lang]['IngredientNum']..'2'] )
			local x = {} ; x = mw.text.split(args[data[lang]['IngredientNum']..'2'], "%s*,%s*")
			local y = {}
			local check
			if args[data[lang]['IngredientExtra']..'2'] then
				f:callParserFunction( '#Set', 'IngredientExtra2', args[data[lang]['IngredientExtra']..'2'] )
				y = mw.text.split(args[data[lang]['IngredientExtra']..'2'], "%s*,%s*")
			end
			for i, item in ipairs(v) do
				if i > 1 and check == false then Ings2 = Ings2 .. '<br />' end
				check = false
				if item ~= '' then
					local z = string.find(item, "%s*/%s*")
					if z then
						local z = {} ; z = mw.text.split(item, "%s*/%s*")
						local z2 = {} ; z2 = mw.text.split(x[i], "%s*/%s*") or 1
						for i2, item2 in ipairs(z) do
							if i2 > 1 then Ings2 = Ings2 .. '<div class="or-separator">or</div>' end
							Ings2 = Ings2 .. f:expandTemplate{ title = data[lang]['TemplateName'], args = { item2,z2[i2] } }
						end
						Ings2 = Ings2 .. '<div class="separator">&nbsp;</div>'
						check = true
					else
						Ings2 = Ings2 .. f:expandTemplate{ title = data[lang]['TemplateName'], args = { item,x[i] } }
					end
					
					if y[i] == data[lang]['TitleExtra'] then
						Ings2 = Ings2 .. data[lang]['TextExtra']
					elseif y[i] == data[lang]['TitleGourmet'] then
						Ings2 = Ings2 .. data[lang]['TextGourmet']
					end
				else
					Ings2 = Ings2 .. data[lang]['BlankValue']
				end
			end
		end
	end
--Recipe3
	local CSs3 = ''
	if not args[data[lang]['CraftingStation']..'3'] then
	else
		f:callParserFunction( '#Set', 'CraftingStation3', args[data[lang]['CraftingStation']..'3'] )
		local v = {} ; v = mw.text.split(args[data[lang]['CraftingStation']..'3'], "%s*,%s*")
		for i, item in ipairs(v) do
			if i > 1 then CSs3 = CSs3 .. '<br />' end
			if item ~= '' then
				CSs3 = CSs3 .. f:expandTemplate{ title = data[lang]['TemplateName'], args = { item } }
			else
				CSs3 = CSs3 .. data[lang]['BlankValue']
			end
		end
	end

	local Ings3 = ''
	if not args[data[lang]['Ingredient']..'3'] then
	else
		f:callParserFunction( '#Set', 'Ingredient3', args[data[lang]['Ingredient']..'3'] )
		local v = {} ; v = mw.text.split(args[data[lang]['Ingredient']..'3'], "%s*,%s*")
		if not args[data[lang]['IngredientNum']..'3'] then
		else
			f:callParserFunction( '#Set', 'IngredientNum3', args[data[lang]['IngredientNum']..'3'] )
			local x = {} ; x = mw.text.split(args[data[lang]['IngredientNum']..'3'], "%s*,%s*")
			local y = {}
			local check
			if args[data[lang]['IngredientExtra']..'3'] then
				f:callParserFunction( '#Set', 'IngredientExtra3', args[data[lang]['IngredientExtra']..'3'] )
				y = mw.text.split(args[data[lang]['IngredientExtra']..'3'], "%s*,%s*")
			end
			for i, item in ipairs(v) do
				if i > 1 and check == false then Ings3 = Ings3 .. '<br />' end
				check = false
				if item ~= '' then
					local z = string.find(item, "%s*/%s*")
					if z then
						local z = {} ; z = mw.text.split(item, "%s*/%s*")
						local z2 = {} ; z2 = mw.text.split(x[i], "%s*/%s*") or 1
						for i2, item2 in ipairs(z) do
							if i2 > 1 then Ings3 = Ings3 .. '<div class="or-separator">or</div>' end
							Ings3 = Ings3 .. f:expandTemplate{ title = data[lang]['TemplateName'], args = { item2,z2[i2] } }
						end
						Ings3 = Ings3 .. '<div class="separator">&nbsp;</div>'
						check = true
					else
						Ings3 = Ings3 .. f:expandTemplate{ title = data[lang]['TemplateName'], args = { item,x[i] } }
					end
					
					if y[i] == data[lang]['TitleExtra'] then
						Ings3 = Ings3 .. data[lang]['TextExtra']
					elseif y[i] == data[lang]['TitleGourmet'] then
						Ings3 = Ings3 .. data[lang]['TextGourmet']
					end
				else
					Ings2 = Ings3 .. data[lang]['BlankValue']
				end
			end
		end
	end

	local Craftingskill = args[data[lang]['CraftSkill']] or nil
	local CraftingskillLv = args[data[lang]['CraftSkillLv']] or nil

	local html = mw.html.create('p')
	local div = html:tag('div'):addClass('CraftingTable'):cssText('float: left; display: ruby;')
	local table = div:tag('table'):addClass('wikitable')
		if not Craftingskill and not CraftingskillLv then
		else
			local Skills = ''

			if not Craftingskill then
				Skills = '?'..data[lang]['TitleSkill']
			else
				Skills = Craftingskill..data[lang]['TitleSkill']
				f:callParserFunction( '#Set', 'CraftingSkill', Craftingskill )
			end

			Skills = Skills .. '&nbsp;'

			if not CraftingskillLv then
				Skills = Skills .. 'Lv.?'
			else
				Skills = Skills .. 'Lv.'.. CraftingskillLv
				f:callParserFunction( '#Set', 'CraftingSkillLv', CraftingskillLv )
			end

			table:tag('tr'):tag('th'):attr('colspan',2):wikitext(Skills)
		end
		table:tag('tr'):tag('th'):wikitext(string.format(data[lang]['TitleCraftingStation'])):tag('th'):wikitext(string.format(data[lang]['TitleIngredient']))
		:tag('tr'):tag('td'):wikitext(CSs):tag('td'):wikitext(Ings)

		if Ings2 ~= '' then
			local table2 = div:tag('table'):addClass('wikitable'):cssText('margin-left:1em;')
			table2:tag('tr'):tag('th'):wikitext(string.format(data[lang]['TitleCraftingStation'])):tag('th'):wikitext(string.format(data[lang]['TitleIngredient']))
			:tag('tr'):tag('td'):wikitext(CSs2):tag('td'):wikitext(Ings2)
		end

		if Ings3 ~= '' then
			local table3 = div:tag('table'):addClass('wikitable'):cssText('margin-left:1em;')
			table3:tag('tr'):tag('th'):wikitext(string.format(data[lang]['TitleCraftingStation'])):tag('th'):wikitext(string.format(data[lang]['TitleIngredient']))
			:tag('tr'):tag('td'):wikitext(CSs3):tag('td'):wikitext(Ings3)
		end

		html:wikitext(string.format('<div style="clear:both;"></div>'))

		local ObtainRecipe = args[data[lang]['ObtainRecipe']] or nil
		if not ObtainRecipe then
		else
			html:wikitext(string.format('<h3>'.. data[lang]['TitleObtainRecipe'] ..'</h3>' .. ObtainRecipe))
			f:callParserFunction( '#Set', 'ObtainRecipe', ObtainRecipe )
		end

		local title = mw.title.getCurrentTitle()
		if title.nsText == "Elin" then
			html:wikitext(string.format(data[lang]['Category']))
		end

	return tostring(html)
	
end

return p