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' )
removeAll = function (list, del)
for i=#list, 1 -1 do
table.remove(list,del[i])
end
return list
end
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},{Infobox Space Station}'
} )
--Define categories
local star;
local planets = {};
local moons = {};
local other = {};
local orphans = {}; --pages without the infobox
--Iterate through list, place each item in correct category
for i, line in ipairs(list) do
local entry = line["include"][1]
local name = "[["..list[i]["title"].."]]"
local loctype = entry["Type"]
--Ground Locations
if type(entry) == "string" then
entry = line["include"][2]
if type(entry) == "string" then
entry = line["include"][3]
if type(entry) == "string" then
table.insert(orphans,name)
end
entry["ProperName"]= string.sub(name,3,#name-2)
loctype = entry["Type"]
if entry["Classification"] =="Trade Hub" then
entry["ListEntry"] = hubSymb.." "..name
entry["SortPower"] = 4
elseif loctype =="Asteroid Base" then
entry["ListEntry"] = pirateSymb.." "..name
entry["SortPower"] = 4.5
elseif entry["Classification"] =="Rest Stop" or entry["Classification"] =="[[Rest Stop]]" then
entry["ListEntry"] = restSymb.." "..name
entry["SortPower"] = 5
elseif loctype =="Space Station" then
entry["ListEntry"] = stationSymb.." "..name
entry["SortPower"] = 6
else
entry["SortPower"] = 8
entry["ListEntry"] = miscSpaceSymb.." "..name
end
table.insert(other,entry)
else
entry["ProperName"]= string.sub(name,3,#name-2)
loctype = 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
end
-- Space Locations
else
entry["ProperName"]= string.sub(name,3,#name-2)
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 =="Asteroid Formation" then
entry["ListEntry"] = asteroidSymb.." "..name
entry["SortPower"] = 7
elseif loctype =="Jump Point" then
entry["ListEntry"] = jpSymb.." "..name
entry["SortPower"] = 99
else
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"]
local del={}
for x, mn in ipairs(moons) do
if string.find(mn["Location"],plan["ProperName"])~=nil then
str = str .."\n::".. mn["ListEntry"]
end
end
moons = removeAll(moons,del)
end
table.sort(other,comparePrecedence)
for i, site in ipairs(other) do
str = str .."\n:::".. site["ListEntry"]
end
str = str .."\nThe following locations are not formatting correctly, either because their infoboxes need updating, or due to an error. You can help by editing the wiki."
table.sort(moons,compareOrbits)
for i, moon in ipairs(moons) do
str = str .."\n::".. moon["ListEntry"]
end
for i, orp in ipairs(orphans) do
str = str .."\n::::".. orp
end
return str
end
return p