Module:RankedWars

From NPOWiki
Revision as of 03:08, 15 October 2025 by Bobogoobo (talk | contribs) (quick and dirty module for testing)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Documentation [edit]

This page is a stub - it only covers the very basics of its subject. More information should be added to make the page informative and useful. If no more information is available, the page should be considered for a merge, redirect, or deletion.

Details: documentation to be written

If you can correct the issue, please edit the page to do so, then remove this notice.

Please see Template:Ranked war for usage information. Use the template rather than invoking the module. Data for this module is imported from Module:RankedWars/data and Module:RankedWars/data.json.

For how to update data, please see Module:RankedWars/data/doc.

The above documentation is transcluded from Module:RankedWars/doc.

--todo: remember to handle ongoing wars (end = 0). Display war.note if present.
--local data = mw.loadData('Module:RankedWars/data')
local jsonData = mw.loadJsonData('Module:RankedWars/data.json')

local p = {}

function p.main(frame)
	--local args=frame.args
	local args = frame:getParent().args
	local faction = mw.ustring.lower(args[1])
	local war = args[2]
	local capName
	
	if not jsonData.factions[faction] then
		return '<span class="error">Incorrect faction name</span>'
	end
	capName = mw.ustring.upper(mw.ustring.sub(faction, 1, 1)) .. mw.ustring.sub(faction, 2)
	
	if war and war ~= '' then
		local warData = jsonData.wars[faction][war]
		
		local outcome = 'fought'
		if warData.win then
			outcome = 'won against'
		else
			outcome = 'lost to'
		end
		local terms = 'war'
		if warData.termed then
			terms = 'termed war'
		end
		
		return table.concat({
			'NPO - ' .. capName,
			outcome,
			warData.oppName,
			'in a',
			terms,
			'that started at',
			os.date('!%F %T TCT', warData.start),
			'and lasted',
			string.format('%.0f', (warData['end'] - warData['start']) / 3600),
			'hours. With a lead target of',
			warData.target .. ',',
			capName,
			'scored',
			warData.ourScore,
			'while the opponent scored',
			warData.oppScore .. '.',
		}, ' ')
	end
	
	if faction and faction ~= '' then
		local overall = jsonData.wars.overall[faction]
		
		return table.concat({
			'NPO - ' .. capName,
			'has participated in',
			overall.wars,
			'ranked wars, winning',
			overall.wins,
			'(' .. overall.termedWins .. ' termed)',
			'and losing',
			overall.losses,
			'(' .. overall.termedLosses .. ' termed).',
		}, ' ')
	end
	
	return '<span class="error">at least one parameter is required</span>'
end

return p