Module:Thought

From RimWorld Wiki
Revision as of 17:22, 16 August 2024 by Arcangelus (talk | contribs)
Jump to navigation Jump to search

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

local p = {}
local getArgs = require('Module:Arguments').getArgs
-- "stack, "duration", "multi", "label", "desc", "label"
valores_ingresados={"value", "value2", "value3", "value4", "value5", "value6", "value7", "value8", "value9" }


function p.Main(frame)
	local args = getArgs(frame)
	-- Los valores están en args en la forma { "value" = A, "value2"= B....}
	-- There must be a better way... This also fails for missing values.
	local desc = tostring(args["desc"])
	local label = tostring(args["label"])
	local duration = tonumber(args["duration"])
	local stack = tonumber(args["stack"])
	local multi = tonumber(args["multi"])
	local valores = {args["value"], args["value2"], args["value3"], args["value4"], args["value5"], args["value6"], args["value7"], args["value8"], args["value9"]}
	-- I believe the issue is scope: args calls something very different on subsecuent functions.
	if tonumber(args["value"]) then
		return p._main(desc, label, duration, stack, multi, valores)
		else
			error "Missing value field."
	end
end

function p._main(desc, label, duration, stack, multi, valores)
	local final_string = duration and " [[mood]] for "..duration.." [[Time|days]]" or " [[mood]]"

	if valores[2] then --Any extra value.
		return p.Thought(valores)..'<abbr title="'..desc..'">'..(label:gsub("^%l", string.upper))..'</abbr>'..final_string
	else --Only one value
		return p.stacks(stack, multi, valores[1])..'<abbr title="'..desc..'">'..(label:gsub("^%l", string.upper))..'</abbr>'..final_string
	end
end

function p.Thought(valores)--This is just the value section.
	local valores_buscados={}
	for i, j in ipairs(valores) do
		local vx = valores[i]
		local vy = ""
		if tonumber(vx) then -- A number.
			if tonumber(vx)<0 then vy='<b><font color="firebrick">'..vx.."</font></b>" else vy='<b><font color="forestgreen">'..vx.."</font></b>" end
		else
			vy='<b>'..vx.."</b>" --The idea is to prevent a hard to track error
		end
		valores_buscados[#valores_buscados+1]=vy
	end
	return "<b>"..table.concat(valores_buscados,"<b>/</b>").."</b> "
end

function p.stacks(stack, multi, value)--This is just the stacking section.
	local text=""
	multi = tonumber(multi) or 1 -- Now has a default value of 1.
	if stack then
		if mumlti == 1 then
			text= "Stacking "..stack.." times for a maximum of "..tostring(value*stack)
		else
			text= "Stacking "..stack.." times with a "..multi.." multiplier for maximum of "..tostring(value*( 1 - multi^stack)/(1 - multi))
		end
	else
		if multi >= 1 then --I want to avoid the case of really large numbers.
			text = "Stacking infinitely"
		else
			text = "Stacking with a "..multi.." multiplier for maximum of "..tostring(value*( 1 - multi^100)/(1 - multi) )
		end
	end

	if tonumber(value)>0 then
		return '<abbr title="'..text..'"><b><font color="forestgreen">'..value..'</font></b></abbr>'
	elseif tonumber(value) == 0 then
		return '<abbr title="'..text..'"><br>'..value..'</br></abbr>'
	else
		return '<abbr title="'..text..'"><b><font color="firebrick">'..value..'</font></b></abbr>'
	end
end

return p