Module:HabModuleSpecial
From Terra Invicta Official Wiki
Documentation for this module may be created at Module:HabModuleSpecial/doc
-- This is a LUA version of the Template:HabModuleSpecial page.
local p = {}
local IconModule = require('Module:Icon')
local TVModule = require('Module:TV')
local hmsData = mw.loadData( 'Module:HabModuleSpecial/data' )
local sfind = string.find
local ssub = string.sub
-- Replaces ONE instance of the stringToReplace with replacementString in the fullString
local sreplace = function(fullString, stringToReplace, replacementString)
local si, ei = sfind(fullString, stringToReplace, 1, true)
if not si then
return fullString
end
local prefix = ssub(fullString,1,si - 1)
local suffix = ssub(fullString,ei+1)
return prefix .. replacementString .. suffix
end
function p.hms( frame )
local hmsName = frame.args[1]
if not hmsName or not hmsData[hmsName] then
return 'No such Hab Module Special'
end
local returnString = hmsData[hmsName]
returnString = sreplace(returnString, '{tier}', frame.args['tier'] or '(Error: Missing tier)')
returnString = sreplace(returnString, '{specialRulesValue}', frame.args['specialRulesValue'] or '(Error: Missing specialRulesValue)')
returnString = sreplace(returnString, '{specialRulesValue%}', tostring((tonumber(frame.args['specialRulesValue'] or 0) or 0) * 100) .. '%')
returnString = sreplace(returnString, '{constructionTimeModifier}', frame.args['constructionTimeModifier'] or '(Error: Missing constructionTimeModifier)')
returnString = sreplace(returnString, '{controlPointCapacity}', frame.args['controlPointCapacity'] or '(Error: Missing controlPointCapacity)')
local techBonus = tostring((tonumber(frame.args['techBonus'] or 0) or 0) * 100) .. '% '
local techCat = frame.args['techCat']
returnString = sreplace(returnString, '{techBonus}', TVModule.TV({args={techCat, techBonus}}))
return returnString
end
return p


