Module:ModsFP

From ARK Wiki
Jump to navigation Jump to search

Documentation for this module may be created at Module:ModsFP/doc

local Arkitecture = require( 'Module:Arkitecture' )
local Html = Arkitecture.Html
local ColumnTypes = Arkitecture.Cargo.ColumnTypes
local ParameterTypes = Arkitecture.ParameterTypes
local ParameterConstraint = Arkitecture.ParameterConstraints
local Color = require( 'Module:Color' )
local Utility = require( 'Module:Utility' )

local Text = require( 'Module:Infoboxes/Patch/strings' )


return Arkitecture.makeRenderer{
    RequiredLibraries = {
        'Module:Arkitecture/Common library',
    },

    PrivateComponents = {
        ModEntry = Arkitecture.Component{
            render = function ( self, ctx, instance )
                return mw.getCurrentFrame():expandTemplate{
                	title = 'Template:ModListEntry',
                	args = {
                		name = instance.Name,
                		image = instance.PreviewImage,
                		tags = instance.Kind,
                		curseforgeId = instance.CfSlug,
                		workshopId = instance.SwId,
                	}
                }
            end
        },
    },

    Parameters = {
    	game = { ParameterTypes.GAME },
    },

    wrapRendered = function ( self, html )
        return Html.Element{
            tag = 'div',
            classes = 'mod-list',
            html,
        }
    end,

    getSetup = function ( self, ctx )
    	local results = {}
        
        local game = ctx:getParameter( 'game' )
        local isAsa = game == 'ARK: Survival Ascended'
        
        local records = Arkitecture.Cargo.Query{
        	table = 'GameMod',
        	fields = { 'Name', 'PreviewImageFp', 'PreviewImageWide', 'Kind', 'SwId', 'CfId', 'CfSlug' },
        	where = isAsa and "CfId <> '' AND CfSlug <> ''" or "SwId <> ''",
        }
        for index = 1, #records do
        	local record = records[ index ]
        	
        	-- Skip records without images
        	if record.PreviewImageFp or record.PreviewImageWide then
        		results[ #results + 1 ] = {
        			Component = 'ModEntry',
        			Name = record.Name,
        			PreviewImage = record.PreviewImageFp or record.PreviewImageWide,
        			Kind = record.Kind,
        			SwId = not isAsa and record.SwId or nil,
        			CfId = isAsa and record.CfId or nil,
        			CfSlug = isAsa and record.CfSlug or nil,
        		}
        	end
        end
        
        return results
    end
}