Content deleted Content added
Alistair3149 (talk | contribs) No edit summary |
Alistair3149 (talk | contribs) No edit summary |
||
(27 intermediate revisions by the same user not shown) | |||
Line 5: | Line 5: | ||
local MODULE_NAME = 'WeaponPersonal' |
local MODULE_NAME = 'WeaponPersonal' |
||
local i18n = require( 'Module:i18n' ):new() |
|||
local TNT = require( 'Module:Translate' ):new() |
local TNT = require( 'Module:Translate' ):new() |
||
local smwCommon = require( 'Module:Common/SMW' ) |
local smwCommon = require( 'Module:Common/SMW' ) |
||
local data = mw.loadJsonData( 'Module:Item/' .. MODULE_NAME .. '/data.json' ) |
local data = mw.loadJsonData( 'Module:Item/' .. MODULE_NAME .. '/data.json' ) |
||
local config = mw.loadJsonData( 'Module:Item/config.json' ) |
local config = mw.loadJsonData( 'Module:Item/config.json' ) |
||
--- 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 |
|||
Line 17: | Line 27: | ||
--- @return string If the key was not found in the .tab page, the key is returned |
--- @return string If the key was not found in the .tab page, the key is returned |
||
local function translate( key, addSuffix, ... ) |
local function translate( key, addSuffix, ... ) |
||
return TNT:translate( 'Module:Item/' .. MODULE_NAME .. '/i18n.json', config, key, addSuffix, {...} ) |
return TNT:translate( 'Module:Item/' .. MODULE_NAME .. '/i18n.json', config, key, addSuffix, { ... } ) |
||
end |
end |
||
Line 35: | Line 45: | ||
) |
) |
||
if apiData.personal_weapon then |
|||
local setData = {} |
|||
-- Save damages as subobjects, we did not do it through data.json because we need to build the key |
|||
-- for the damage SMW properties such as SMW_DamageEnergy |
|||
-- TODO: This should probably apply to vehicle weapon too |
|||
if apiData.personal_weapon.damages then |
|||
local ucfirst = require( 'Module:String2' ).ucfirst |
|||
local subobject = {} |
|||
for _, damage in pairs( apiData.personal_weapon.damages ) do |
|||
-- FIXME: Wikipedia modules like Module:String2 does not have a proper Lua entry point |
|||
-- Perhaps we should look into it some day |
|||
local ucfirstArgs = { args = { damage.name } } |
|||
subobject[ t( 'SMW_DamageType' ) ] = damage.type |
|||
subobject[ t( 'SMW_Damage' .. ucfirst( ucfirstArgs ) ) ] = damage.damage |
|||
end |
|||
mw.smw.subobject( subobject ) |
|||
end |
|||
-- Get the lowest damage falloff min distance value |
|||
-- FIXME: Maybe we should create a utility function to do nil checks like this |
|||
-- FIXME: Maybe we should create a utility function to do nil checks on each level of the table until the end |
|||
if apiData.personal_weapon and apiData.personal_weapon.ammunition and apiData.personal_weapon.ammunition.damage_falloffs and apiData.personal_weapon.ammunition.damage_falloffs.min_distance then |
|||
-- TODO: This should probably apply to vehicle weapon too |
|||
local effectiveRange |
|||
if apiData.personal_weapon.ammunition and apiData.personal_weapon.ammunition.damage_falloffs and apiData.personal_weapon.ammunition.damage_falloffs.min_distance then |
|||
local effectiveRange |
|||
local minDistances = apiData.personal_weapon.ammunition.damage_falloffs.min_distance |
|||
if minDistance ~= 0 then |
|||
local i = 1 |
|||
for _, minDistance in pairs( minDistances ) do |
|||
if minDistance ~= 0 then |
|||
if not effectiveRange then |
|||
effectiveRange = minDistance |
|||
elseif minDistances[ i - 1 ] and minDistance < minDistances[ i - 1 ] then |
|||
effectiveRange = minDistance |
|||
end |
|||
end |
end |
||
i = i + 1 |
|||
end |
end |
||
end |
|||
-- Use maximum range as effective range if there are no falloff |
|||
if effectiveRange then |
|||
smwSetObject[ t( 'SMW_EffectiveRange' ) ] = effectiveRange or apiData.personal_weapon.ammunition.range |
|||
end |
end |
||
end |
end |
||
mw.smw.set( setData ) |
|||
end |
end |
||
--- Adds all SMW parameters set by this Module to the ASK object |
--- Adds all SMW parameters set by this Module to the ASK object |
||
Line 72: | Line 98: | ||
) |
) |
||
end |
end |
||
--- Adds entries to the infobox |
--- Adds entries to the infobox |
||
Line 81: | Line 106: | ||
function p.addInfoboxData( infobox, smwData, itemPageIdentifier ) |
function p.addInfoboxData( infobox, smwData, itemPageIdentifier ) |
||
local tabber = require( 'Module:Tabber' ).renderTabber |
local tabber = require( 'Module:Tabber' ).renderTabber |
||
local function renderDamagesSection() |
|||
local damageTypes = { |
|||
'Physical', |
|||
'Energy', |
|||
'Distortion', |
|||
'Thermal', |
|||
'Biochemical', |
|||
'Stun' |
|||
} |
|||
local smwProps = { 'SMW_DamageType' } |
|||
for _, damageType in ipairs( damageTypes ) do |
|||
table.insert( smwProps, 'SMW_Damage' .. damageType ) |
|||
end |
|||
local subobjects = smwCommon.loadSubobjects( |
|||
itemPageIdentifier, |
|||
'SMW_DamageType', |
|||
smwProps, |
|||
translate |
|||
) |
|||
if type( subobjects ) == 'table' then |
|||
local section = {} |
|||
local tabberData = {} |
|||
local tabCount = 1 |
|||
for _, mode in ipairs( subobjects ) do |
|||
tabberData[ 'label' .. tabCount ] = translate( 'damagetype_' .. mode[ t( 'SMW_DamageType' ) ] ) |
|||
for _, damageType in ipairs( damageTypes ) do |
|||
table.insert( section, |
|||
infobox:renderItem( { |
|||
label = translate( 'LBL_Damage' .. damageType ), |
|||
tooltip = t( 'SMW_Damage' .. damageType ), |
|||
data = mode[ t( 'SMW_Damage' .. damageType ) ] |
|||
} ) |
|||
) |
|||
end |
|||
tabberData[ 'content' .. tabCount ] = infobox:renderSection( { content = section, col = 3 }, true ) |
|||
tabCount = tabCount + 1 |
|||
-- Clean up |
|||
section = {} |
|||
end |
|||
infobox:renderSection( { |
|||
title = translate( 'LBL_Damages' ), |
|||
class = 'infobox__section--tabber', |
|||
content = tabber( tabberData ) |
|||
} ) |
|||
end |
|||
end |
|||
local function renderFiringModesSection() |
local function renderFiringModesSection() |
||
local |
local subobjects = smwCommon.loadSubobjects( |
||
itemPageIdentifier, |
itemPageIdentifier, |
||
'SMW_FiringMode', |
'SMW_FiringMode', |
||
Line 90: | Line 167: | ||
'SMW_FiringRate', |
'SMW_FiringRate', |
||
'SMW_AmmoPerShot', |
'SMW_AmmoPerShot', |
||
'SMW_ProjectilePerShot' |
'SMW_ProjectilePerShot' |
||
'SMW_DamagePerSecond' |
|||
}, |
}, |
||
translate |
translate |
||
) |
) |
||
if type( |
if type( subobjects ) == 'table' then |
||
local section = {} |
local section = {} |
||
local |
local tabberData = {} |
||
local |
local tabCount = 1 |
||
for _, mode in ipairs( |
for _, mode in ipairs( subobjects ) do |
||
tabberData[ 'label' .. tabCount ] = translate( 'firingmode_' .. |
|||
mode[ t( 'SMW_FiringMode' ) ] ) |
|||
section = { |
section = { |
||
infobox:renderItem( translate( ' |
infobox:renderItem( translate( 'LBL_FiringRate' ), mode[ t( 'SMW_FiringRate' ) ] ), |
||
infobox:renderItem( translate( ' |
infobox:renderItem( translate( 'LBL_ProjectilePerShot' ), |
||
mode[ t( 'SMW_ProjectilePerShot' ) ] ), |
|||
infobox:renderItem( translate( 'LBL_AmmoPerShot' ), mode[ |
infobox:renderItem( translate( 'LBL_AmmoPerShot' ), mode[ t( 'SMW_AmmoPerShot' ) ] ) |
||
} |
} |
||
tabberData[ 'content' .. tabCount ] = infobox:renderSection( { content = section, col = 3 }, true ) |
|||
tabCount = tabCount + 1 |
|||
end |
end |
||
Line 116: | Line 193: | ||
title = translate( 'LBL_Modes' ), |
title = translate( 'LBL_Modes' ), |
||
class = 'infobox__section--tabber', |
class = 'infobox__section--tabber', |
||
content = tabber( |
content = tabber( tabberData ) |
||
border = false |
|||
} ) |
} ) |
||
end |
end |
||
Line 124: | Line 200: | ||
infobox:renderSection( { |
infobox:renderSection( { |
||
content = { |
content = { |
||
infobox:renderItem( translate( 'LBL_Damage' ), smwData[ |
infobox:renderItem( translate( 'LBL_Damage' ), smwData[ t( 'SMW_Damage' ) ] ), |
||
infobox:renderItem( translate( 'LBL_AmmoSpeed' ), smwData[ |
infobox:renderItem( translate( 'LBL_AmmoSpeed' ), smwData[ t( 'SMW_AmmoSpeed' ) ] ), |
||
infobox:renderItem( translate( 'LBL_EffectiveRange' ), smwData[ |
infobox:renderItem( translate( 'LBL_EffectiveRange' ), smwData[ t( 'SMW_EffectiveRange' ) ] ), |
||
infobox:renderItem( translate( 'LBL_MaximumRange' ), smwData[ |
infobox:renderItem( translate( 'LBL_MaximumRange' ), smwData[ t( 'SMW_MaximumRange' ) ] ), |
||
infobox:renderItem( translate( 'LBL_Ammo' ), smwData[ |
infobox:renderItem( translate( 'LBL_Ammo' ), smwData[ t( 'SMW_Ammo' ) ] ) |
||
}, |
}, |
||
col = 2 |
col = 2 |
||
} ) |
} ) |
||
renderDamagesSection() |
|||
renderFiringModesSection() |
renderFiringModesSection() |
||
end |
end |
||
--- Add categories that are set on the page. |
--- Add categories that are set on the page. |
||
Line 155: | Line 231: | ||
end |
end |
||
return p |
return p |
Revision as of 22:06, 8 May 2024
This documentation is transcluded from Module:Item/WeaponPersonal/doc. Changes can be proposed in the talk page.
Module:Item/WeaponPersonal 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.
Module:Item/WeaponPersonal loads messages from Module:Item/WeaponPersonal/i18n.json.
This module is designed to be language-neutral. All of the messages are saved in the i18n.json subpage.
This module is unused.
This module is neither invoked by a template nor required/loaded by another module. If this is in error, make sure to add
{{Documentation}}
/{{No documentation}}
to the calling template's or parent's module documentation.Module:Item/WeaponPersonal requires 6 modules.
Function list |
---|
require( 'strict' )
local p = {}
local MODULE_NAME = 'WeaponPersonal'
local i18n = require( 'Module:i18n' ):new()
local TNT = require( 'Module:Translate' ):new()
local smwCommon = require( 'Module:Common/SMW' )
local data = mw.loadJsonData( 'Module:Item/' .. MODULE_NAME .. '/data.json' )
local config = mw.loadJsonData( 'Module:Item/config.json' )
--- 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
--- Wrapper function for Module:Translate.translate
---
--- @param key string The translation key
--- @param addSuffix boolean|nil Adds a language suffix if config.smw_multilingual_text is true
--- @return string If the key was not found in the .tab page, the key is returned
local function translate( key, addSuffix, ... )
return TNT:translate( 'Module:Item/' .. MODULE_NAME .. '/i18n.json', config, key, addSuffix, { ... } )
end
--- Adds the properties valid for this item to the SMW Set object
---
--- @param smwSetObject table
function p.addSmwProperties( apiData, frameArgs, smwSetObject )
smwCommon.addSmwProperties(
apiData,
frameArgs,
smwSetObject,
translate,
config,
data,
'Item/' .. MODULE_NAME
)
if apiData.personal_weapon then
-- Save damages as subobjects, we did not do it through data.json because we need to build the key
-- for the damage SMW properties such as SMW_DamageEnergy
-- TODO: This should probably apply to vehicle weapon too
if apiData.personal_weapon.damages then
local ucfirst = require( 'Module:String2' ).ucfirst
local subobject = {}
for _, damage in pairs( apiData.personal_weapon.damages ) do
-- FIXME: Wikipedia modules like Module:String2 does not have a proper Lua entry point
-- Perhaps we should look into it some day
local ucfirstArgs = { args = { damage.name } }
subobject[ t( 'SMW_DamageType' ) ] = damage.type
subobject[ t( 'SMW_Damage' .. ucfirst( ucfirstArgs ) ) ] = damage.damage
end
mw.smw.subobject( subobject )
end
-- Get the lowest damage falloff min distance value
-- FIXME: Maybe we should create a utility function to do nil checks on each level of the table until the end
-- TODO: This should probably apply to vehicle weapon too
if apiData.personal_weapon.ammunition and apiData.personal_weapon.ammunition.damage_falloffs and apiData.personal_weapon.ammunition.damage_falloffs.min_distance then
local effectiveRange
local minDistances = apiData.personal_weapon.ammunition.damage_falloffs.min_distance
local i = 1
for _, minDistance in pairs( minDistances ) do
if minDistance ~= 0 then
if not effectiveRange then
effectiveRange = minDistance
elseif minDistances[ i - 1 ] and minDistance < minDistances[ i - 1 ] then
effectiveRange = minDistance
end
end
i = i + 1
end
-- Use maximum range as effective range if there are no falloff
smwSetObject[ t( 'SMW_EffectiveRange' ) ] = effectiveRange or apiData.personal_weapon.ammunition.range
end
end
end
--- Adds all SMW parameters set by this Module to the ASK object
---
--- @param smwAskObject table
--- @return nil
function p.addSmwAskProperties( smwAskObject )
smwCommon.addSmwAskProperties(
smwAskObject,
translate,
config,
data
)
end
--- Adds entries to the infobox
---
--- @param infobox table The Module:InfoboxNeue instance
--- @param smwData table Data from Semantic MediaWiki
--- @return nil
function p.addInfoboxData( infobox, smwData, itemPageIdentifier )
local tabber = require( 'Module:Tabber' ).renderTabber
local function renderDamagesSection()
local damageTypes = {
'Physical',
'Energy',
'Distortion',
'Thermal',
'Biochemical',
'Stun'
}
local smwProps = { 'SMW_DamageType' }
for _, damageType in ipairs( damageTypes ) do
table.insert( smwProps, 'SMW_Damage' .. damageType )
end
local subobjects = smwCommon.loadSubobjects(
itemPageIdentifier,
'SMW_DamageType',
smwProps,
translate
)
if type( subobjects ) == 'table' then
local section = {}
local tabberData = {}
local tabCount = 1
for _, mode in ipairs( subobjects ) do
tabberData[ 'label' .. tabCount ] = translate( 'damagetype_' .. mode[ t( 'SMW_DamageType' ) ] )
for _, damageType in ipairs( damageTypes ) do
table.insert( section,
infobox:renderItem( {
label = translate( 'LBL_Damage' .. damageType ),
tooltip = t( 'SMW_Damage' .. damageType ),
data = mode[ t( 'SMW_Damage' .. damageType ) ]
} )
)
end
tabberData[ 'content' .. tabCount ] = infobox:renderSection( { content = section, col = 3 }, true )
tabCount = tabCount + 1
-- Clean up
section = {}
end
infobox:renderSection( {
title = translate( 'LBL_Damages' ),
class = 'infobox__section--tabber',
content = tabber( tabberData )
} )
end
end
local function renderFiringModesSection()
local subobjects = smwCommon.loadSubobjects(
itemPageIdentifier,
'SMW_FiringMode',
{
'SMW_FiringMode',
'SMW_FiringRate',
'SMW_AmmoPerShot',
'SMW_ProjectilePerShot'
},
translate
)
if type( subobjects ) == 'table' then
local section = {}
local tabberData = {}
local tabCount = 1
for _, mode in ipairs( subobjects ) do
tabberData[ 'label' .. tabCount ] = translate( 'firingmode_' ..
mode[ t( 'SMW_FiringMode' ) ] )
section = {
infobox:renderItem( translate( 'LBL_FiringRate' ), mode[ t( 'SMW_FiringRate' ) ] ),
infobox:renderItem( translate( 'LBL_ProjectilePerShot' ),
mode[ t( 'SMW_ProjectilePerShot' ) ] ),
infobox:renderItem( translate( 'LBL_AmmoPerShot' ), mode[ t( 'SMW_AmmoPerShot' ) ] )
}
tabberData[ 'content' .. tabCount ] = infobox:renderSection( { content = section, col = 3 }, true )
tabCount = tabCount + 1
end
infobox:renderSection( {
title = translate( 'LBL_Modes' ),
class = 'infobox__section--tabber',
content = tabber( tabberData )
} )
end
end
infobox:renderSection( {
content = {
infobox:renderItem( translate( 'LBL_Damage' ), smwData[ t( 'SMW_Damage' ) ] ),
infobox:renderItem( translate( 'LBL_AmmoSpeed' ), smwData[ t( 'SMW_AmmoSpeed' ) ] ),
infobox:renderItem( translate( 'LBL_EffectiveRange' ), smwData[ t( 'SMW_EffectiveRange' ) ] ),
infobox:renderItem( translate( 'LBL_MaximumRange' ), smwData[ t( 'SMW_MaximumRange' ) ] ),
infobox:renderItem( translate( 'LBL_Ammo' ), smwData[ t( 'SMW_Ammo' ) ] )
},
col = 2
} )
renderDamagesSection()
renderFiringModesSection()
end
--- Add categories that are set on the page.
--- The categories table should only contain category names, no MW Links, i.e. 'Foo' instead of '[[Category:Foo]]'
---
--- @param categories table The categories table
--- @param frameArgs table Frame arguments from Module:Arguments
--- @param smwData table Data from Semantic MediaWiki
--- @return nil
function p.addCategories( categories, frameArgs, smwData )
end
--- Return the short description for this object
---
--- @param frameArgs table Frame arguments from Module:Arguments
--- @param smwData table Data from Semantic MediaWiki
--- @return string|nil
function p.getShortDescription( frameArgs, smwData )
end
return p