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 dpl = require( 'Module:DPLlua' )
--List of possible categories for each location ordered :
--Category Name, Bullet symbol, Important?, Precedence Score
--Mistakes/inadequacies arising from the code are likely to originate here!
local typelist = {
{"Trade Hub","💰",true,4},
{"Asteroid Base","☠",true,4.5},
{"Rest Stop","🏨",false,5},
{"Space Station","🚀", false,6},
{"Planet","🪐",true,1},
{"Moon","🌙",true,2},
{"Asteroid Belt","⭕",true,3},
{"Asteroid Formation","🧱",false,7},
{"Jump Point","🌌", true,99},
{"Landing Zone", "✈",true,0},
{"Space Port","⚓",true,1},
{"Landmark","🏠", false,2}
}
--Special cases for the star and unidentified.
local starSymb = "☀"
local miscLandSymb = "🏚"
local miscSpaceSymb = "🌠"
local orphanSymbol = "?"
--How small to make the minor location expandables.
local minorlocationfontsize = 50
--Remove all indices in del from the list
removeAll = function (list, del)
for i=#del, 1 -1 do
table.remove(list,del[i])
end
return list
end
--Find all objects in list that mention string s in their location descriptor. Returns in format:
--{{important land, unimportant land},{important space},{unimportant space}}
findChildren = function (list, s)
local del={}
local found={}
for x, item in ipairs(list) do
if string.find(item["Location"],s)~=nil then
local important = 2
local space = 2
if item["inSpace"] == true then land = 1 end
if item["Important"] == true then important = 1 end
table.insert(found[land][important],item)
table.insert(del,x)
end
end
list = removeAll(list,del)
return found
end
--Return a table that combines
mergeTab = function (table1, table2)
local newtab = {}
for x,item in ipairs(table1) do
newtab.insert(table1[i])
end
for x,item in ipairs(table2) do
newtab.insert(table2[i])
end
return newtab
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}'
} )
local star;
local objects = {}
local orphans = {}; --pages without the infobox
local infoboxtypes = {true,false,true}
--Iterate through list, categorise and populate accordingly
for i, line in ipairs(list) do
local entry = {}
local name = "[["..list[i]["title"].."]]"
local loctype = "orphan"
local inspace = true
for j, category in infoboxtypes do
entry = line["include"][j]
if type(entry) ~= string then
entry["ProperName"]= list[i]["title"]
loctype = entry["Type"]
entry["inSpace"] = category
break
end
end
--A lot of space stations are categorised in their classifications
if loctype == "Space Station" and entry["Classification"]~=nil then
loctype = entry["Classification"]
end
if loctype =="Star" then
entry["ListEntry"] = starSymb.." "..name
star = entry
entry["SortPower"] = 0
elseif loctype == "orphan" then
table.insert(orphans,orphanSymbol..name)
else
local found = false
for j, category in typelist do
if string.find(loctype,category[1])~=nil then
entry["ListEntry"] = category[2].." "..name
entry["Important"] = category[3]
entry["SortPower"] = category[4]
table.insert(objects,entry)
found = true
break;
end
end
if found == false then
if entry["inSpace"] == true then
entry["ListEntry"] = miscSpaceSymbol.." "..name
else
entry["ListEntry"] = miscLandSymbol.." "..name
end
entry["Important"] = false
entry["SortPower"] = 10
end
end
end
local orbitSun = findChildren(objects,star["ProperName"])
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