Module:Places

From Nguhcraft Wiki
Revision as of 11:20, 19 November 2025 by Annwan (talk | contribs)
Jump to navigation Jump to search

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

local _m = {}
local u = require"Module:Utils"

local data = mw.loadJsonData([[Data:Places]])

_m.format_ruler = function(c)
	local f = mw.getCurrentFrame()
	if not c.ruler then return "" end
	if type(c.ruler_title) == "table" then
		if type(c.ruler) ~= "table" or #c.ruler ~= #c.ruler_title then
			return f:expandTemplate{title="Warning",args={"Malformed data"}}
		end
		local out = "TEST!"
		for i = 1, #(c.ruler) do
			if i ~= 1 then out = out .. "<br />" end
			out = out .. "'''" .. c.ruler_title[i] .. ":''' [[" .. c.ruler[i] .. "]] "
			out = out .. "RAN!"
		end
		return out
	else
		local out = (c.ruler_title and "'''" .. c.ruler_title .. "''': " or "")
		if type(c.ruler) == "table" then for i, v in ipairs(c.ruler) do if i ~= 1 then out = out .. ", " end out = out .. "[[" .. v .. "]] " end
		else
		out = out .. "[[" .. (c.ruler_link and c.ruler_link .. "|" or "") .. c.ruler .. "]]"
		end
		return out
	end
end
_m.countries = function(frame)
	local out = [==[
<table class="wikitable sortable">
<tr>
	<th>Common name</th>
	<th>Full name</th>
	<th>Ruler</th>
	<th data-sort-type="date">Date founded</th>
	<th>Capital</th>
	<th>Code-2</th>
	<th>Code-3</th>
	<th>UŊ Member</th>
	<th>Notes</th>
</tr>
]==]
	for _, c in ipairs(data.places) do
		if not c.not_ngation and not c.condominium and not c.reason_dissolved and not c.reserved then
			out = out .. "<tr>"
			out = out .. "<td>" .. _m.style(c) .. "</td>"
			out = out .. "<td>" .. (c.name or "") .. "</td>"
			out = out .. "<td>" .. _m.format_ruler(c) .. "</td>"
			if not c.date_founded then out = out .. "<td></td>" else
				out = out .. "<td>" .. u.date(c.date_founded[1], c.date_founded[2], c.date_founded[3], true) .. "</td>"
			end
			out = out .. "<td>" .. (c.capital or "") .. "</td>"
			out = out .. "<td>" .. c.code2 .. "</td>"
			out = out .. "<td>" .. c.code3 .. "</td>"
			out = out .. "<td>" .. (c.ung == "member" and "yes" or "no") .. "</td>"
			if not c.notes then out = out .. "<td></td>" else
				out = out .. [[<td><div class="mw-collapsible mw-collapsed">]] .. c.notes .. "</div></td>"
			end
			out = out .. "</tr>"
		end
	end
	out = out .. [[</table>]]
	return out
end

_m.condominia = function(frame)
	out = [=[
<table  class="wikitable sortable">
	<th>Common name</th>
	<th>Full name</th>
	<th data-sort-type="date">Date founded</th>
	<th>Capital</th>
	<th>Parent Ŋation(s)</th>
	<th>Code-2</th>
	<th>Code-3</th>
	<th>Notes</th>
</tr>
]=]
	for _, c in ipairs(data.places) do
		if c.condominium and not c.reason_dissolved then
			out = out .. "<tr>"
			out = out .. "<td>" .. _m.style(c) .. "</td>"
			out = out .. "<td>" .. (c.name or "") .. "</td>"
			if not c.date_founded then out = out .. "<td></td>" else
				out = out .. "<td>" .. u.date(c.date_founded[1], c.date_founded[2], c.date_founded[3], true) .. "</td>"
			end
			out = out .. "<td>" .. (c.capital or "") .. "</td>"
			out = out .. "<td>"
			for i, p in ipairs(c.condominium) do
				if i ~= 1 then out = out .. ", " end
				out = out .. _m.get_style(p) 
			end
			out = out .. "</td><td>" .. c.code2 .. "</td>"
			out = out .. "<td>" .. c.code3 .. "</td>"
			if not c.notes then out = out .. "<td></td>" else
				out = out .. [[<td><div class="mw-collapsible mw-collapsed">]] .. c.notes .. "</div></td>"
			end
			out = out .. "</tr>"
		end
	end
	out = out .. [[</table>]]
	return out
end

_m.non_countries = function(frame)
	return ""
end
_m.former = function(frame)
	return ""
end

_m.get = function(it) for _, v in ipairs(data.places) do if it == v.code2 then return v end end end
_m.style = function(c)
	local f = mw.getCurrentFrame()
	return (c.banner and f:expandTemplate{title = "Banner", args = {c.code2}} or "") .. " [[" .. c.common_name .. "]]"
end
_m.get_style = function(it)
	return _m.style(_m.get(u._a(it)))
end

_m.get_banner = function(it)
	for _, c in ipairs(data.places) do
		if c.code2 == u._a(it) then return (c.banner or "???") end
	end
end
return _m