Module:HabModuleSpecial: Difference between revisions

From Terra Invicta Official Wiki
Redwah (talk | contribs)
No edit summary
Redwah (talk | contribs)
No edit summary
 
(One intermediate revision by the same user not shown)
Line 4: Line 4:


local IconModule = require('Module:Icon')
local IconModule = require('Module:Icon')
local TVModule = require('Module:TV')
local hmsData = mw.loadData( 'Module:HabModuleSpecial/data' )
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 )
function p.hms( frame )
Line 11: Line 25:
     return 'No such Hab Module Special'
     return 'No such Hab Module Special'
     end
     end
-- hmsData[hmsName][1] is the text before the value.
   
-- hmsData[hmsName][2] is the text after the value.
    local returnString = hmsData[hmsName]
-- hmsData[hmsName][3] is the value type to insert.
    returnString = sreplace(returnString, '{tier}', frame.args['tier'] or '(Error: Missing tier)')
    if not hmsData[hmsName][3] then
     returnString = sreplace(returnString, '{specialRulesValue}', frame.args['specialRulesValue'] or '(Error: Missing specialRulesValue)')
    return hmsData[hmsName][1]
     returnString = sreplace(returnString, '{specialRulesValue%}', tostring((tonumber(frame.args['specialRulesValue'] or 0) or 0) * 100) .. '%')
     elseif hmsData[hmsName][3] == 'specialRulesValue' then
     returnString = sreplace(returnString, '{constructionTimeModifier}', frame.args['constructionTimeModifier'] or '(Error: Missing constructionTimeModifier)')
    return hmsData[hmsName][1]  .. frame.args['specialRulesValue'] .. hmsData[hmsName][2]
     returnString = sreplace(returnString, '{controlPointCapacity}', frame.args['controlPointCapacity'] or '(Error: Missing controlPointCapacity)')
     elseif hmsData[hmsName][3] == 'specialRulesValue%' then
    local techBonus = tostring((tonumber(frame.args['techBonus'] or 0) or 0) * 100) .. '% '
    return hmsData[hmsName][1]  .. tostring(tonumber(frame.args['specialRulesValue']) * 100) .. '%' .. hmsData[hmsName][2]
    local techCat = frame.args['techCat']
     elseif hmsData[hmsName][3] == 'constructionTimeModifier' then
    returnString = sreplace(returnString, '{techBonus}', TVModule.TV({args={techCat, techBonus}}))
    return hmsData[hmsName][1]  .. frame.args['constructionTimeModifier'] .. hmsData[hmsName][2]
     return returnString
     elseif hmsData[hmsName][3] == 'controlPointCapacity' then
    return hmsData[hmsName][1]  .. frame.args['controlPointCapacity'] .. hmsData[hmsName][2]
    elseif hmsData[hmsName][3] == 'techBonus' then
    local techBonus = tostring(tonumber(frame.args['techBonus']) * 100) .. '% '
    local techCat = frame.args['techCat']
    return hmsData[hmsName][1]  .. techBonus ..  IconModule.Icon({args={techCat}}) .. techCat .. hmsData[hmsName][2]
     end
return 'ERROR, this should never appear.'
end
end


return p
return p

Latest revision as of 15:29, 3 January 2026

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