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.
It works by getting all of the pages from the category (in this example, Stanton) including their infobox data
through a single DPLlua request. It then parses these into categories and assigns a sort order.
These lists are then iterated through to find the objects that orbit the star, objects that orbit
those objects, etc. Those lists are then sorted by their orbit location (a new required field) and then
semantic precedence. As this sorting goes on, a string is built up to generate the 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=#del, 1 -1 do
table.remove(list,del[i])
end
return list
end
findOrbiters = function (list, s)
local del={}
local found={}
for x, item in ipairs(list) do
if string.find(item["Location"],s)~=nil then
table.insert(found,item)
end
end
list = removeAll(list,del)
return found
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 important = {};
local unimportant = {};
local orphans = {}; --pages without the infobox
--Iterate through list, place each item in correct category
--All of this ugly hardcoding could be replaced with a single table that has the same categorising
--information
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
table.insert(important,entry)
elseif loctype =="Asteroid Base" then
entry["ListEntry"] = pirateSymb.." "..name
entry["SortPower"] = 4.5
table.insert(important,entry)
elseif entry["Classification"] =="Rest Stop" or entry["Classification"] =="[[Rest Stop]]" then
entry["ListEntry"] = restSymb.." "..name
entry["SortPower"] = 5
table.insert(unimportant,entry)
elseif loctype =="Space Station" then
entry["ListEntry"] = stationSymb.." "..name
entry["SortPower"] = 6
table.insert(unimportant,entry)
else
entry["SortPower"] = 8
entry["ListEntry"] = miscSpaceSymb.." "..name
table.insert(unimportant,entry)
end
else
entry["ProperName"]= string.sub(name,3,#name-2)
loctype = entry["Type"]
if loctype =="Landing zone" then
entry["ListEntry"] = lzSymb.." "..name
entry["SortPower"] = 0
table.insert(important,entry)
elseif loctype =="Landmark" then
entry["ListEntry"] = landSymb.." "..name
entry["SortPower"] = 2
table.insert(unimportant,entry)
elseif loctype =="Spaceport" then
entry["ListEntry"] = portSymb.." "..name
entry["SortPower"] = 1
table.insert(other,entry)
table.insert(important,entry)
else
entry["ListEntry"] = miscLandSymb.." "..name
entry["SortPower"] = 3
table.insert(unimportant,entry)
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
table.insert(important,entry)
elseif loctype =="Asteroid Formation" then
entry["ListEntry"] = asteroidSymb.." "..name
entry["SortPower"] = 7
table.insert(unimportant,entry)
elseif loctype =="Jump Point" then
entry["ListEntry"] = jpSymb.." "..name
entry["SortPower"] = 99
table.insert(important,entry)
else
entry["SortPower"] = 8
entry["ListEntry"] = miscSpaceSymb.." "..name
table.insert(unimportant,entry)
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(important,comparePrecedence)
for i, site in ipairs(other) do
str = str .."\n:::".. site["ListEntry"]
end
table.sort(unimportant,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