Difference between revisions of "Module:WeaponData"
(First draft) |
|||
Line 2: | Line 2: | ||
local weapon = {} | local weapon = {} | ||
local weaponData = mw.loadData('Module:WeaponData/data') | local weaponData = mw.loadData('Module:WeaponData/data') | ||
+ | |||
+ | local function getMiscStatsTable(weaponDefName) | ||
+ | local wd = weaponData[weaponDefName] | ||
+ | if not wd then return nil end | ||
+ | if not wd.miscstats then return nil end | ||
+ | |||
+ | local tbl = {} | ||
+ | for index, tag in ipairs(wd.miscstats) do | ||
+ | tbl[tag] = true | ||
+ | end | ||
+ | return tbl | ||
+ | end | ||
function weapon.getData(frame) | function weapon.getData(frame) | ||
Line 18: | Line 30: | ||
return [[{{User:Histidine/Autoinfobox zkweapon | return [[{{User:Histidine/Autoinfobox zkweapon | ||
|defname=]]..weaponDefName..[[}}]] | |defname=]]..weaponDefName..[[}}]] | ||
+ | end | ||
+ | |||
+ | function weapon.hasTag(frame) | ||
+ | if not frame then return '' end | ||
+ | local weaponDefName = frame.args[1] | ||
+ | if not (weaponData[weaponDefName]) then return 'weapondef ' .. weaponDefName .. ' not found' end | ||
+ | local tag = frame.args[2] | ||
+ | |||
+ | local miscStats = getMiscStatsTable(weaponDefName) | ||
+ | if not miscStats then return false end | ||
+ | return miscStats[tag] | ||
end | end | ||
return weapon | return weapon |
Revision as of 22:23, 10 May 2024
This module is used to autogenerate the weapon infoboxes contained in unit infoboxes, by drawing data from Module:WeaponData/data. The intent is to ease updating of unit infoboxes on the wiki; ideally, only the one data page needing to be changed every release. The concept is taken from e.g. the Combat Card Data module on the Library of Ruina Wiki.
Unlike Module:UnitData, there is no template for this module. If it is desired to generate a weapon infobox outside its unit infobox, the module should be invoked directly, e.g.:
{{#invoke:WeaponData|printInfobox|defname=striderdetriment_gauss|name=Name override}}
Data page
Module:WeaponData/data is a central store of data used by Module:WeaponData to automatically populate weapon infoboxes.
The page is a Lua table written to the local file temp/weaponStats.lua
by the Wiki Data Export (dbg_wiki_export.lua
) widget in Zero-K. This widget should be run once each update and the data page on the wiki replaced accordingly. It should not be necessary to edit the data manually.
local getArgs = require('Module:Arguments').getArgs local weapon = {} local weaponData = mw.loadData('Module:WeaponData/data') local function getMiscStatsTable(weaponDefName) local wd = weaponData[weaponDefName] if not wd then return nil end if not wd.miscstats then return nil end local tbl = {} for index, tag in ipairs(wd.miscstats) do tbl[tag] = true end return tbl end function weapon.getData(frame) if not frame then return '' end local weaponDefName = frame.args[1] if not (weaponData[weaponDefName]) then return 'weapondef ' .. weaponDefName .. ' not found' end local property = frame.args[2] local result = weaponData[weaponDefName][property] if not result then result = '' end return frame:preprocess(result) or '' end function weapon.printInfobox(frame) local weaponDefName = frame.args[1] if not (weaponData[weaponDefName]) then return 'weapondef ' .. weaponDefName .. ' not found' end return [[{{User:Histidine/Autoinfobox zkweapon |defname=]]..weaponDefName..[[}}]] end function weapon.hasTag(frame) if not frame then return '' end local weaponDefName = frame.args[1] if not (weaponData[weaponDefName]) then return 'weapondef ' .. weaponDefName .. ' not found' end local tag = frame.args[2] local miscStats = getMiscStatsTable(weaponDefName) if not miscStats then return false end return miscStats[tag] end return weapon
Debug data:
[SQLBagOStuff] MainObjectStash using store ReplicatedBagOStuff
[objectcache] MainWANObjectCache using store EmptyBagOStuff
IP: 18.117.129.72
Start request GET /mediawiki/index.php?diff=prev&oldid=9258&title=Module%3AWeaponData
HTTP HEADERS:
CONTENT-TYPE:
CONTENT-LENGTH: 0
USER-AGENT: Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
HOST: zero-k.info
ACCEPT-ENCODING: gzip, br, zstd, deflate
ACCEPT: */*
CONNECTION: close[localisation] LocalisationCache: using store LCStoreDB
[session] SessionManager using store SqlBagOStuff
[DBReplication] Cannot use ChronologyProtector with EmptyBagOStuff
[DBReplication] Wikimedia\Rdbms\LBFactory::getChronologyProtector: request info {
"IPAddress": "18.117.129.72",
"UserAgent": "Mozilla\/5.0 AppleWebKit\/537.36 (KHTML, like Gecko; compatible; ClaudeBot\/1.0; +claudebot@anthropic.com)",
"ChronologyProtection": false,
"ChronologyPositionIndex": 0,
"ChronologyClientId": false
}[DBConnection] Wikimedia\Rdbms\LoadBalancer::lazyLoadReplicationPositions: executed chronology callback.
[DBConnection] Wikimedia\Rdbms\LoadBalancer::getLocalConnection: connected to database 0 at 'localhost'.
[SQLBagOStuff] Connection mysql object #127 (handle id #121) will be used for SqlBagOStuff
[session] SessionBackend "s455kmq2q9m9d7dofavleajbfaucj66u" is unsaved, marking dirty in constructor
[session] SessionBackend "s455kmq2q9m9d7dofavleajbfaucj66u" save: dataDirty=1 metaDirty=1 forcePersist=0
[cookie] already deleted setcookie: "wikidb229_mw__session", "", "1713712971", "/", "", "", "1"
[cookie] already deleted setcookie: "wikidb229_mw_UserID", "", "1713712971", "/", "", "", "1"
[cookie] already deleted setcookie: "wikidb229_mw_Token", "", "1713712971", "/", "", "", "1"
[cookie] already deleted setcookie: "forceHTTPS", "", "1713712971", "/", "", "", "1"
[DBConnection] Wikimedia\Rdbms\LoadBalancer::getLocalConnection: connected to database 0 at 'localhost'.
Title::getRestrictionTypes: applicable restrictions to [[Module:WeaponData]] are {edit,move}
[ContentHandler] Created handler for Scribunto: ScribuntoContentHandler
Article::view: showing diff page
DifferenceEngine old '9258' new 'prev' rcid ''
[MessageCache] MessageCache using store SqlBagOStuff
[SQLBagOStuff] Connection mysql object #127 (handle id #121) will be used for SqlBagOStuff
[SQLBagOStuff] Connection mysql object #127 (handle id #121) will be used for SqlBagOStuff
[SQLBagOStuff] Connection mysql object #127 (handle id #121) will be used for SqlBagOStuff
[SQLBagOStuff] Connection mysql object #127 (handle id #121) will be used for SqlBagOStuff
[SQLBagOStuff] SqlBagOStuff::lock failed due to timeout for wikidb229-mw_:messages:en.
[ContentHandler] Created handler for wikitext: WikitextContentHandler
[SQLBagOStuff] Connection mysql object #127 (handle id #121) will be used for SqlBagOStuff
[SQLBagOStuff] Connection mysql object #127 (handle id #121) will be used for SqlBagOStuff
[MessageCache] MessageCache::load: Loading en... local cache is empty, global cache is expired/volatile, loading from database
ParserFactory: using preprocessor: Preprocessor_Hash
Unstubbing $wgLang on call of $wgLang::_unstub from ParserOptions->__construct
DifferenceEngine old '0' new '0' rcid '0'
WikiPage::getParserOutput: using parser cache: no
[caches] parser: SqlBagOStuff
[SQLBagOStuff] Connection mysql object #127 (handle id #121) will be used for SqlBagOStuff
Unstubbing $wgParser on call of $wgParser::parse from AbstractContent->getParserOutput
[Scribunto] Scribunto_LuaStandaloneInterpreter::__construct: creating interpreter: ""C:\Projekty\zero-k.info\www\mediawiki\extensions\Scribunto\includes\engines\LuaStandalone/binaries/lua5_1_5_Win64_bin/lua5.1.exe" "C:\Projekty\zero-k.info\www\mediawiki\extensions\Scribunto\includes\engines\LuaStandalone/mw_main.lua" "C:\Projekty\zero-k.info\www\mediawiki\extensions\Scribunto\includes" "0" "8""
[gitinfo] Candidate cacheFile=C:\Projekty\zero-k.info\www\mediawiki/gitinfo.json for C:\Projekty\zero-k.info\www\mediawiki
[gitinfo] Cache incomplete for C:\Projekty\zero-k.info\www\mediawiki
SiteStats::loadAndLazyInit: reading site_stats from replica DB
MediaWiki::preOutputCommit: primary transaction round committed
MediaWiki::preOutputCommit: pre-send deferred updates completed
MediaWiki::preOutputCommit: session changes committed
MediaWiki::preOutputCommit: LBFactory shutdown completed
Title::getRestrictionTypes: applicable restrictions to [[Module:WeaponData]] are {edit,move}