Module:ExperimentalNavplate

From the Star Citizen Wiki, the fidelity™ encyclopedia
Revision as of 21:26, 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]
   	if type(entry) ~= "string" then 
	   	local name = list[i]["title"]
	   	entry["ProperName"]= name
		local type = entry["Type"]
		--Ground Locations
		if type == nil then
			entry = list[i]["include"][2]
			type = entry["Type"]
			if type == "Landing zone" then
				entry["ListEntry"] = lzSymb.." "..name
				entry["SortPower"] = 0

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

			elseif type == "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
		elseif type == "Star" then
			entry["ListEntry"] = starSymb.." "..name
			star = entry
			entry["SortPower"] = 0
		elseif type == "Planet" then
			entry["ListEntry"] = planetSymb.." "..name
			table.insert(planets,entry)
			entry["SortPower"] = 1
		elseif type == "Moon" then
			entry["ListEntry"] = moonSymb.." "..name
			entry["SortPower"] = 2
			table.insert(moons,entry)
		else 
			if type == "Asteroid Belt" then
				entry["ListEntry"] = beltSymb.." "..name
				entry["SortPower"] = 3
			elseif type == "Trade Hub" then
				entry["ListEntry"] = hubSymb.." "..name
				entry["SortPower"] = 4
			elseif type == "Asteroid Base" then
				entry["ListEntry"] = pirateSymb.." "..name
				entry["SortPower"] = 4.5
			elseif type == "Space Station" then
				entry["ListEntry"] = stationSymb.." "..name
				entry["SortPower"] = 6
			elseif type == "Rest Stop" then
				entry["ListEntry"] = restSymb.." "..name
				entry["SortPower"] = 5
			elseif type == "Asteroid Formation" then
				entry["ListEntry"] = asteroidSymb.." "..name
				entry["SortPower"] = 7
			elseif type == "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"].."\n"
	 table.sort(planets,compareOrbits)
	 for i, plan in ipairs(planets) do
		str = str .. plan[i]["ListEntry"] .. "\n"
	end
	
	 table.sort(moons,compareOrbits)
	 for i, moon in ipairs(moons) do
		str = str .. moons[i]["ListEntry"] .. "\n"
	end
	
	table.sort(other,comparePrecedence)
	 for i, site in ipairs(other) do
		str = str .. others[i]["ListEntry"] .. "\n"
	end
   
    return str
end


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