Module:Minion/UI

local getArgs = require('Module:Arguments').getArgs local mergeArgsSyntax = require('Module:Arguments').mergeArgsSyntax local loader = require('Module:Loader')

local string, table, yesno, inventoryslot, craftingui, ui, minionMdl = loader.require('String', 'Table', 'Yesno', 'Inventory slot', 'Crafting/UI', 'UI', 'Minion')

local _error = string._error local slot = inventoryslot.slot local lang = mw.getContentLanguage local title = mw.title.getCurrentTitle.text

local p = {}

-- NPC text for p.minionUI local npctext = { ['Bulvar'] = {name = '&5Bulvar', loc = '&2Dwarven Mines'}, ['Tony'] = {name = '&5Tony', loc = '&bTrappers Den'}, } npctext['Terry'] = npctext['Tony']

- -- Template:Minion recipe gallery -- -- Makes a table of to form the in-game ideal layout for a minion - function p.minionRecipeGallery( frame ) --local parameters = frame.args local args = getArgs(frame) local minion = args['minion'] or args[1] if not minion then minion = title end return p._minionRecipeGallery( minion ) end function p._minionRecipeGallery( minionName ) local minion = minionMdl.getMinion(minionName) -- Get a list of the desired tiers local tiers = {} local start = minion.stats[1] and (minion.stats[1].crafting.info and 2 or 1) local _, nCraftable = minionMdl.peakStat(minionName) for i = start, nCraftable do tiers[#tiers+1] = i end -- Generate crafting tables local tables = {} for _,tier in ipairs(tiers) do		local grid = minionMdl._getRecipe( minionName, tier ) tables[#tables+1] = grid and craftingui.craftingGrid(grid) or nil end -- Display all crafting tables in a grid local grid = mw.html.create('table') local row for i, ct in pairs(tables) do		if (i - 1) % 3 == 0 then if row then row:done end row = grid:tag('tr') end row:tag('td'):wikitext(ct):done end row:done grid:done return tostring(grid) end

- -- Template:Minion animated crafting table -- -- Make an animated of all potential minion crafting recipes - function p.minionAnimatedCraftingTable( frame ) --local parameters = frame.args local args = getArgs(frame) local minion = args['minion'] or args[1] or title local item = args['item'] local from = args['from'] local to = args['to'] return mw.getCurrentFrame:preprocess(p._minionAnimatedCraftingTable( minion, item, from, to )) end function p._minionAnimatedCraftingTable( minionName, item, from, to ) local minion = minionMdl.getMinion(minionName) local highestTier, highestCraftable = minionMdl.peakStat(minionName) -- Get a list of the desired tiers local tiers = {} if item then for i=1,highestCraftable,1 do			local crafting = minion.stats[i].crafting if crafting.item == item and not crafting.info then tiers[#tiers+1] = i			end end --ignore .info elseif from and to then if not tonumber(from) or not tonumber(to) then error('Range is not correct') end from, to = tonumber(from), tonumber(to) if not minion.stats[from] or not minion.stats[to] then error('Range is not correct') end if from > to then from, to = to, from end for i = from, to, 1 do tiers[#tiers+1] = i end else local start = minion.stats[1].crafting.info and 2 or 1 for i = start, highestCraftable, 1 do tiers[#tiers+1] = i end end return (''):format(table.concat(table.map(tiers, function(v)		return ('|%s Minion %s'):format(minionName, string._toRoman(v))	end))) end

- -- Template:Minion ideal layout -- -- Makes a table of to form the in-game ideal layout for a minion - function p.minionIdealLayoutTable( frame ) --local parameters = frame.args local args = getArgs(frame) local minion = args['minion'] or args[1] or title local ideal = args['ideal'] local border = args['border'] local size = 5; local slots = {} local rowLetter = { 'A', 'B', 'C', 'D', 'E', } for y = 1,size,1 do		slots[y] = {} for x = 1,size,1 do			slots[y][x] = args[rowLetter[x]..y]		end end return p.minionIdealLayout( minion, size, ideal, border, slots ) end

function p.minionIdealLayout( minion, size, ideal, border, customSlots ) if border then size = size + 2 end local table = mw.html.create('table'):addClass('mcui mcui-Crafting_Table pixel-image margin-centered display-table') for y = 1, size, 1 do		local row = table:tag('tr'):addClass('mcui-row') for x = 1, size, 1 do			local img if border and (y == 1 or y == size or x == 1 or x == size) then img = border elseif x == math.ceil(size / 2) and y == math.ceil(size / 2) then img = ('[%s]%s'):format(minion, minion) if customSlots[y][x] then img = ('%s;%s'):format(img, customSlots[y][x]) end else img = border and (customSlots[y-1][x-1] or ideal) or (customSlots[y][x] or ideal) end row:tag('td'):wikitext( slot{ img } ):done end row:done end table:done return tostring(table) end

- -- Template:Minion UI -- -- Makes a table of to form the in-game UI of a minion - function p.minionUI( frame ) --local parameters = frame.args local args = getArgs(frame) local minion = args['minion'] or args[1] or title return p._minionUI( minion ) end

function p._minionUI( minion ) local name, tier = minion:match('(.-)%s?[Mm]?[Ii]?[Nn]?[Ii]?[Oo]?[Nn]?%s([%divxIVX]+)') if tier then tier = tonumber(tier) or string._toArabic(tier) else name = minion:gsub('%s*[Mm][Ii][Nn][Ii][Oo][Nn]', '') tier = 1 end local dt = minionMdl.getMinion(name) if not dt.stats[tier] then error(name..'Minion has no such tier (Tier '..tier..')') end local highestTier, highestCraftable = minionMdl.peakStat(name) local storageTier = {} for slotno = 1, 15, 1 do -- Minions have 15 total slots for y = 1, 10, 1 do -- All slots unlocked at tier 10 local avail = dt.stats[y].storage / 64 storageTier[slotno] = y			if avail >= slotno then break end end end local function available( num ) if tier >= storageTier[num] then return '' -- Empty slot else return ('White Stained Glass Pane, none, &eStorage unlocked at tier %s, none'):format(string._toRoman(storageTier[num])) end end local title = name .. ' Minion ' .. string._toRoman(tier) local titleLink = name .. ' Minion#' .. string._toRoman(tier) local description = dt.description or 'No Description' local upgradeMessage = '' local upgradeMessageView = '' local upgradeMessageUpgrade = '' if tier == highestTier then upgradeMessage = '&aHighest tier has been reached!' upgradeMessageView = 'The highest tier of this minion/has been reached//'..upgradeMessage upgradeMessageUpgrade = '&cThis minion has reached the/maximum tier.' elseif tier == highestCraftable then local tradenpc = dt.stats[tier+1].tradeNpc upgradeMessage = '&aHighest craftable tier has been/reached!' upgradeMessageView = 'The highest craftable tier of/this minion has been reached/Talk to '..(npctext[tradenpc] and npctext[tradenpc].name or tradenpc)..' &rin the/'..(npctext[tradenpc] and npctext[tradenpc].loc or '(unknown)')..' &rto unlock the/next tier!//'..upgradeMessage upgradeMessageUpgrade = '&cThis minion has reached the/maximum tier.' elseif dt.stats[tier + 1].storage > dt.stats[tier].storage then upgradeMessage = '&7Time Between Actions: &e'..dt.stats[tier].tba..'s/&7Max Storage: &8'..dt.stats[tier].storage..' ➜ &a'..dt.stats[tier + 1].storage upgradeMessageView = '&7View the items required to/upgrade this minion to the/next tier.//'..upgradeMessage..'//&eClick to view!' upgradeMessageUpgrade = upgradeMessage..'//&eClick to upgrade!' else upgradeMessage = '&7Time Between Actions: &8'..dt.stats[tier].tba..'s ➜ &a'..dt.stats[tier + 1].tba..'s/&7Max Storage: &e'..dt.stats[tier].storage upgradeMessageView = '&7View the items required to/upgrade this minion to the/next tier.//'..upgradeMessage..'//&eClick to view!' upgradeMessageUpgrade = upgradeMessage..'//&eClick to upgrade!' end local uitable = { title, arrow = 'none', close = 'none', dnl = true, ['1,4'] = 'Redstone Torch, none, &aIdeal Layout, &7View the most effecient spot for/this minion to be placed in.', ['1,5'] = ('%s, none;%s, &9%s, &7%s//&7Time Between Action: &a%ss/&7Max Storage: &e%s/&7Resources Generated: &b0'):format(			title, titleLink, title, description,			dt.stats[tier].tba, dt.stats[tier].storage		), ['1,6'] = 'Gold Ingot, none, &aNext Tier, '..upgradeMessageView, ['2,2'] = 'Lime Stained Glass Pane, none, &aMinion Skin Slot, &7You can insert a Minion Skin/here to change the appearance of/your minion.', ['3,2'] = 'Orange Stained Glass Pane, none, &aFuel, &7Increase the speed of your/minion by adding minion fuel/items here.//&cNote: &7You can\'t take/fuel back out after you/place it here!', ['4,2'] = 'Blue Stained Glass Pane, none, &aAutomated Shipping, Add a &bBudget Hopper&7,/&bEnchanted Hopper&7 or a/&bPerfect Hopper&7 here to make/your minion automatically sell/generated items after its/inventory is full.', ['5,2'] = 'Yellow Stained Glass Pane, none, &aUpgrade Slot, &7You can improve your minion by/adding a minion upgrade item/here.', ['6,2'] = 'Yellow Stained Glass Pane, none, &aUpgrade Slot, &7You can improve your minion by/adding a minion upgrade item/here.', ['6,4'] = 'Chest, none, &aCollect All, &eClick to Collect all items!', ['6,6'] = 'Diamond, none, &aQuick-Upgrade Minion, &7Click here to upgrade your/minion to the next tier.//'..upgradeMessageUpgrade, ['6,9'] = 'Bedrock, none, &aPickup Minion, &eClick to pickup!', }	for i = 0, 14, 1 do		uitable[('%d,%d'):format(math.floor(i/5)+3, i%5+4)] = available(i+1) end return tostring(ui.ui(uitable)) end

return p