Module:Decoration

local Decoration = {}

-- Libraries of functions --

-- HF stands for High Frequency. -- This Module augments the built-in HF local HF = mw.InfoboxBuilderHF -- This Module helps process template parameters local getArgs = require('Dev:Arguments').getArgs

--- -- Libraries of data -- --- -- functions as local data = mw.loadData( 'Module:Decoration/data' ) local lang = mw.language.getContentLanguage

local basePageName = mw.title.getCurrentTitle.baseText local dequalifiedTitle = mw.text.split(mw.title.getCurrentTitle.baseText, '%s%(')[1]

-- Local functions (used only in this Module) --

-- eliminates whitespace from the front and back of a string function HF.trim(s) if type(s) == 'string' then return (s:gsub("^%s*(.-)%s*$", '%1')) else return false end end

-- Adds an internal link -- `label` is optional function HF.Link( link, text ) if not HF.isempty( text ) then return string.format('%s'..'%s|%s]]', '[[', link, text) else return string.format('%s'..'%s]]', '[[', link) end end

-- Adds a Category -- `sortkey` is optional function HF.Category( category, sortkey ) if sortkey == nil then sortkey = '' else sortkey = '|' .. sortkey end return string.format('%s'..'Category:%s%s]]', '[[', category, sortkey) end -- Adds a link to a Category function HF.LinkToCategory( category, label ) return string.format('%s'..'Category:%s|%s]]', '[[:', category, label or 'Category:' .. category ) end

function getTool(term) local tool = data.tool return (type(term) == 'string') and tool[term:lower:sub(0,3)] or term end

function getBiome(term) local biome = data.biome search = (type(term) == 'string') and term:lower:sub(0,3) if search and biome[search or ''] and (search ~= 'non') then return biome[search] else return term end end

function getRecipe(term) local recipe = data.recipe search = (type(term) == 'string') and term:lower:sub(0,3) if search and recipe[search] and (search ~= 'non') then return recipe[search] elseif search then return term..' Recipe' end end

local function getDesigner(blueprint) local designer = 'Trove Team' if type(blueprint) == 'string' then if string.find(blueprint, ']') ~= nil then local p,q = string.find(blueprint, '%b[]') designer = string.sub(blueprint, p + 1, q - 1) -- exception code exception = mw.loadData('Module:NewDecoPage/Designer') if exception[string.lower(designer)] ~= nil then designer = exception[string.lower(designer)] else designer = string.lower(designer):gsub("^%l", string.upper) end end end return designer end

-- -- Public functions (called from a Template or article) -- -- function HF.dequalifyTitle(frame) return mw.text.split(mw.title.getCurrentTitle.baseText, '%s%(')[1] end

-- functions as function Decoration.Blueprint(frame) local args = getArgs(frame) return Decoration._blueprint(args) end

-- functions as function Decoration.ItemLink(frame) local args = getArgs(frame) return Decoration._itemLink(args) end

-- supplies Designer field function Decoration.Designer(frame) local args = getArgs(frame) return HF.LinkToCategory(getDesigner(args.blueprint), getDesigner(args.blueprint)) end

-- supplies Biome field function Decoration.Biome(frame) local args = getArgs(frame) --   local B = args['biome'] or '' if getBiome('Summer') then -- Changes type2 link to category link if in the table local seasons = { ['Geode'] = 'Geode', ['Spring'] = 'Spring', ['Summer'] = 'Summer', ['Winter'] = 'Winter' }       local vb = getBiome(args.biome) return seasons[vb] and HF.LinkToCategory(vb,vb) or HF.Link(vb) end end

-- Generates article introduction / lead function Decoration.articleLead(frame) local args = getArgs(frame) local workbench = getTool(args['biome'] or 'none') local text = { string.format(           "The %s is a placable%s decoration%s.",            dequalifiedTitle,            (args['emitLight'] and string.lower(args['emitLight']) == 'yes')                 and ', ' .. HF.LinkToCategory( 'Luminous', 'luminous' )                or '',            workbench                 and string.format( ' that is crafted through the %s', HF.Link(workbench) )               or ''        ) } --   if string.find(pageName, 'Banner') then --     table.insert(text, ('Like other %s banners...'):format('decorational')) --   end return table.concat(text, ' ') --[==[   function data.description(emitLight, workbench, pageName, itemSet, Modname)

-- Decoration is a banner local geode = false local currentSect = nil local sections = { 'Top', 'Bottom' }   if string.find(pageName, 'Banner') ~= nil then local i,_ = string.find(pageName, 'Banner') if i + 7 <= string.len(pageName) then -- If Geode banner if string.find(pageName, 'Spire Banner') ~= nil then geode = true end if geode then table.insert(sections, 2, 'Lower Middle') table.insert(sections, 2, 'Upper Middle') result = result .. '. Like other Geode spire banners, the ' .. pageName .. ' can be combined with the' else table.insert(sections, 2, 'Middle') result = result .. '. Like other decorational banners, the ' .. pageName .. ' can be combined with the' end -- Determines which section the banner is           for n, part in ipairs(sections) do                    if string.find(pageName, part) ~= nil then currentSect = sections[n] table.remove(sections, n)                       break end end -- Generates links to other parts if geode then result = result .. ' ' .. sections[1] .. ', ' .. sections[2] .. ', and ' .. sections[3] .. '' else result = result .. ' ' .. sections[1] .. ' and ' .. sections[2] .. '' end result = result .. ' sections to create the full banner' end end result = result .. '.'   return result end --]==] end

