Module:TV: Difference between revisions

From Terra Invicta Official Wiki
Redwah (talk | contribs)
Created page with "-- This is a LUA version of the Template:VT page. -- The idea is to standardize how Value-Type pairs are presented. local p = {} local IconModule = require('Module:Icon') local VTData = mw.loadData('Module:VT/data') function p.VT( frame ) local VTvalue = frame.args[1] local VTtype = frame.args[2] if not VTtype then return 'ERROR: No type specified for VT Module' end local returnString = VTvalue .. ' ' .. VTData[VTtype] return returnString end return p"
 
Alsadius (talk | contribs)
m Added category code 7 for some stuff I'm adding in /data, as well as fallback handling if someone else does the same dumb thing I did and uses an invalid category code
 
(16 intermediate revisions by one other user not shown)
Line 1: Line 1:
-- This is a LUA version of the Template:VT page.
-- This is a LUA version of the Template:TV page.
-- The idea is to standardize how Value-Type pairs are presented.
-- The idea is to standardize how Type-Value pairs are presented.


local p = {}
local p = {}


local IconModule = require('Module:Icon')
local TVData = mw.loadData('Module:TV/data')


local VTData = mw.loadData('Module:VT/data')
local slower = string.lower
local spanSettings = {'<span style="white-space: nowrap; border: 2px solid ', '; border-radius: 7px; padding: 0px 4px 2px; background-color: black; color: white;">'}


local categoryColors = {
-- 1: Resource
'powderblue',
-- 2: Space Related
'blue',
-- 3: Nation Related
'orange',
-- 4: Nation Priority
'green',
-- 5: Tech Category
'purple',
-- 6: Councilor Related
'red',
-- 7: Other
'silver',
}


 
function p.TV( frame )
function p.VT( frame )
local TVtype = frame.args[1]
local VTvalue = frame.args[1]
local TVvalue = frame.args[2]
local VTtype = frame.args[2]
local TVshort = frame.args[3]
if not VTtype then
if not TVtype then
return 'ERROR: No type specified for VT Module'
return 'ERROR: No type specified for [[Module:TV/data|TV Module]]'
end
TVtype = slower(TVtype)
TVtype = mw.text.trim(TVtype)
if not TVData[TVtype] then
return 'ERROR: Unknown value type ' .. TVtype .. ' for [[Module:TV/data|TV Module]]'
end
local returnString = spanSettings[1] .. (categoryColors[TVData[TVtype][3]] or 'white') .. spanSettings[2]
if TVvalue and mw.text.trim(TVvalue) ~= '' then
returnString = returnString .. TVvalue .. ' '
end
returnString = returnString .. TVData[TVtype][1]
if TVshort ~= 'true' then
returnString = returnString .. TVData[TVtype][2]
end
end
local returnString = VTvalue .. ' ' .. VTData[VTtype]
returnString = returnString .. '</span>'
return returnString
return returnString
end
end


return p
return p

Latest revision as of 00:50, 13 September 2026

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

-- This is a LUA version of the Template:TV page.
-- The idea is to standardize how Type-Value pairs are presented.

local p = {}

local TVData = mw.loadData('Module:TV/data')

local slower = string.lower
local spanSettings = {'<span style="white-space: nowrap; border: 2px solid ', '; border-radius: 7px; padding: 0px 4px 2px; background-color: black; color: white;">'}

local categoryColors = {
	-- 1: Resource
	'powderblue', 
	-- 2: Space Related
	'blue', 
	-- 3: Nation Related
	'orange', 
	-- 4: Nation Priority
	'green', 
	-- 5: Tech Category
	'purple', 
	-- 6: Councilor Related
	'red', 
	-- 7: Other
	'silver', 
}

function p.TV( frame )
	local TVtype = frame.args[1]
	local TVvalue = frame.args[2]
	local TVshort = frame.args[3]
	if not TVtype then
		return 'ERROR: No type specified for [[Module:TV/data|TV Module]]'
	end
	TVtype = slower(TVtype)
	TVtype = mw.text.trim(TVtype)
	if not TVData[TVtype] then
		return 'ERROR: Unknown value type ' .. TVtype .. ' for [[Module:TV/data|TV Module]]'
	end
	
	local returnString = spanSettings[1] .. (categoryColors[TVData[TVtype][3]] or 'white') .. spanSettings[2]
	if TVvalue and mw.text.trim(TVvalue) ~= '' then
		returnString = returnString .. TVvalue .. ' '
	end
	returnString = returnString .. TVData[TVtype][1]
	if TVshort ~= 'true' then
		returnString = returnString .. TVData[TVtype][2]
	end
	returnString = returnString .. '</span>'
	return returnString
end

return p