Module:PaintRegions
Jump to navigation
Jump to search
Documentation
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 = {
ColoredSquares = Arkitecture.Component{
render = function ( self, ctx, instance )
return Color.makeColoredSquares( Color.selectSubset( Color.queryColorTable(), instance.Values ) )
end
},
Region = Arkitecture.Component{
render = function ( self, ctx, instance )
local isUnused = not instance.Name
return Html.Element{
tag = 'div',
classes = {
'color-region',
isUnused and 'color-region-unused' or nil,
},
Html.Element{
tag = 'div',
classes = 'color-region-name',
Html.Element{
tag = 'span',
string.format( 'Region %d:', instance.Index ),
},
Html.Element{
tag = 'span',
instance.Name or 'Unused',
},
},
Html.Element{
tag = 'div',
classes = 'color-region-photo',
ctx:expandComponent{
Component = 'RegionPhoto',
IsUnused = isUnused,
Index = instance.Index,
Creature = instance.Creature,
},
},
ctx:expandComponent{
Component = 'RegionDetails',
IsUnused = isUnused,
Colors = instance.Colors,
},
not isUnused and ctx:expandComponent{
Component = 'NewCargoRow',
Table = 'CreaturePaint',
---
ObjectGame = instance.CargoGame,
ObjectName = instance.Creature,
Id = instance.Index,
Name = instance.Name,
Colors = instance.Colors,
} or ''
}
end
},
RegionPlaceholder = Arkitecture.Component{
render = function ( self, ctx, instance )
return Html.Element{
tag = 'div',
classes = 'color-region',
Html.Element{
tag = 'div',
classes = 'color-region-name',
Html.Element{
tag = 'span',
string.format( 'Region %d:', instance.Index )
},
},
Html.Element{
tag = 'div',
classes = 'color-region-photo',
Arkitecture.File{
name = 'Missing.png',
width = 300,
},
},
}
end
},
RegionPhoto = Arkitecture.Component{
render = function ( self, ctx, instance )
local final
local size = 300
if instance.IsUnused then
final = 'X mark.svg'
size = 150
else
local baseFileName = string.format(
'%s PaintRegion%d %s.',
instance.Creature,
instance.Index,
ctx:getGameId()
)
local png = baseFileName .. 'png'
local jpg = baseFileName .. 'jpg'
final = 'No image available.svg'
if Utility.doesFileExist( png ) then
final = png
elseif Utility.doesFileExist( jpg ) then
final = jpg
end
end
return Arkitecture.File{
name = final,
width = size,
}
end
},
RegionDetails = Arkitecture.Component{
render = function ( self, ctx, instance )
if instance.IsUnused then
return Html.Element{
tag = 'div',
classes = 'color-region-details',
'This region does not show on the body.'
}
end
return Html.Element{
tag = 'div',
classes = 'color-region-details',
Html.Element{
tag = 'div',
Html.Element{
tag = 'i',
'Natural colors:',
},
instance.Colors and #instance.Colors > 0
and ctx:expandComponent{
Component = 'ColoredSquares',
Values = instance.Colors,
}
or 'None.'
},
}
end
},
},
CargoSetup = {
CreaturePaint = {
Unprefixed = true,
Arkitecture.Cargo.GameColumn,
{ 'ObjectName', ColumnTypes.STRING },
{ 'Id', ColumnTypes.INTEGER },
{ 'Name', ColumnTypes.STRING, Optional = true },
{ 'Colors', ColumnTypes.STRING_LIST, Optional = true },
},
},
Parameters = Utility.merge(
{
game = { ParameterTypes.GAME },
creature = { ParameterTypes.STRING, Optional = true },
structure = { ParameterTypes.STRING, Optional = true },
unknown = { ParameterTypes.BOOL, Default = false },
},
( function ()
local pName = { ParameterTypes.STRING, Optional = true }
local pColors = { ParameterTypes.LIST, ParameterTypes.STRING, Optional = true, Default = {} }
local map = {}
for index = 0, 5 do
local prefix = string.format( 'region %d/', index )
map[prefix .. 'name'] = pName
map[prefix .. 'colors'] = pColors
end
return map
end )()
),
wrapRendered = function ( self, html )
return Html.Element{
tag = 'div',
classes = 'color-regions',
mw.getCurrentFrame():extensionTag( 'templatestyles', nil, { src = 'Module:PaintRegions/styles.css' } ),
html,
}
end,
getSetup = function ( self, ctx )
local comps = {}
for index = 0, 5 do
local paramPrefix = string.format( 'region %d/', index )
local regionName = ctx:getParameter( paramPrefix .. 'name' )
local regionColors = ctx:getParameter( paramPrefix .. 'colors' )
local unknown = regionName == 'Unknown'
comps[index + 1] = {
Component = 'Region',
CargoGame = ctx:getParameter( 'game' ),
Index = index,
Creature = ctx:getParameter( 'creature' ),
Name = regionName,
Colors = regionColors,
}
end
return comps
end
}