Module:CraftingTable: Difference between revisions
Neko Knight (talk | contribs) No edit summary |
Neko Knight (talk | contribs) No edit summary |
||
Line 1: | Line 1: | ||
local p = {} | local p = {} | ||
local function isBlank(value) | |||
return value == nil or not value or value == '' | |||
end | |||
function p.crafttable(f) | function p.crafttable(f) | ||
Line 31: | Line 35: | ||
} | } | ||
local CSs = { '', '', '' } | local CSs = { '','','' } | ||
local CSCategory = '' | local CSCategory = '' | ||
local Ings = { '', '', '' } | local Ings = { '','','' } | ||
local Results = { '', '', '' } | local Results = { '','','' } | ||
for | for tableNum = 1, 3 ,1 do | ||
if | if isBlank(Recipe[tableNum].CraftingStation) then | ||
if | if tableNum == 1 then CSs[1] = data[lang]['ErrorCraftingStation'] end | ||
else | else | ||
local v = {} ; v = mw.text.split(Recipe[ | local v = {} ; v = mw.text.split(Recipe[tableNum].CraftingStation,'%s*,%s*') | ||
f:callParserFunction( '#Set', 'CraftingStation', Recipe[ | f:callParserFunction('#Set','CraftingStation'..tableNum,Recipe[tableNum].CraftingStation) | ||
for i, item in ipairs(v) do | for i, item in ipairs(v) do | ||
if i > 1 then CSs[ | if i > 1 then CSs[tableNum] = CSs[tableNum]..'<br />' end | ||
if | if isBlank(item) then | ||
CSs[ | CSs[tableNum] = CSs[tableNum]..data[lang]['BlankValue'] | ||
else | else | ||
CSs[ | CSs[tableNum] = CSs[tableNum]..f:expandTemplate{title=data[lang]['TemplateName'],args={item,size=imgsize}} | ||
if title.nsText == | if title.nsText == 'Elin' then | ||
CSCategory = CSCategory..'[[Category:Elin '..item..']]' | CSCategory = CSCategory..'[[Category:Elin '..item..']]' | ||
end | end | ||
Line 58: | Line 62: | ||
end | end | ||
if | if isBlank(Recipe[tableNum].Ingredient) then | ||
if | if tableNum == 1 then Ings[1] = data[lang]['ErrorIngredient'] end | ||
else | else | ||
local | local Ing = {} ; Ing = mw.text.split(Recipe[tableNum].Ingredient,'%s*,%s*') | ||
local | local IngN = {} ; IngN = mw.text.split(Recipe[tableNum].IngredientNum,'%s*,%s*') | ||
local | local IngE = {} ; IngE = mw.text.split(Recipe[tableNum].IngredientExtra,'%s*,%s*') or '' | ||
f:callParserFunction( '#Set', 'Ingredient', Recipe[ | f:callParserFunction('#Set','Ingredient'..tableNum,Recipe[tableNum].Ingredient) | ||
f:callParserFunction( '#Set', 'IngredientNum', Recipe[ | f:callParserFunction('#Set','IngredientNum'..tableNum,Recipe[tableNum].IngredientNum) | ||
f:callParserFunction( '#Set', 'IngredientExtra', Recipe[ | f:callParserFunction('#Set','IngredientExtra'..tableNum,Recipe[tableNum].IngredientExtra) | ||
for i, item in ipairs( | for i, item in ipairs(Ing) do | ||
if i > 1 then | if i > 1 then | ||
Ings[ | Ings[tableNum] = Ings[tableNum]..'<div class="plus or-separator">+</div>' | ||
end | end | ||
if | if isBlank(item) then | ||
Ings[ | Ings[tableNum] = Ings[tableNum]..data[lang]['BlankValue'] | ||
else | else | ||
if string.find(item,'/') then | |||
local z = {} ; z = mw.text.split(Ing[i],'%s*/%s*') | |||
local z = {} ; z = mw.text.split( | local z2 = {} ; if IngN[i] then z2 = mw.text.split(IngN[i],'%s*/%s*') or 1 end | ||
local z2 = {} ; z2 = mw.text.split( | local z3 = {} ; if IngE[i] then z3 = mw.text.split(IngE[i],'%s*/%s*') or '' end | ||
local z3 = {} ; z3 = mw.text.split( | |||
for i2, item2 in ipairs(z) do | for i2, item2 in ipairs(z) do | ||
local itemname = item2 | |||
local itemnum = z2[i2] or 1 | |||
local itemvar | |||
local itemext = z3[i2] or '' | |||
if i2 > 1 then | if i2 > 1 then | ||
Ings[ | Ings[tableNum] = Ings[tableNum]..'<div class="or-separator">'..data[lang]['Or']..'</div>' | ||
end | end | ||
if | |||
if string.find(item2,'@') then | |||
local v2 = {} ; v2 = mw.text.split(item2,'%s*@%s*') | |||
itemname = v2[1] | |||
itemvar = v2[2] | |||
end | end | ||
if | if isBlank(itemnum) then | ||
if itemvar then | |||
Ings[tableNum] = Ings[tableNum]..f:expandTemplate{title=data[lang]['TemplateName'],args={itemname,v=itemvar,link='Elin:'..itemname..' '..itemvar,size=imgsize}} | |||
else | |||
Ings[tableNum] = Ings[tableNum]..f:expandTemplate{title=data[lang]['TemplateName'],args={itemname,size=imgsize}} | |||
end | |||
else | else | ||
Ings[ | if itemvar then | ||
Ings[tableNum] = Ings[tableNum]..f:expandTemplate{title=data[lang]['TemplateName'],args={itemname,itemnum,v=itemvar,link='Elin:'..itemname..' '..itemvar,size=imgsize}} | |||
else | |||
Ings[tableNum] = Ings[tableNum]..f:expandTemplate{title=data[lang]['TemplateName'],args={itemname,itemnum,size=imgsize}} | |||
end | |||
end | end | ||
if itemext == data[lang]['TitleExtra'] then Ings[tableNum] = Ings[tableNum]..data[lang]['TextExtra'] | |||
elseif itemext == data[lang]['TitleGourmet'] then Ings[tableNum] = Ings[tableNum]..data[lang]['TextGourmet'] end | |||
end | end | ||
elseif string.find(item,'@') then | |||
local v2 = {} ; v2 = mw.text.split(item,'%s*@%s*') | |||
Ings[tableNum] = Ings[tableNum]..f:expandTemplate{title=data[lang]['TemplateName'],args={v2[1],v=v2[2],link='Elin:'..v2[1]..' '..v2[2],size=imgsize}} | |||
Ings[ | elseif isBlank(IngN[i]) then | ||
Ings[tableNum] = Ings[tableNum]..f:expandTemplate{title=data[lang]['TemplateName'],args={item,size=imgsize}} | |||
else | |||
Ings[tableNum] = Ings[tableNum]..f:expandTemplate{title=data[lang]['TemplateName'],args={item,IngN[i],size=imgsize}} | |||
end | end | ||
if IngE[i] == data[lang]['TitleExtra'] then Ings[tableNum] = Ings[tableNum]..data[lang]['TextExtra'] | |||
elseif IngE[i] == data[lang]['TitleGourmet'] then Ings[tableNum] = Ings[tableNum]..data[lang]['TextGourmet'] end | |||
end | end | ||
end | end | ||
end | end | ||
if | if isBlank(Recipe[tableNum].CraftResult) then | ||
else | else | ||
f:callParserFunction('#Set','CraftingResult'..tableNum, Recipe[tableNum].CraftResult) | |||
f:callParserFunction( '#Set', 'CraftingResult', Recipe[ | local itemtable = {} ; itemtable = mw.text.split(Recipe[tableNum].CraftResult,'%s*,%s*') | ||
for i, item in ipairs(itemtable) do | |||
if i > 1 then | |||
if | Results[tableNum] = Results[tableNum]..'<div class="or-separator">'..data[lang]['Or']..'</div>' | ||
local | end | ||
local itemname = item | |||
local itemnum = 1 | |||
local itemvar | |||
if string.find(itemname,'/') then | |||
local z = {} ; z = mw.text.split(itemname,'%s*/%s*') | |||
itemname = z[1] | |||
itemnum = z[2] | |||
if string.find(itemname,'@') then | |||
local z = {} ; z = mw.text.split(itemname,'%s*@%s*') | |||
itemname = z[1] | |||
itemvar = z[2] | |||
end | |||
elseif string.find(itemname,'@') then | |||
local z = {} ; z = mw.text.split(itemname,'%s*@%s*') | |||
itemname = z[1] | |||
itemvar = z[2] | |||
end | end | ||
if itemvar then | |||
if | Results[tableNum] = Results[tableNum]..f:expandTemplate{title=data[lang]['TemplateName'],args={itemname,itemnum,v=itemvar,link='Elin:'..itemname..' '..itemvar,size=imgsize}} | ||
else | else | ||
Results[ | Results[tableNum] = Results[tableNum]..f:expandTemplate{title=data[lang]['TemplateName'],args={itemname,itemnum,size=imgsize}} | ||
end | end | ||
end | end | ||
Line 156: | Line 183: | ||
local Skills = '' | local Skills = '' | ||
if | if isBlank(Craftingskill) then | ||
Skills = '?'..data[lang]['TitleSkill'] | Skills = '?'..data[lang]['TitleSkill'] | ||
else | else | ||
Skills = Craftingskill..data[lang]['TitleSkill'] | Skills = Craftingskill..data[lang]['TitleSkill'] | ||
f:callParserFunction( '#Set', 'CraftingSkill', Craftingskill ) | f:callParserFunction('#Set','CraftingSkill',Craftingskill) | ||
end | end | ||
Skills = Skills .. ' ' | Skills = Skills..' ' | ||
if | if isBlank(CraftingskillLv) then | ||
Skills = Skills .. 'Lv.?' | Skills = Skills..'Lv.?' | ||
else | else | ||
Skills = Skills .. 'Lv.'.. CraftingskillLv | Skills = Skills..'Lv.'..CraftingskillLv | ||
f:callParserFunction( '#Set', 'CraftingSkillLv', CraftingskillLv ) | f:callParserFunction('#Set','CraftingSkillLv',CraftingskillLv) | ||
end | end | ||
Line 177: | Line 204: | ||
end | end | ||
for | for tableNum = 1, 3 ,1 do | ||
if CSs[ | if CSs[tableNum] ~= '' or Ings[tableNum] ~= '' or Results[tableNum] ~= '' then | ||
if | if tableNum > 1 then | ||
table = div:tag('table'):addClass('wikitable'):cssText('margin-left:1em;') | table = div:tag('table'):addClass('wikitable'):cssText('margin-left:1em;') | ||
end | end | ||
Line 185: | Line 212: | ||
tr1:tag('th'):wikitext(data[lang]['TitleCraftingStation']) | tr1:tag('th'):wikitext(data[lang]['TitleCraftingStation']) | ||
tr1:tag('th'):wikitext(data[lang]['TitleIngredient']) | tr1:tag('th'):wikitext(data[lang]['TitleIngredient']) | ||
if Results[ | if Results[tableNum] ~= '' then | ||
tr1:tag('th'):wikitext(data[lang]['TitleResult']) | tr1:tag('th'):wikitext(data[lang]['TitleResult']) | ||
end | end | ||
local tr2 = table:tag('tr') | local tr2 = table:tag('tr') | ||
tr2:tag('td'):wikitext(CSs[ | tr2:tag('td'):wikitext(CSs[tableNum]) | ||
tr2:tag('td'):cssText('text-align: center;'):wikitext(Ings[ | tr2:tag('td'):cssText('text-align: center;'):wikitext(Ings[tableNum]) | ||
if Results[ | if Results[tableNum] ~= '' then | ||
tr2:tag('td'):cssText('text-align: center;'):wikitext(Results[ | tr2:tag('td'):cssText('text-align: center;'):wikitext(Results[tableNum]) | ||
end | end | ||
end | end | ||
Line 200: | Line 227: | ||
local CraftBonus = args[data[lang]['CraftBonus']] or nil | local CraftBonus = args[data[lang]['CraftBonus']] or nil | ||
if | if isBlank(CraftBonus) then | ||
else | else | ||
html:tag('li'):wikitext(string.format('<b>'.. data[lang]['TitleCraftBonus'] ..'</b> : ' .. CraftBonus)):done() | html:tag('li'):wikitext(string.format('<b>'..data[lang]['TitleCraftBonus']..'</b> : '..CraftBonus)):done() | ||
f:callParserFunction( '#Set', 'CraftBonus', CraftBonus ) | f:callParserFunction('#Set','CraftBonus',CraftBonus) | ||
end | end | ||
local ObtainRecipe = args[data[lang]['ObtainRecipe']] or nil | local ObtainRecipe = args[data[lang]['ObtainRecipe']] or nil | ||
if | if isBlank(ObtainRecipe) then | ||
else | else | ||
html:tag('li'):wikitext(string.format('<b>'.. data[lang]['TitleObtainRecipe'] ..'</b> : ' .. ObtainRecipe)):done() | html:tag('li'):wikitext(string.format('<b>'..data[lang]['TitleObtainRecipe']..'</b> : '..ObtainRecipe)):done() | ||
f:callParserFunction( '#Set', 'ObtainRecipe', ObtainRecipe ) | f:callParserFunction('#Set','ObtainRecipe',ObtainRecipe) | ||
end | end | ||
if title.nsText == | if title.nsText == 'Elin' then | ||
html:wikitext(string.format(data[lang]['Category'])) | html:wikitext(string.format(data[lang]['Category'])) | ||
if isBlank(CSCategory) then | |||
else | |||
html:wikitext(CSCategory) | |||
end | |||
end | end | ||
Revision as of 16:07, 29 March 2025
Documentation for this module may be created at Module:CraftingTable/doc
local p = {}
local function isBlank(value)
return value == nil or not value or value == ''
end
function p.crafttable(f)
local args = f:getParent().args
local lang = f.args[1]
local data = mw.loadData('Module:CraftingTable/i18n')
local title = mw.title.getCurrentTitle()
local Recipe = {
{
CraftingStation = args[data[lang]['CraftingStation']] or '',
Ingredient = args[data[lang]['Ingredient']] or '',
IngredientNum = args[data[lang]['IngredientNum']] or '',
IngredientExtra = args[data[lang]['IngredientExtra']] or '',
CraftResult = args[data[lang]['TitleResult']] or '',
},
{
CraftingStation = args[data[lang]['CraftingStation']..'2'] or '',
Ingredient = args[data[lang]['Ingredient']..'2'] or '',
IngredientNum = args[data[lang]['IngredientNum']..'2'] or '',
IngredientExtra = args[data[lang]['IngredientExtra']..'2'] or '',
CraftResult = args[data[lang]['TitleResult']..'2'] or '',
},
{
CraftingStation = args[data[lang]['CraftingStation']..'3'] or '',
Ingredient = args[data[lang]['Ingredient']..'3'] or '',
IngredientNum = args[data[lang]['IngredientNum']..'3'] or '',
IngredientExtra = args[data[lang]['IngredientExtra']..'3'] or '',
CraftResult = args[data[lang]['TitleResult']..'3'] or '',
}
}
local CSs = { '','','' }
local CSCategory = ''
local Ings = { '','','' }
local Results = { '','','' }
for tableNum = 1, 3 ,1 do
if isBlank(Recipe[tableNum].CraftingStation) then
if tableNum == 1 then CSs[1] = data[lang]['ErrorCraftingStation'] end
else
local v = {} ; v = mw.text.split(Recipe[tableNum].CraftingStation,'%s*,%s*')
f:callParserFunction('#Set','CraftingStation'..tableNum,Recipe[tableNum].CraftingStation)
for i, item in ipairs(v) do
if i > 1 then CSs[tableNum] = CSs[tableNum]..'<br />' end
if isBlank(item) then
CSs[tableNum] = CSs[tableNum]..data[lang]['BlankValue']
else
CSs[tableNum] = CSs[tableNum]..f:expandTemplate{title=data[lang]['TemplateName'],args={item,size=imgsize}}
if title.nsText == 'Elin' then
CSCategory = CSCategory..'[[Category:Elin '..item..']]'
end
end
end
end
if isBlank(Recipe[tableNum].Ingredient) then
if tableNum == 1 then Ings[1] = data[lang]['ErrorIngredient'] end
else
local Ing = {} ; Ing = mw.text.split(Recipe[tableNum].Ingredient,'%s*,%s*')
local IngN = {} ; IngN = mw.text.split(Recipe[tableNum].IngredientNum,'%s*,%s*')
local IngE = {} ; IngE = mw.text.split(Recipe[tableNum].IngredientExtra,'%s*,%s*') or ''
f:callParserFunction('#Set','Ingredient'..tableNum,Recipe[tableNum].Ingredient)
f:callParserFunction('#Set','IngredientNum'..tableNum,Recipe[tableNum].IngredientNum)
f:callParserFunction('#Set','IngredientExtra'..tableNum,Recipe[tableNum].IngredientExtra)
for i, item in ipairs(Ing) do
if i > 1 then
Ings[tableNum] = Ings[tableNum]..'<div class="plus or-separator">+</div>'
end
if isBlank(item) then
Ings[tableNum] = Ings[tableNum]..data[lang]['BlankValue']
else
if string.find(item,'/') then
local z = {} ; z = mw.text.split(Ing[i],'%s*/%s*')
local z2 = {} ; if IngN[i] then z2 = mw.text.split(IngN[i],'%s*/%s*') or 1 end
local z3 = {} ; if IngE[i] then z3 = mw.text.split(IngE[i],'%s*/%s*') or '' end
for i2, item2 in ipairs(z) do
local itemname = item2
local itemnum = z2[i2] or 1
local itemvar
local itemext = z3[i2] or ''
if i2 > 1 then
Ings[tableNum] = Ings[tableNum]..'<div class="or-separator">'..data[lang]['Or']..'</div>'
end
if string.find(item2,'@') then
local v2 = {} ; v2 = mw.text.split(item2,'%s*@%s*')
itemname = v2[1]
itemvar = v2[2]
end
if isBlank(itemnum) then
if itemvar then
Ings[tableNum] = Ings[tableNum]..f:expandTemplate{title=data[lang]['TemplateName'],args={itemname,v=itemvar,link='Elin:'..itemname..' '..itemvar,size=imgsize}}
else
Ings[tableNum] = Ings[tableNum]..f:expandTemplate{title=data[lang]['TemplateName'],args={itemname,size=imgsize}}
end
else
if itemvar then
Ings[tableNum] = Ings[tableNum]..f:expandTemplate{title=data[lang]['TemplateName'],args={itemname,itemnum,v=itemvar,link='Elin:'..itemname..' '..itemvar,size=imgsize}}
else
Ings[tableNum] = Ings[tableNum]..f:expandTemplate{title=data[lang]['TemplateName'],args={itemname,itemnum,size=imgsize}}
end
end
if itemext == data[lang]['TitleExtra'] then Ings[tableNum] = Ings[tableNum]..data[lang]['TextExtra']
elseif itemext == data[lang]['TitleGourmet'] then Ings[tableNum] = Ings[tableNum]..data[lang]['TextGourmet'] end
end
elseif string.find(item,'@') then
local v2 = {} ; v2 = mw.text.split(item,'%s*@%s*')
Ings[tableNum] = Ings[tableNum]..f:expandTemplate{title=data[lang]['TemplateName'],args={v2[1],v=v2[2],link='Elin:'..v2[1]..' '..v2[2],size=imgsize}}
elseif isBlank(IngN[i]) then
Ings[tableNum] = Ings[tableNum]..f:expandTemplate{title=data[lang]['TemplateName'],args={item,size=imgsize}}
else
Ings[tableNum] = Ings[tableNum]..f:expandTemplate{title=data[lang]['TemplateName'],args={item,IngN[i],size=imgsize}}
end
if IngE[i] == data[lang]['TitleExtra'] then Ings[tableNum] = Ings[tableNum]..data[lang]['TextExtra']
elseif IngE[i] == data[lang]['TitleGourmet'] then Ings[tableNum] = Ings[tableNum]..data[lang]['TextGourmet'] end
end
end
end
if isBlank(Recipe[tableNum].CraftResult) then
else
f:callParserFunction('#Set','CraftingResult'..tableNum, Recipe[tableNum].CraftResult)
local itemtable = {} ; itemtable = mw.text.split(Recipe[tableNum].CraftResult,'%s*,%s*')
for i, item in ipairs(itemtable) do
if i > 1 then
Results[tableNum] = Results[tableNum]..'<div class="or-separator">'..data[lang]['Or']..'</div>'
end
local itemname = item
local itemnum = 1
local itemvar
if string.find(itemname,'/') then
local z = {} ; z = mw.text.split(itemname,'%s*/%s*')
itemname = z[1]
itemnum = z[2]
if string.find(itemname,'@') then
local z = {} ; z = mw.text.split(itemname,'%s*@%s*')
itemname = z[1]
itemvar = z[2]
end
elseif string.find(itemname,'@') then
local z = {} ; z = mw.text.split(itemname,'%s*@%s*')
itemname = z[1]
itemvar = z[2]
end
if itemvar then
Results[tableNum] = Results[tableNum]..f:expandTemplate{title=data[lang]['TemplateName'],args={itemname,itemnum,v=itemvar,link='Elin:'..itemname..' '..itemvar,size=imgsize}}
else
Results[tableNum] = Results[tableNum]..f:expandTemplate{title=data[lang]['TemplateName'],args={itemname,itemnum,size=imgsize}}
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 isBlank(Craftingskill) then
Skills = '?'..data[lang]['TitleSkill']
else
Skills = Craftingskill..data[lang]['TitleSkill']
f:callParserFunction('#Set','CraftingSkill',Craftingskill)
end
Skills = Skills..' '
if isBlank(CraftingskillLv) then
Skills = Skills..'Lv.?'
else
Skills = Skills..'Lv.'..CraftingskillLv
f:callParserFunction('#Set','CraftingSkillLv',CraftingskillLv)
end
if Results ~= '' then colspan = 3
else colspan = 2 end
table:tag('tr'):tag('th'):attr('colspan',colspan):wikitext(Skills)
end
for tableNum = 1, 3 ,1 do
if CSs[tableNum] ~= '' or Ings[tableNum] ~= '' or Results[tableNum] ~= '' then
if tableNum > 1 then
table = div:tag('table'):addClass('wikitable'):cssText('margin-left:1em;')
end
local tr1 = table:tag('tr')
tr1:tag('th'):wikitext(data[lang]['TitleCraftingStation'])
tr1:tag('th'):wikitext(data[lang]['TitleIngredient'])
if Results[tableNum] ~= '' then
tr1:tag('th'):wikitext(data[lang]['TitleResult'])
end
local tr2 = table:tag('tr')
tr2:tag('td'):wikitext(CSs[tableNum])
tr2:tag('td'):cssText('text-align: center;'):wikitext(Ings[tableNum])
if Results[tableNum] ~= '' then
tr2:tag('td'):cssText('text-align: center;'):wikitext(Results[tableNum])
end
end
end
html:wikitext(string.format('<div style="clear:both;"></div>'))
local CraftBonus = args[data[lang]['CraftBonus']] or nil
if isBlank(CraftBonus) then
else
html:tag('li'):wikitext(string.format('<b>'..data[lang]['TitleCraftBonus']..'</b> : '..CraftBonus)):done()
f:callParserFunction('#Set','CraftBonus',CraftBonus)
end
local ObtainRecipe = args[data[lang]['ObtainRecipe']] or nil
if isBlank(ObtainRecipe) then
else
html:tag('li'):wikitext(string.format('<b>'..data[lang]['TitleObtainRecipe']..'</b> : '..ObtainRecipe)):done()
f:callParserFunction('#Set','ObtainRecipe',ObtainRecipe)
end
if title.nsText == 'Elin' then
html:wikitext(string.format(data[lang]['Category']))
if isBlank(CSCategory) then
else
html:wikitext(CSCategory)
end
end
return tostring(html)
end
return p