Content deleted Content added
Alistair3149 (talk | contribs) No edit summary |
Alistair3149 (talk | contribs) No edit summary |
||
Line 153: | Line 153: | ||
local a = numLength or longestSide |
local a = numLength or longestSide |
||
local b = numWidth or longestSide |
local b = numWidth or longestSide |
||
local diagonal = math.sqrt( a^2 + b^2 ) |
local diagonal = math.sqrt( a^2 + b^2 ) |
||
local containerHeight = diagonal / 2 |
local containerHeight = diagonal / 2 |
||
local containerWidth = diagonal + containerHeight |
local containerWidth = diagonal + containerHeight |
Revision as of 04:42, 25 October 2024
This documentation is transcluded from Module:Dimensions/doc. Changes can be proposed in the talk page.
Module:Dimensions is shared across the Star Citizen Wikis.
This module is shared across the Star Citizen Wikis. Any changes should also be relayed to the GitHub repository.
Function list |
---|
require( 'strict' )
local p = {}
local i18n = require( 'Module:i18n' ):new()
--- Wrapper function for Module:i18n.translate
---
--- @param key string The translation key
--- @return string If the key was not found, the key is returned
local function t( key )
return i18n:translate( key )
end
local function getTextHTML( data )
if not data.label and not data.value then return end
local html = mw.html.create( 'div' )
:addClass( 'template-dimensions-box-text' )
if data.variant then
html:addClass( 'template-dimensions-box-text-' .. data.variant )
end
if data.label then
html:tag( 'div' )
:addClass( 'template-dimensions-label' )
:wikitext( data.label )
:done()
end
if data.value then
html:tag( 'div' )
:addClass( 'template-dimensions-data' )
:wikitext( data.value )
:done()
end
return html
end
local function getObjectHTML( data )
local html = mw.html.create( 'div' )
:addClass( 'template-dimensions-isometric' )
:css( {
[ '--object-length' ] = data.length or data.longestSide,
[ '--object-width' ] = data.width or data.longestSide,
[ '--object-height' ] = data.height or data.longestSide,
[ '--object-longest-side' ] = data.longestSide,
[ 'transform-style' ] = 'preserve-3d',
[ 'grid-template-areas' ] = "'layer'"
} )
-- Top layer
html:tag( 'div' )
:addClass( 'template-dimensions-layer template-dimensions-layer-top' )
:css( 'transform-style', 'preserve-3d' )
:tag( 'div' )
:addClass( 'template-dimensions-box-faces' )
:css( 'transform-style', 'preserve-3d' )
:tag( 'div' )
:addClass( 'template-dimensions-box-face-top' )
:done()
:tag( 'div' )
:addClass( 'template-dimensions-box-face-front' )
:done()
:tag( 'div' )
:addClass( 'template-dimensions-box-face-right' )
:done()
:done()
:node( getTextHTML( {
label = 'Mass',
value = data.mass,
variant = 'fill'
} ) )
:done()
-- Mid layer
html:tag( 'div' )
:addClass( 'template-dimensions-layer template-dimensions-layer-mid' )
:css( 'transform-style', 'preserve-3d' )
:node( getTextHTML( {
label = 'Height',
value = data.height,
variant = 'y'
} ) )
:done()
-- Bottom layer
html:tag( 'div' )
:addClass( 'template-dimensions-layer template-dimensions-layer-bottom' )
:node( getTextHTML( {
label = 'Length',
value = data.length,
variant = 'z'
} ) )
:node( getTextHTML( {
label = 'Width',
value = data.width,
variant = 'x'
} ) )
:done()
return html
end
local function getOutputHTML( data )
local html = mw.html.create( 'div' )
:addClass( 'template-dimensions' )
:css( {
[ '--container-height' ] = data.containerHeight,
[ '--container-width' ] = data.containerWidth
} )
:node( getObjectHTML( data) )
return html
end
--- Return the biggest number
---
--- @param numbers table
--- @return number|nil
local function getBiggestNumber( numbers )
local biggest = 0
for i = 1, #numbers do
local number = numbers[ i ]
-- Attempt to convert to number if it is string
if type( number ) == 'string' then
number = tonumber( number )
end
if type( number ) == 'number' then
if number > biggest then
biggest = number
end
end
end
return biggest
end
local function getDimensionsData( args )
local numLength = tonumber( args.length )
local numWidth = tonumber( args.width )
local numHeight = tonumber( args.height )
local longestSide = getBiggestNumber( {
numLength,
numWidth,
numHeight
} )
local a = numLength or longestSide
local b = numWidth or longestSide
local diagonal = math.sqrt( a^2 + b^2 )
local containerHeight = diagonal / 2
local containerWidth = diagonal + containerHeight
return {
length = numLength,
width = numWidth,
height = numHeight,
mass = tonumber( args.mass ),
longestSide = longestSide,
containerHeight = containerHeight,
containerWidth = containerWidth
}
end
function p.main( frame )
local args = require( 'Module:Arguments' ).getArgs( frame )
local data = getDimensionsData( args )
return tostring( getOutputHTML( data ) ) .. frame:extensionTag{
name = 'templatestyles', args = { src = 'Module:Dimensions/styles.css' }
}
end
return p