Module:ExperimentalNavplate

From the Star Citizen Wiki, the fidelity™ encyclopedia
Revision as of 21:36, 3 August 2020 by Jale (talk | contribs)

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

--[[This Mess is an experimental module for seeing if we can create a navplate that populates itself
as an ordered, nested list]]--

local p = {};    
 
local lzSymb = "✈"
local landSymb = "🏠"
local portSymb = "⚓"
local miscLandSymb = "🏚"
local starSymb = "☀"
local planetSymb = "🪐"
local moonSymb ="🌙"
local beltSymb ="⭕"
local hubSymb = "💰"
local stationSymb = "🧑"
local restSymb = "🏨"
local asteroidSymb = "🧱"
local jpSymb = "🌌"
local miscSpaceSymb = "🌠"
local pirateSymb = "☠"
local dpl = require( 'Module:DPLlua' )


comparePrecedence = function(a,b)
	if a["SortPower"] == b["SortPower"] then return compareOrbits(a,b) end
	return a["SortPower"] < b["SortPower"]
end

--Sort the orbits of two objects of the same time, or default to alphabetical if both are unknown
--If one is known, and the other is not, the known position will be sorted first.
compareOrbits = function  (a,b)
	orbA = a["Orbital Position"]
	orbB = b["Orbital Position"]
	if orbA == nil then
		if orbB == nil then	return a["Name"]<b["Name"] end
		return false
	else 
		if orbB == nil then return true end
		return orbA<orbB
	end

end

p.fullplate= function(frame )    
	
	-- Get the pages from the category of Stanton System
	-- Potential to make this more elegant
   local list = dpl.ask({
		namespace = '',
		category = 'Stanton System',
		include='{Infobox Astronomical Object},{Infobox Location}'
	} )

--Define categories
   local star;
   local planets = {};
   local moons = {};
   local other = {}; -- Catchall for anything that has a type set weirdly.
   
   --Iterate through list, place each item in correct category
   for i, entry in ipairs(list) do
   	local entry = list[i]["include"][1]

	   	local name = list[i]["title"]

		local loctype = entry["Type"]
		--Ground Locations
		if type(entry) == "string" then
			entry = list[i]["include"][2]
			entry["ProperName"]= name
			type = entry["Type"]
			if loctype =="Landing zone" then
				entry["ListEntry"] = lzSymb.." "..name
				entry["SortPower"] = 0

			elseif loctype =="Landmark" then
				entry["ListEntry"] = landSymb.." "..name
				entry["SortPower"] = 2

			elseif loctype =="Spaceport" then
				entry["ListEntry"] = portSymb.." "..name
				entry["SortPower"] = 1
				table.insert(other,entry)
			else
				entry["ListEntry"] = miscLandSymb.." "..name
				entry["SortPower"] = 3
			table.insert(other,entry)
			end
		-- Space Locations
		else
			entry["ProperName"]= name
				if loctype =="Star" then
				entry["ListEntry"] = starSymb.." "..name
				star = entry
				entry["SortPower"] = 0
			elseif loctype =="Planet" then
				entry["ListEntry"] = planetSymb.." "..name
				table.insert(planets,entry)
				entry["SortPower"] = 1
			elseif loctype =="Moon" then
				entry["ListEntry"] = moonSymb.." "..name
				entry["SortPower"] = 2
				table.insert(moons,entry)
			else 
				if loctype =="Asteroid Belt" then
					entry["ListEntry"] = beltSymb.." "..name
					entry["SortPower"] = 3
				elseif loctype =="Trade Hub" then
					entry["ListEntry"] = hubSymb.." "..name
					entry["SortPower"] = 4
				elseif loctype =="Asteroid Base" then
					entry["ListEntry"] = pirateSymb.." "..name
					entry["SortPower"] = 4.5
				elseif loctype =="Space Station" then
					entry["ListEntry"] = stationSymb.." "..name
					entry["SortPower"] = 6
				elseif loctype =="Rest Stop" then
					entry["ListEntry"] = restSymb.." "..name
					entry["SortPower"] = 5
				elseif loctype =="Asteroid Formation" then
					entry["ListEntry"] = asteroidSymb.." "..name
					entry["SortPower"] = 7
				elseif loctype =="Jump Point" then
					entry["ListEntry"] = jpSymb.." "..name
					entry["SortPower"] = 99
				elseif type(entry) ~= "string" then
					entry["SortPower"] = 8
					entry["ListEntry"] = miscSpaceSymb.." "..name
				end
				table.insert(other,entry)
			end
	end
end



   
   
	 local str =  star["ListEntry"]
	 table.sort(planets,compareOrbits)
	 for i, plan in ipairs(planets) do
		str = str .."\n:".. plan["ListEntry"]
	end
	
	 table.sort(moons,compareOrbits)
	 for i, moon in ipairs(moons) do
		str = str .."\n::".. moon["ListEntry"]
	end
	
	table.sort(other,comparePrecedence)
	 for i, site in ipairs(other) do
		str = str .."\n:::".. site["ListEntry"]
	end
   
    return str
end


return p
🍪 We use cookies to keep session information to provide you a better experience.