Module:MoneyMakingGuide: Difference between revisions

From Melvor Idle
(First version)
 
mNo edit summary
Line 102: Line 102:
--- Formats a wikicode string to be bold and red
--- Formats a wikicode string to be bold and red
local function formatError(errorMessage)
local function formatError(errorMessage)
local eror mw.html.create('span')
local eror = mw.html.create('span')
:wikitext("'''")
:wikitext("'''")
:css('color', 'red')
:css('color', 'red')

Revision as of 21:45, 19 March 2024

Documentation for this module may be created at Module:MoneyMakingGuide/doc

local p = {}

local shared = require('Module:Shared')
local num = require('Module:Number')
local paramtest = require('Module:Shared/Paramtest')

local MaxDynamicArgs = 20
local AmountSuffix = 'amount'
local ValueSuffix = 'value'
local SkillPrefix = 'skillExp'

function p.main(frame)
	local args = frame:getParent().args
	return p._main(args)
end

function p._main(args)
	return formatError("Module:MoneyMakingGuide is not yet implemented. Do not use.")
end

--- Builds the section of the mmg table that shows the input and output items.
-- @param items (table) A table containing items
-- @return (string) The HTML representation of the item table section.
local function buildItemTable(items)
end

--- Builds the section of the mmg table that shows the skill experience gained.
-- @param items (table) A table containing skills and experience values.
-- @return (string) The HTML representation of the item table section.
local function buildExpTable(skills)
end

--- Parses the input and output items from the provided arguments.
-- @param args (table) Passed args table from the caller.
-- @param prefix (string) The prefix that determines input or output item parsing.
-- @return (table) A table containing parsed item information.
local function parseItemInOut(args, prefix)
	local items = {}
	for i = 1, MaxDynamicArgs do
		local numPrefix = prefix .. i

		-- Stop parsing. Could cause problems if user input skips indexes.
		if paramtest.is_empty(args[numPrefix]) then
			break
		end
			
		local pName = args[numPrefix] -- Guaranteed to have a value.
		local pAmount = args[numPrefix .. AmountSuffix]
		local pValue = args[numPrefix .. ValueSuffix]

		-- Values *should* always exit this function with a non nil value.
		if paramtest.has_content(pAmount) then
			pAmount = tonumber(pAmount)
		end
		
		if not paramtest.has_content(pValue) or tonumber(pValue) == nil then
			-- Look up value from item module if it's not entered manually?
			pValue = nil
		else
			pValue = tonumber(pValue)
		end
		
		table.insert(items, {
			prmNumber = i,
			name = pName, 
			amount = pAmount, 
			value = pValue})
	end
	
	return items
end

--- Parses the skill experience from the provided arguments.
-- @param args (table) Passed args table from the caller.
-- @return (table) A table containing parsed skill experience information.
local function parseExp(args)
	local skills = {}
	for i = 1, MaxDynamicArgs do
		local skillPrefix = 'skillExp' .. i
		
		-- Stop parsing. Could cause problems if user input skips indexes.
		if paramtest.is_empty(args[skillPrefix]) then
			break
		end
			
		local pSkill = args[skillPrefix] -- Guaranteed to have a value.
		local pExp = args[skillPrefix .. AmountSuffix]

		if paramtest.has_content(pExp) then 
			pExp = tonumber(pExp)
		end
		
		table.insert(items, {
			prmNumber = i,
			name = pSkill, 
			exp = pExp})
	end
	
	return items
end

--- Formats a wikicode string to be bold and red
local function formatError(errorMessage)
	local eror = mw.html.create('span')
		:wikitext("'''")
		:css('color', 'red')
		:wikitext(errorMessage)
		:wikitext("'''")
		:done()
		
	return tostring(error)
end

return p