Difference between revisions of "Module:Thought"

From RimWorld Wiki
Jump to navigation Jump to search
m
m
Line 9: Line 9:
 
-- Los valores están en args en la forma { "value" = A, "value2"= B....}
 
-- 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.
 
-- There must be a better way... This also fails for missing values.
desc = tostring(args["desc"])
+
local desc = tostring(args["desc"])
label = tostring(args["label"])
+
local label = tostring(args["label"])
duration = tostring(args["duration"])
+
local duration = tonumber(args["duration"])
stack = tostring(args["stack"])
+
local stack = tonumber(args["stack"])
multi = tonumber(args["multi"])
+
local multi = tonumber(args["multi"])
value = tonumber(args["value"])
 
 
local valores = {args["value"], args["value2"], args["value3"], args["value4"], args["value5"], args["value6"], args["value7"], args["value8"], args["value9"]}
 
local valores = {args["value"], args["value2"], args["value3"], args["value4"], args["value5"], args["value6"], args["value7"], args["value8"], args["value9"]}
value2 = args["value2"]
+
-- I believe the issue is scope: args calls something very different on subsecuent functions.
value3 = args["value3"]
+
if tonumber(args["value"]) then
value4 = args["value4"]
+
return p._main(desc, label, duration, stack, multi, valores)
value5 = args["value5"]
+
else
value6 = args["value6"]
+
error "Missing value field."
value7 = args["value7"]
+
end
value8 = args["value8"]
 
value9 = args["value9"]
 
return table.concat(valores,",").." \nOtros valores: "..value
 
-- return p._main(desc, label, duration, stack, multi, value, value2, value3, value4, value5, value6, value7, value8, value9)
 
 
end
 
end
  
function p._main(desc, label, duration, stack, multi, value, value2, value3, value4, value5, value6, value7, value8, value9)
+
function p._main(desc, label, duration, stack, multi, valores)
if not value then
+
local final_string = duration and " [[mood]] for "..duration.." [[Time|days]]" or " [[mood]]"
if value2 then
+
 
return p.Thought(args)..'<abbr title="'..desc..'">'..(label:gsub("^%l", string.upper))..'</abbr>'.." [[mood]]"
+
if valores[2] then --Any extra value.
else
+
return p.Thought(valores)..'<abbr title="'..desc..'">'..(label:gsub("^%l", string.upper))..'</abbr>'..final_string
return '<abbr title="'..p.stacks(args)..'"> '..'<abbr title="'..desc..'">'..(label:gsub("^%l", string.upper))..'</abbr>'.." [[mood]]"
+
else --Only one value
end
+
return '<abbr title="'..p.stacks(stack, multi, valores[1])..'"> '..'<abbr title="'..desc..'">'..(label:gsub("^%l", string.upper))..'</abbr>'..final_string
else
 
return "Value is nill or false  T_T "
 
 
end
 
end
 
end
 
end
  
function p.Thought(args)--This is just the value section.
+
function p.Thought(valores)--This is just the value section.
 
local valores_buscados={}
 
local valores_buscados={}
for i, j in ipairs(valores_ingresados) do
+
for i, j in ipairs(valores) do
local vx = valores_ingresados[i]
+
local vx = valores[i]
 
local vy = ""
 
local vy = ""
 
if vx then -- Not a nil
 
if vx then -- Not a nil
Line 56: Line 49:
 
end
 
end
  
function p.stacks(args)--This is just the stacking section.
+
function p.stacks(stack, multi, value)--This is just the stacking section.
 
if stack then
 
if stack then
 
local va= "Stacking "..stack.."times "
 
local va= "Stacking "..stack.."times "
Line 66: Line 59:
 
return va..text
 
return va..text
 
else
 
else
if multi == 1 then --What about a mult above 1?
+
if multi >= 1 then --I want to avoid the case of really large numbers.
 
text = "Stacking infinitely"
 
text = "Stacking infinitely"
 
else
 
else

Revision as of 16:24, 16 August 2024

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 '<abbr title="'..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 vx then -- Not a nil
			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]=vx
		end
	end
	return "<b>"..table.concat(valores_buscados,"<b>/</b>").."</b>"
end

function p.stacks(stack, multi, value)--This is just the stacking section.
	if stack then
		local va= "Stacking "..stack.."times "
		if multi == 1 then
			text= "for a maximum of "..tostring(value*stack)
		else
			text= "with a "..multi.." multiplier for maximum of "..tostring(value*( 1 - multi^stack)/(1 - multi))
		end
		return va..text
	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
		return text
	end
end

return p