Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Special pages
Random page
Wiki Discord
Contents
Neighbors
Galaxy
> Hexia
> Norvan
> Pashah
> Taffeh
Creatures
> Insects
> Fishes
> Shore-Dwellers
Items
> Dishes
> Furniture
Game Systems
> Dress Up
> Luca Arbor
> Loomix Footprints
> Loomix Vehicle Services
> Loomix Homes
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Editing
Module
:
Item Usage
Module
Discussion
English
Read
Edit source
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit source
View history
General
What links here
Related changes
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Once you make an edit, a temporary account will be created for you.
Learn more
.
Log in
or
create an account
to continue receiving notifications after this account expires, and to access other features.
Anti-spam check. Do
not
fill this in!
local p = {} local lib = require('Module:Feature') local Parse = require('Module:Parser').getTemplateArgs local Rlib = require('Module:Recipe').param local Item = require('Module:Item')._main -------------------------------------------------------------------------------- -- Helpers -------------------------------------------------------------------------------- local function isNotEmpty(v) return lib.isNotEmpty(v) end local function normalizeText(s) return mw.ustring.lower(mw.text.trim(tostring(s or ''))) end local function getKitchenwareArg() return Rlib.sKitchArg or 'kitchenware' end local function getSortDelimiter(sort) return lib.ternary( sort:find(Rlib.sSortDelim2), Rlib.sSortDelim2, Rlib.sSortDelim ) end local function isCookingRecipe(recipe) return normalizeText(recipe[Rlib.sTypeArg]) == 'cooking' end local function getMaxCookingItemIndex(recipe) local maxIndex = 0 for key, _ in pairs(recipe) do local index = tostring(key):match('^item_(%d+)') if index then index = tonumber(index) if index and index > maxIndex then maxIndex = index end end end return maxIndex end -------------------------------------------------------------------------------- -- Usage detection -------------------------------------------------------------------------------- local function standardRecipeUsesItem(recipe, item) if not isNotEmpty(recipe['sort']) then return false end if not isNotEmpty(recipe[item]) then return false end for name in lib.gsplit(recipe['sort'], getSortDelimiter(recipe['sort'])) do if isNotEmpty(name) and name == item then return true end end return false end local function cookingRecipeUsesItem(recipe, item) local maxIndex = getMaxCookingItemIndex(recipe) for index = 1, maxIndex do local prefix = 'item_' .. index -- Specific item: -- |item_1 = Rice if isNotEmpty(recipe[prefix]) and recipe[prefix] == item then return true end -- Single type: -- |item_1_type = Fish if isNotEmpty(recipe[prefix .. '_type']) and recipe[prefix .. '_type'] == item then return true end -- Multiple types: -- |item_1_type_1 = Freshwater Fish -- |item_1_type_2 = Saltwater Fish local typeIndex = 1 while isNotEmpty(recipe[prefix .. '_type_' .. typeIndex]) do if recipe[prefix .. '_type_' .. typeIndex] == item then return true end typeIndex = typeIndex + 1 end -- Multiple accepted specific items: -- |item_1_option_1 = Rice -- |item_1_option_2 = Wheat local optionIndex = 1 while isNotEmpty(recipe[prefix .. '_option_' .. optionIndex]) do if recipe[prefix .. '_option_' .. optionIndex] == item then return true end optionIndex = optionIndex + 1 end end -- Kitchenware: -- |kitchenware = Cooking Pot local kitchenwareArg = getKitchenwareArg() if isNotEmpty(recipe[kitchenwareArg]) and recipe[kitchenwareArg] == item then return true end -- Multiple kitchenware: -- |kitchenware_1 = -- |kitchenware_2 = local kitchenwareIndex = 1 while isNotEmpty(recipe[kitchenwareArg .. '_' .. kitchenwareIndex]) do if recipe[kitchenwareArg .. '_' .. kitchenwareIndex] == item then return true end kitchenwareIndex = kitchenwareIndex + 1 end return false end local function recipeUsesItem(recipe, item) if isCookingRecipe(recipe) then return cookingRecipeUsesItem(recipe, item) end return standardRecipeUsesItem(recipe, item) end -------------------------------------------------------------------------------- -- Recipe display helpers -------------------------------------------------------------------------------- local function renderItem(name, amount, quality) local out = tostring(Item({ name, size = 20, x = amount })) if isNotEmpty(quality) then out = out .. ' <small>(' .. quality .. ')</small>' end return out end local function renderIconLink(name, amount, quality) local out = '' if isNotEmpty(amount) then out = tostring(amount) .. '× ' end out = out .. '[[File:' .. name .. ' Icon.png|20x20px|link=' .. name .. ']] [[' .. name .. ']]' if isNotEmpty(quality) then out = out .. ' <small>(' .. quality .. ')</small>' end return out end local function renderStandardIngredients(recipe) local ingredients = {} if not isNotEmpty(recipe['sort']) then return ingredients end for name in lib.gsplit(recipe['sort'], getSortDelimiter(recipe['sort'])) do if isNotEmpty(name) and isNotEmpty(recipe[name]) then table.insert(ingredients, Item({ name, size = 20, x = recipe[name] })) end end return ingredients end local function renderCookingIngredient(recipe, index) local prefix = 'item_' .. index local amount = recipe[prefix .. '_amount'] or '1' local quality = recipe[prefix .. '_quality'] -- Specific item: -- |item_1 = Rice if isNotEmpty(recipe[prefix]) then return renderItem(recipe[prefix], amount, quality) end -- Specific item options: -- |item_1_option_1 = Rice -- |item_1_option_2 = Wheat local options = {} local optionIndex = 1 while isNotEmpty(recipe[prefix .. '_option_' .. optionIndex]) do table.insert(options, renderItem( recipe[prefix .. '_option_' .. optionIndex], amount, quality )) optionIndex = optionIndex + 1 end if #options > 0 then return table.concat(options, ' / ') end -- Type requirements: -- |item_1_type = Fish -- |item_1_type_1 = Freshwater Fish -- |item_1_type_2 = Saltwater Fish local types = {} if isNotEmpty(recipe[prefix .. '_type']) then table.insert(types, renderIconLink( recipe[prefix .. '_type'], amount, quality )) end local typeIndex = 1 while isNotEmpty(recipe[prefix .. '_type_' .. typeIndex]) do table.insert(types, renderIconLink( recipe[prefix .. '_type_' .. typeIndex], amount, quality )) typeIndex = typeIndex + 1 end if #types > 0 then return table.concat(types, ' / ') end return nil end local function renderCookingIngredients(recipe) local ingredients = {} local maxIndex = getMaxCookingItemIndex(recipe) for index = 1, maxIndex do local rendered = renderCookingIngredient(recipe, index) if isNotEmpty(rendered) then table.insert(ingredients, rendered) end end return ingredients end local function renderCookingKitchenware(recipe) local kitchenwareArg = getKitchenwareArg() local kitchenware = {} if isNotEmpty(recipe[kitchenwareArg]) then table.insert(kitchenware, renderIconLink(recipe[kitchenwareArg])) end local index = 1 while isNotEmpty(recipe[kitchenwareArg .. '_' .. index]) do table.insert(kitchenware, renderIconLink(recipe[kitchenwareArg .. '_' .. index])) index = index + 1 end return kitchenware end local function renderRecipeIngredients(recipe) if isCookingRecipe(recipe) then return renderCookingIngredients(recipe) end return renderStandardIngredients(recipe) end local function hasCookingRecipes(valids) for _, recipes in pairs(valids) do for _, recipe in pairs(recipes) do if isCookingRecipe(recipe) then return true end end end return false end -------------------------------------------------------------------------------- -- Main -------------------------------------------------------------------------------- function p.main(frame) local args = require('Module:Arguments').getArgs(frame, { parentFirst = true, wrappers = {'Template:Item Usage'} }) local item = args[1] or mw.title.getCurrentTitle().rootText local count = 0 local craftType = args['type'] local out = mw.html.create() if isNotEmpty(frame.args.pages) and frame.args.pages:find('%$%$%$') then local valids = {} for page in lib.gsplit(frame.args.pages, '$$$') do local data = Parse(page, { only = 'Recipe' }) if type(data[1]) ~= 'table' then data = { data } end for _, call in ipairs(data) do if recipeUsesItem(call, item) then valids[page] = valids[page] or {} table.insert(valids[page], call) count = count + 1 end end end if craftType == 'Furnishing Set' then out:wikitext( 'There ', lib.ternary(count > 1, 'are', 'is'), ' <b>', tostring(count), '</b> [[Furnishing Set]]', lib.ternary(count > 1, 's', ''), ' that use', lib.ternary(count > 1, '', 's'), ' [[', item, ']] as a component:\n' ) else out:wikitext( 'There ', lib.ternary(count > 1, 'are', 'is'), ' <b>', tostring(count), '</b> use', lib.ternary(count > 1, 's', ''), ' for [[', item, ']]:\n' ) end out:node(p._main(valids, craftType)) return out else if craftType == 'Furnishing Set' then out:wikitext('No [[Furnishing Set]]s use [[', item, ']] as a component.') else out:wikitext('No recipes use [[', item, ']] as an ingredient.') end return out end end function p._main(valids, craftType) local _table = mw.html.create('table'):addClass('wikitable article-table sortable') local showKitchenware = hasCookingRecipes(valids) -- Header row local tr = _table:tag('tr') tr:tag('th'):wikitext('Item') tr:tag('th'):wikitext('Craft Type') if showKitchenware then tr:tag('th'):wikitext('Kitchenware') end tr:tag('th'):wikitext(craftType == 'Furnishing Set' and 'Components' or 'Recipe') for page, recipes in lib.spairs(valids) do local tr = _table:tag('tr') for i, recipe in pairs(recipes) do if i == 1 then local cell = tr:tag('td'):attr('rowspan', #valids[page]) if recipe[Rlib.sTypeArg]:find('Set') then cell :tag('div') :css{ ['text-align'] = 'center', ['width'] = '165px' } :wikitext( '[[File:Furnishing Set ', page, ' Display.png|160x80px|alt=', page, '|link=', page, ']]<br>[[', page, ']]' ) else cell:wikitext(Item({ page, x = recipe[Rlib.sYieldArg] })) end else tr = _table:tag('tr') end tr:tag('td') :css{['text-align'] = 'center'} :wikitext('[[', recipe[Rlib.sTypeArg], ']]') if showKitchenware then if isCookingRecipe(recipe) then local kitchenware = renderCookingKitchenware(recipe) tr:tag('td'):wikitext(table.concat(kitchenware, '<br>')) else tr:tag('td'):wikitext('—') end end local ingredients = renderRecipeIngredients(recipe) tr:tag('td'):wikitext(table.concat(ingredients, '<br>')) end end return _table end return p
Summary:
Please note that all contributions to The Petit Planet Wiki are considered to be released under the Creative Commons Attribution-ShareAlike (see
Petit Planet Wiki:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Preview page with this template
Below are commonly used wikitext from
MediaWiki:Edittools
. Click on any to insert them in the edit box.
File Pages
==Summary==
==Licensing==
{{Fairuse}}
{{File|}}
Dynamic Page List
¦
²
«
»
²{¦}²
«»
«/»
«!----»
Array in DPL
¹
^2{
}^2
^2{¹}^2
Parser Functions
{{#if:||}}
{{#if:<condition>|<result if true>|<result if false>}}
{{#ifeq:|||}}
{{#ifeq:<text1>|<text2>|<result if text1=text2>|<result if text1≠text2>}}
{{#expr:}}
{{#expr:<mathematical expression>}}
{{#switch:||#default=}}
{{#switch:<text1>|<text2>=<result if text1=text2>|<text3>=<result if text1=text3>|#default=<result if no valid match>}}
{{#replace:||}}
{{#replace:<text1>|<plain text to find in text1>|<plain text to insert in place of the text found>}}
{{#titleparts:}}
{{#replace:<page name>}}
{{#tag:|}}
{{#tag:<name of html tag>|<content inside html tag>}}
Markup
{{}}
|
[]
[[]]
[[Category:]]
#REDIRECT [[]] [[Category:Redirect Pages]]
<code></code>
<includeonly></includeonly>
<noinclude></noinclude>
<nowiki></nowiki>
<!---->
<br>
§
Notices
{{Stub|}}
{{Stub Dialogue}}
{{Upcoming}}
{{Under Construction}}
{{Placeholder|}}
Magic Words
{{!}}
{{formatnum:}}
{{lc:}}
{{uc:}}
{{PAGENAME}}
{{FULLPAGENAME}}
{{ROOTPAGENAME}}
{{BASEPAGENAME}}
{{SUBPAGENAME}}
{{DISPLAYTITLE:|noreplace}}
__TOC__
__NOTOC__
__EXPECTUNUSEDCATEGORY__
__HIDDENCAT__
HTML Entities
—
,
­
Pages included on this page:
Template:Documentation/Header
(
edit
)
Template:Documentation/styles.css
(
edit
)
Template:T
(
edit
)
Template:TOC Right
(
edit
)
Module:Arguments
(
edit
)
Module:Arguments/i18n
(
edit
)
Module:Common/i18n
(
edit
)
Module:Config
(
edit
)
Module:Documentation
(
edit
)
Module:Documentation/config
(
edit
)
Module:Documentation/i18n
(
edit
)
Module:Entrypoint
(
edit
)
Module:Exists
(
edit
)
Module:Fallbacklist
(
edit
)
Module:Feature
(
edit
)
Module:Formatting
(
edit
)
Module:I18n
(
edit
)
Module:Item Usage/doc
(
edit
)
Module:Languages
(
edit
)
Module:TableTools
(
edit
)
Module:Yesno
(
edit
)
This page is a member of 2 hidden categories:
Category:Pages using DynamicPageList4 parser function
Category:Pages using DynamicPageList4
Search
Search
Editing
Module
:
Item Usage
Add topic