Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Please sign up or log in to edit the wiki.

Module:Navplate/Manufacturers: Difference between revisions

From the Star Citizen Wiki, the fidelity™ encyclopedia
Content deleted Content added
No edit summary
No edit summary
Line 28: Line 28:
for _, navplateRow in ipairs( template[ 'content' ] ) do
for _, navplateRow in ipairs( template[ 'content' ] ) do
local label = navplateRow[ 'label' ]
local label = navplateRow[ 'label' ]
newData[ label ] = {}
mw.logObject( label )
for _, result in pairs( data ) do
for _, result in pairs( data ) do
if result[ 'Category' ] ~= nil and type( result[ 'Category' ] ) == 'table' then
if result[ 'Category' ] ~= nil and type( result[ 'Category' ] ) == 'table' then
for _, category in pairs( result[ 'Category' ] ) do
for _, category in pairs( result[ 'Category' ] ) do
if category == navplateRow[ 'conditions' ] then
if category == navplateRow[ 'conditions' ] then
if newData[ label ] == nil then
newData[ label ] = {}
end
table.insert( newData[ label ], result.page )
table.insert( newData[ label ], result.page )
end
end
Line 67: Line 68:
function NavplateManufacturers.new( self, frameArgs )
function NavplateManufacturers.new( self, frameArgs )
local instance = {
local instance = {
category = 'Category:Anvil Aerospace'
category = 'Category:Greycat Industrial'
}
}
setmetatable( instance, metatable )
setmetatable( instance, metatable )

Revision as of 23:12, 5 February 2024

Module documentation[view][edit][history][purge]
This documentation is transcluded from Module:Navplate/Manufacturers/doc. Changes can be proposed in the talk page.

local NavplateManufacturers = {}

local metatable = {}
local methodtable = {}

metatable.__index = methodtable

local navplate = require( 'Module:Navplate' )
local template = mw.loadJsonData( 'Module:Navplate/Manufacturers/data.json' );

--- Queries the SMW Store
--- @return table
--- TODO: Need a lot of clean up to make this generic
function methodtable.getSmwData( self, category )
	local askData = {
		'[[:+]]',
		'[[' .. self.category .. ']]',
		'?#-=page',
		'?Category#'
	}

	local data = mw.smw.ask( askData )
	
	--mw.logObject( data )
	
	local newData = {}

	for _, navplateRow in ipairs( template[ 'content' ] ) do
		local label = navplateRow[ 'label' ]
		for _, result in pairs( data ) do
			if result[ 'Category' ] ~= nil and type( result[ 'Category' ] ) == 'table' then
				for _, category in pairs( result[ 'Category' ] ) do
					if category == navplateRow[ 'conditions' ] then
						if newData[ label ] == nil then
							newData[ label ] = {}
						end
						table.insert( newData[ label ], result.page )
					end
				end
			end
		end
	end

	mw.logObject( newData )
end

--- Outputs the table
---
--- @return string
function methodtable.make( self )
	local args = {
		subtitle = 'Products of',
		title = 'Manufacturer'
	}

	local data = self:getSmwData( self.category )

	-- mw.logObject( args )

    return navplate.navplateTemplate({
		args = args
    })
end

--- New Instance
---
--- @return table NavplateManufacturers
function NavplateManufacturers.new( self, frameArgs )
    local instance = {
		category = 'Category:Greycat Industrial'
	}
    setmetatable( instance, metatable )
    return instance
end


--- "Main" entry point
---
--- @param frame table Invocation frame
--- @return string
function NavplateManufacturers.main( frame )
    local instance = NavplateManufacturers:new()

    return instance:make()
end


return NavplateManufacturers