Module:Craft Usage: Difference between revisions

Created page with "local p = {} local recipeParams = { station = 'station', time = 'time', output = 'output', yield = 'yield', } local labels = { craftTitle = 'Crafting', craftInputText = 'The item can be used in the following craft recipes', craftOutputText = 'The item can be created in the following craft recipes', incineratorTitle = 'Incinerator', incineratorInputText = 'The item can be used in the following incinerator recipes', incineratorOutputText = 'The item can be c..."
mNo edit summary
 
(One intermediate revision by the same user not shown)
Line 22: Line 22:
waterTitle = 'Water Source',
waterTitle = 'Water Source',
waterInputText = 'The item can be used at a water source to gain the following items',
waterInputText = 'The item can be used at a water source to gain the following items',
waterOutputText = 'The item can be gained at a water source by using the following items the following items',
waterOutputText = 'The item can be gained at a water source by using the following items',
}
}


function split(str, delimiter)
function split(str, delimiter)
     local returnTable = {}
     local returnTable = {}
     for k, v in string.gmatch(str, "([^" .. delimiter .. "]+)")  
     for k, v in string.gmatch(str, "([^" .. delimiter .. "]+)") do
    do
         returnTable[#returnTable+1] = k
         returnTable[#returnTable+1] = k
     end
     end
Line 41: Line 40:


if not args.item then
if not args.item then
args.item = mw.title.getCurrentTitle().text
args.item = mw.title.getCurrentTitle().text
end
end


local title = mw.title.new('Recipes')
local title = mw.title.new('Recipes')
local content = title:getContent()
local content = title:getContent()
if not content then
return '<div class="error">Strona Recipes nie istnieje.</div>'
end


local recipeStringResult = ''
local recipeStringResult = ''
Line 67: Line 70:
local outputs = {}
local outputs = {}
for propertyStringKey, propertyString in pairs(split(recipe, '|')) do
for propertyStringKey, propertyString in pairs(split(recipe, '|')) do
if not (propertyString == 'Recipe') then
if not (propertyString == 'Recipe') then
local propertySplitTable = split(propertyString, '=')
local propertySplitTable = split(propertyString, '=')


if not recipeParams[propertySplitTable[1]] then
if not recipeParams[propertySplitTable[1]] then
inputText = inputText..'[['..propertySplitTable[1]..']]'..' x '..propertySplitTable[2]..'</br>'
inputText = inputText..'[['..propertySplitTable[1]..']]'..' x '..propertySplitTable[2]..'<br />'
inputs[propertySplitTable[1]] = true
inputs[propertySplitTable[1]] = true
else
else
recipeTable[propertySplitTable[1]] = propertySplitTable[2]
recipeTable[propertySplitTable[1]] = propertySplitTable[2]
 
if propertySplitTable[1] == 'output' then
if propertySplitTable[1] == 'output' then
outputs[propertySplitTable[2]] = true
outputs[propertySplitTable[2]] = true
Line 86: Line 89:


recipeTable['inputText'] = inputText
recipeTable['inputText'] = inputText
 
if recipeTable.station == 'Incinerator' then
if recipeTable.station == 'Incinerator' then
typeKey = 'incineratorRecipes'
typeKey = 'incineratorRecipes'
Line 101: Line 104:
end
end
end
end
 
local wrapper = mw.html.create('div')
local wrapper = mw.html.create('div')
if recipes.craftRecipes[1] then
local craftWrapper = wrapper:tag('div')


local craftTitleWrapper = craftWrapper:tag('h3')
local function buildTable(wrapper, titleText, labelText, recipeList, showStation, showTime)
local craftTitle = craftTitleWrapper:tag('span'):addClass('mw-headline'):wikitext(labels.craftTitle)
if not recipeList[1] then return end
local craftTextLabel = ''
if args.mode == 'input' then
craftTextLabel = labels.craftInputText
elseif args.mode == 'output' then
craftTextLabel = labels.craftOutputText
end
local craftText = craftWrapper:tag('p'):wikitext(craftTextLabel)
local _table = craftWrapper:tag('table'):addClass('fandom-table article-table sortable alternating-colors-table')
local tr = _table:tag('tr')
tr:tag('th'):wikitext('Ingredients')
tr:tag('th'):wikitext('Station')
tr:tag('th'):wikitext('Time')
tr:tag('th'):wikitext('Output')
for recipeKey, recipe in pairs(recipes.craftRecipes) do
if recipe.output then
local tr = _table:tag('tr')
tr:tag('td'):wikitext(recipe.inputText or " - ")
tr:tag('td'):wikitext(recipe.station and '[['..recipe.station..']]' or " - ")
tr:tag('td'):wikitext(recipe.time or " - ")
tr:tag('td'):wikitext('[['..recipe.output..']]'.." x "..(recipe.yield or 1))
end
end
end


if recipes.incineratorRecipes[1] then
local section = wrapper:tag('div')
local incineratorWrapper = wrapper:tag('div')
section:tag('h3'):tag('span'):addClass('mw-headline'):wikitext(titleText)
section:tag('p'):wikitext(labelText)


local incineratorTitleWrapper = incineratorWrapper:tag('h3')
-- używamy wikitable zamiast fandom-table
local incineratorTitle = incineratorTitleWrapper:tag('span'):addClass('mw-headline'):wikitext(labels.incineratorTitle)
local _table = section:tag('table'):addClass('wikitable sortable')
local incineratorTextLabel = ''
if args.mode == 'input' then
incineratorTextLabel = labels.incineratorInputText
elseif args.mode == 'output' then
incineratorTextLabel = labels.incineratorOutputText
end
local incineratorText = incineratorWrapper:tag('p'):wikitext(incineratorTextLabel)
local _table = incineratorWrapper:tag('table'):addClass('fandom-table article-table sortable alternating-colors-table')
local tr = _table:tag('tr')
local tr = _table:tag('tr')
tr:tag('th'):wikitext('Ingredients')
tr:tag('th'):wikitext('Ingredients')
if showStation then tr:tag('th'):wikitext('Station') end
if showTime then tr:tag('th'):wikitext('Time') end
tr:tag('th'):wikitext('Output')
tr:tag('th'):wikitext('Output')
 
for recipeKey, recipe in pairs(recipes.incineratorRecipes) do
for _, recipe in pairs(recipeList) do
if recipe.output then
if recipe.output then
local tr = _table:tag('tr')
local row = _table:tag('tr')
tr:tag('td'):wikitext(recipe.inputText or " - ")
row:tag('td'):wikitext(recipe.inputText or '-')
if showStation then row:tag('td'):wikitext(recipe.station and '[['..recipe.station..']]' or '-') end
tr:tag('td'):wikitext('[['..recipe.output..']]'.." x "..(recipe.yield or 1))
if showTime then row:tag('td'):wikitext(recipe.time or '-') end
row:tag('td'):wikitext('[['..recipe.output..']]'..' x '..(recipe.yield or 1))
end
end
end
end
end
end


if recipes.cookingRecipes[1] then
local mode = args.mode or 'output'
local cookingWrapper = wrapper:tag('div')
 
local cookingTitleWrapper = cookingWrapper:tag('h3')
local cookingTitle = cookingTitleWrapper:tag('span'):addClass('mw-headline'):wikitext(labels.cookingTitle)
local cookingTextLabel = ''
if args.mode == 'input' then
cookingTextLabel = labels.cookingInputText
elseif args.mode == 'output' then
cookingTextLabel = labels.cookingOutputText
end
local cookingText = cookingWrapper:tag('p'):wikitext(cookingTextLabel)
local _table = cookingWrapper:tag('table'):addClass('fandom-table article-table sortable alternating-colors-table')
local tr = _table:tag('tr')
tr:tag('th'):wikitext('Ingredients')
tr:tag('th'):wikitext('Output')
for recipeKey, recipe in pairs(recipes.cookingRecipes) do
if recipe.output then
local tr = _table:tag('tr')
tr:tag('td'):wikitext(recipe.inputText or " - ")
tr:tag('td'):wikitext('[['..recipe.output..']]'.." x "..(recipe.yield or 1))
end
end
end


if recipes.farmingRecipes[1] then
buildTable(wrapper, labels.craftTitle,
local farmingWrapper = wrapper:tag('div')
mode == 'input' and labels.craftInputText or labels.craftOutputText,
recipes.craftRecipes, true, true)


local farmingTitleWrapper = farmingWrapper:tag('h3')
buildTable(wrapper, labels.incineratorTitle,
local farmingTitle = farmingTitleWrapper:tag('span'):addClass('mw-headline'):wikitext(labels.farmingTitle)
mode == 'input' and labels.incineratorInputText or labels.incineratorOutputText,
recipes.incineratorRecipes, false, false)
local farmingTextLabel = ''
if args.mode == 'input' then
farmingTextLabel = labels.farmingInputText
elseif args.mode == 'output' then
farmingTextLabel = labels.farmingOutputText
end
local farmingText = farmingWrapper:tag('p'):wikitext(farmingTextLabel)
local _table = farmingWrapper:tag('table'):addClass('fandom-table article-table sortable alternating-colors-table')
local tr = _table:tag('tr')
tr:tag('th'):wikitext('Ingredients')
tr:tag('th'):wikitext('Output')
for recipeKey, recipe in pairs(recipes.farmingRecipes) do
if recipe.output then
local tr = _table:tag('tr')
tr:tag('td'):wikitext(recipe.inputText or " - ")
tr:tag('td'):wikitext('[['..recipe.output..']]'.." x "..(recipe.yield or 1))
end
end
end


if recipes.waterRecipes[1] then
buildTable(wrapper, labels.cookingTitle,
local waterWrapper = wrapper:tag('div')
mode == 'input' and labels.cookingInputText or labels.cookingOutputText,
recipes.cookingRecipes, false, false)


local waterTitleWrapper = waterWrapper:tag('h3')
buildTable(wrapper, labels.farmingTitle,
local waterTitle = waterTitleWrapper:tag('span'):addClass('mw-headline'):wikitext(labels.waterTitle)
mode == 'input' and labels.farmingInputText or labels.farmingOutputText,
recipes.farmingRecipes, false, false)
local waterTextLabel = ''
if args.mode == 'input' then
waterTextLabel = labels.waterInputText
elseif args.mode == 'output' then
waterTextLabel = labels.waterOutputText
end
local waterText = waterWrapper:tag('p'):wikitext(waterTextLabel)
local _table = waterWrapper:tag('table'):addClass('fandom-table article-table sortable alternating-colors-table')
local tr = _table:tag('tr')
tr:tag('th'):wikitext('Ingredients')
tr:tag('th'):wikitext('Output')
for recipeKey, recipe in pairs(recipes.waterRecipes) do
if recipe.output then
local tr = _table:tag('tr')
tr:tag('td'):wikitext(recipe.inputText or " - ")
tr:tag('td'):wikitext('[['..recipe.output..']]'.." x "..(recipe.yield or 1))
end
end
end


buildTable(wrapper, labels.waterTitle,
mode == 'input' and labels.waterInputText or labels.waterOutputText,
recipes.waterRecipes, false, false)


return wrapper
return wrapper