Module:Infoboxes/Mod
Jump to navigation
Jump to search
Documentation for this module may be created at Module:Infoboxes/Mod/doc
local Arkitecture = require( 'Module:Arkitecture' )
local ColumnTypes = Arkitecture.Cargo.ColumnTypes
local ParameterTypes = Arkitecture.ParameterTypes
local ParameterConstraint = Arkitecture.ParameterConstraints
local Utility = require( 'Module:Utility' )
local Text = require( 'Module:Infoboxes/Mod/strings' )
local function _determineModImages( name )
local extensions = { 'jpg', 'png' }
local wide = Utility.pickFileExtension( string.format( 'Mod %s logo', name ), extensions )
local fp = Utility.pickFileExtension( string.format( 'Mod %s logo square', name ), extensions )
return wide, fp
end
return Arkitecture.makeInfoboxRenderer{
RequiredLibraries = {
'Module:Arkitecture/Common library',
},
CargoSetup = {
GameMod = {
Unprefixed = true,
{ 'Name', ColumnTypes.STRING },
{ 'PreviewImageWide', ColumnTypes.STRING, Optional = true },
{ 'PreviewImageFp', ColumnTypes.STRING, Optional = true },
{ 'Kind', ColumnTypes.STRING_LIST },
{ 'SwId', ColumnTypes.STRING, Optional = true },
{ 'CfId', ColumnTypes.STRING, Optional = true },
{ 'CfSlug', ColumnTypes.STRING, Optional = true },
{ 'CfCrossplatform', ColumnTypes.BOOL, Optional = true },
},
},
Parameters = {
["name"] = {
ParameterTypes.STRING,
Default = Arkitecture.CURRENT_PAGE_TITLE,
},
["description"] = { ParameterTypes.STRING, Optional = true },
["kind"] = {
ParameterTypes.LIST,
ParameterTypes.STRING,
AllowedValues = {
'Additions',
'Customization',
'Map',
'Overhaul',
'Rework',
},
},
["author"] = {
ParameterTypes.LIST,
ParameterTypes.STRING,
Optional = true,
},
-- Deprecated: only for legacy mods
["status"] = { ParameterTypes.STRING, Optional = true },
-- Support
["discord"] = { ParameterTypes.STRING, Optional = true },
-- Donations
["ko-fi"] = { ParameterTypes.STRING, Optional = true },
["patreon"] = { ParameterTypes.STRING, Optional = true },
-- CurseForge/ASA
["crossplay"] = { ParameterTypes.BOOL, Optional = true },
["curseforge/slug"] = { ParameterTypes.STRING, Optional = true },
["curseforge/id"] = { ParameterTypes.STRING, Optional = true },
["curseforge/releaseDate"] = { ParameterTypes.DATE, Optional = true },
["curseforge/levelName"] = { ParameterTypes.STRING, Optional = true },
-- Workshop/ASE
["workshop/id"] = { ParameterTypes.STRING, Optional = true },
["workshop/releaseDate"] = { ParameterTypes.DATE, Optional = true },
["workshop/levelName"] = { ParameterTypes.STRING, Optional = true },
},
getSetup = function ( self, ctx )
-- Crash if we're in the main namespace
if mw.title.getCurrentTitle().namespace == 0 then
error( Text.NOT_IN_MOD_NAMESPACE )
end
local kindCategories = {}
local imageWide, imageFp = _determineModImages( ctx:getParameter( 'name' ) )
return {
{
{
Component = 'ClassicHeader',
Name = ctx:getParameter( 'name' ),
Image = imageWide,
Description = ctx:getParameter( 'description' ),
IsDescriptionQuote = false,
},
{
Component = 'NamedDataRow',
Name = Text.ROW_KIND,
Value = Utility.mapTable( ctx:getParameter( 'kind' ), function ( value )
local upperValue = value:upper()
kindCategories[ #kindCategories + 1 ] = Arkitecture.JoinCategory( Text['CATEGORY_' .. upperValue]
or Text['CATEGORY_FALLBACK'] )
return Arkitecture.Link{
target = string.format(
'%s#%s',
Text['FRONTPAGE'],
Text['FRONTPAGE_' .. upperValue] or ''
),
label = value,
}
end ),
},
{
Component = 'NamedDataRow',
Name = Arkitecture.Pluralised( Text.ROW_AUTHOR, ctx:getParameter( 'author' ) ),
Value = ctx:getParameter( 'author' ),
},
{
Component = 'NamedDataRow',
Name = Text.ROW_STATUS,
Value = ctx:getParameter( 'status' ),
},
{
Component = 'NamedDataRow',
Name = Text.ROW_DISCORD,
Value = ctx:getParameter( 'discord' )
and string.format(
'[https://discord.gg/%s %s]',
ctx:getParameter( 'discord' ),
Text.ROW_DISCORD_LABEL
)
or nil
},
{
Component = 'NamedDataRow',
Name = Arkitecture.Pluralised( Text.ROW_DONATE, ctx:getParameter( 'author' ) ),
Value = ( function ()
local kofi = ctx:getParameter( 'ko-fi' )
local patreon = ctx:getParameter( 'patreon' )
local links = {}
if kofi ~= nil then
local link = string.format( 'https://ko-fi.com/%s', kofi )
links[ #links + 1 ] = string.format(
'%s [%s Ko-Fi]',
Arkitecture.File {
name = 'Ko-fi.png',
width = 16,
link = link
},
link
)
end
if patreon ~= nil then
local link = string.format( 'https://patreon.com/%s', patreon )
links[ #links + 1 ] = string.format(
'%s [%s Patreon]',
Arkitecture.File {
name = 'Patreon.svg',
width = 16,
link = link
},
link
)
end
return table.concat( links, ' | ' )
end )()
},
},
{
Caption = Text.SECTION_CURSEFORGE,
{
Component = 'NamedDataRow',
Name = Text.ROW_STORE_PAGE,
Value = ctx:getParameter( 'curseforge/slug' )
and string.format(
'[https://curseforge.com/ark-survival-ascended/mods/%s %s]',
ctx:getParameter( 'curseforge/slug' ),
Text.ROW_STORE_PAGE_LABEL
)
or nil,
},
{
Component = 'NamedDataRow',
Name = Text.ROW_CROSSPLAY,
Value = ctx:getParameter( 'curseforge/id' ) ~= nil and ctx:expandComponent{
Component = 'Checkmark',
Value = ctx:getParameter( 'crossplay' ),
CheckedLabel = Text.ROW_CROSSPLAY_YES,
UncheckedLabel = Text.ROW_CROSSPLAY_NO,
} or nil,
},
{
Component = 'NamedDataRow',
Name = Text.ROW_MOD_ID,
Value = Arkitecture.WrapText( 'code', ctx:getParameter( 'curseforge/id' ) ),
},
{
Component = 'NamedDataRow',
Name = Text.ROW_RELEASE_DATE,
Value = ctx:getParameter( 'curseforge/releaseDate' ),
},
{
Component = 'NamedDataRow',
Name = Text.ROW_LEVEL_NAME,
Value = Arkitecture.WrapText( 'code', ctx:getParameter( 'curseforge/levelName' ) ),
},
},
{
Caption = Text.SECTION_WORKSHOP,
{
Component = 'NamedDataRow',
Name = Text.ROW_STORE_PAGE,
Value = ctx:getParameter( 'workshop/id' )
and string.format(
'[https://steamcommunity.com/sharedfiles/filedetails/?id=%s %s]',
ctx:getParameter( 'workshop/id' ),
Text.ROW_STORE_PAGE_LABEL
)
or nil,
},
{
Component = 'NamedDataRow',
Name = Text.ROW_MOD_ID,
Value = Arkitecture.WrapText( 'code', ctx:getParameter( 'workshop/id' ) ),
},
{
Component = 'NamedDataRow',
Name = Text.ROW_RELEASE_DATE,
Value = ctx:getParameter( 'workshop/releaseDate' ),
},
{
Component = 'NamedDataRow',
Name = Text.ROW_LEVEL_NAME,
Value = Arkitecture.WrapText( 'code', ctx:getParameter( 'workshop/levelName' ) ),
},
},
--{
-- SideEffect = true,
-- Arkitecture.JoinCategory( Text.CATEGORY_ ),
--},
Utility.merge(
{
SideEffect = true,
},
kindCategories
),
{
SideEffect = true,
ctx:getParameter( 'curseforge/id' ) and Arkitecture.JoinCategory( Text['CATEGORY_ASA'] ) or '',
ctx:getParameter( 'workshop/id' ) and Arkitecture.JoinCategory( Text['CATEGORY_ASE'] ) or '',
},
{
Component = 'NewCargoRow',
Table = 'GameMod',
Name = ctx:getParameter( 'name' ),
PreviewImageWide = imageWide,
PreviewImageFp = imageFp,
Kind = ctx:getParameter( 'kind' ),
SwId = ctx:getParameter( 'workshop/id' ),
CfId = ctx:getParameter( 'curseforge/id' ),
CfSlug = ctx:getParameter( 'curseforge/slug' ),
CfCrossplatform = ctx:getParameter( 'crossplay' ),
}
}
end,
}