-- Generates Crafting chapter / section function Decoration.Crafting(frame) local args = getArgs(frame) local inputs = { args['ci1'], args['ca1'], args['ci2'], args['ca2'], args['ci3'], args['ca3'], args['ci4'], args['ca4'], args['ci5'], args['ca5'], args['ci6'], args['ca6'] }   if inputs[1] then local values = { ['tool'] = getTool(args.biome), ['resultAmount'] = args.ra       } --Assigns values to crafting ingredient and amount local count = 1 for n=1,12 do           if (inputs[n] ~= nil and inputs[n] ~= '') then if tonumber(inputs[n]) == nil then values['item'..count] = inputs[n] else values['amount'..count] = tonumber(inputs[n]) count = count + 1 end else count = count + 1 end end local header = mw.html.create('h2'):wikitext('Crafting'):allDone local crafting_recipe = Decoration._craftingRecipe(args) return tostring(header) .. crafting_recipe end end

-- functions as function Decoration.CraftingRecipe(frame) local args = getArgs(frame) return Decoration._craftingRecipe(args) end

-- supplies categories function Decoration.Categories(frame) local args = getArgs(frame) local categories = { HF.Category('Decoration'), HF.Category('Placeable') } if string.lower(args.emitLight or '') == 'yes' then table.insert(categories, HF.Category('Luminous')) end if getDesigner(args.blueprint) then table.insert(categories, HF.Category(getDesigner(args.blueprint))) end if getBiome(args.biome) then table.insert(categories, HF.Category(getBiome(args.biome))) end if getRecipe(args.biome) then --Test if item is part of recipe item local exclude = {} for _, v in pairs(         mw.loadData('Module:Decoration_recipes/' .. getBiome(args.biome) .. '/Exclude')       ) do            exclude[v] = true end if not exclude[mw.title.getCurrentTitle.baseText] then table.insert(categories, HF.Category(getRecipe(args.biome))) end end return table.concat(categories) end - -- Internal functions (used in this and other Modules) -- - -- creates a libTroxel invocation function Decoration._blueprint (args) local envelope = mw.html.create('center') :tag('div'):css('width', (args.width or 225)..'px'):css('height', (args.height or 225)..'px') :attr('data-troxel-blueprint', args.name or '') :attr('data-troxel-options', '{"rendererClearColor": "#118784"}') :allDone return tostring(envelope) end

function Decoration._craftingRecipe (args) local tools = { args.tool, args.tool2, args.tool3, args.tool4, args.tool5 } local result = args.result or args.name or mw.title.getCurrentTitle.baseText local crafting_stations = {} for _,entry in pairs(tools) do       table.insert( crafting_stations, itemLink(entry) ) end local T = mw.html.create('table') :addClass('article-table'):addClass('mw-collapsible'):addClass('mw-collapsed') :css('width','330px') --       :css('border','1px solid #e8ea52'):css('border-radius','0.7em') --       :css('padding','0.2em'):css('margin-bottom','5px') :tag('caption') --           :css('background-color','#0f8687'):css('color','#ffffff') --           :css('font-size','110%'):css('padding','0.2em') :wikitext('Crafted using') :done :tag('tr'):tag('th'):attr('colspan','2'):wikitext('Crafting Station'):done:done :tag('tr'):tag('td'):attr('colspan','2') :wikitext(table.concat(crafting_stations, ' '))           :done:done :tag('tr') :tag('th'):wikitext('Ingredient(s)'):done :tag('th'):wikitext('Amount'):done :done for i = 1,12 do           if args['item'..i] then T:tag('tr') :tag('td') :wikitext(Decoration._linkedIcon(args['item'..i])..HF.Link(args['item'..i])) :done :tag('td'):wikitext(args['amount'..i] or 1):done :done end end T:tag('tr'):tag('th'):attr('colspan','2'):wikitext('Result'):done:done :tag('tr'):tag('td'):attr('colspan','2') :wikitext(table.concat( { Decoration._linkedIcon(result), HF.Link(result), args.resultAmount or 1 }, ' ' )           ..( args['category'] ~= 'no' and HF.Category('Craftable items') or '' )            ) :done:done T:allDone return tostring(T) end

function Decoration._itemLink(item) local basePagenameOf = mw.title.new(item).baseText local label = HF.Link(item, basePagenameOf) local o   if args.stack then o = mw.html.create('span'):css('overflow','auto') :tag('span'):css('float','left'):wikitext(Decoration._linkedIcon(item)):done :wikitext(label) :allDone else o = table.concat( { Decoration._linkedIcon(item), label }, ' ' ) end return tostring(o) end

function Decoration._linkedIcon(item) return HF.Link('File:'..item..'_small.png','link='..item..'|50px') end

- -- Output (send it back to whatever called it) -- - return Decoration