Module:HabModuleSpecial: Difference between revisions

From Terra Invicta Official Wiki
Redwah (talk | contribs)
Created page with "-- This is a LUA version of the Template:HabModuleSpecial page. local p = {} local IconModule = require('Module:Icon') local hmsData = mw.loadData( 'Module:HabModuleSpecial/data' ) 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 valueString = '' if frame.args['specialRulesValue'] and frame.args['specialRulesValue'] ~= '' then valueString..."
 
Redwah (talk | contribs)
No edit summary
 
(3 intermediate revisions 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 12: Line 26:
     end
     end
      
      
     local valueString = ''
     local returnString = hmsData[hmsName]
     if frame.args['specialRulesValue'] and frame.args['specialRulesValue'] ~= '' then
     returnString = sreplace(returnString, '{tier}', frame.args['tier'] or '(Error: Missing tier)')
    valueString = frame.args['specialRulesValue']
    returnString = sreplace(returnString, '{specialRulesValue}', frame.args['specialRulesValue'] or '(Error: Missing specialRulesValue)')
     elseif frame.args['constructionTimeModifier'] and frame.args['constructionTimeModifier'] ~= '' then
     returnString = sreplace(returnString, '{specialRulesValue%}', tostring((tonumber(frame.args['specialRulesValue'] or 0) or 0) * 100) .. '%')
    valueString = frame.args['constructionTimeModifier']
    returnString = sreplace(returnString, '{constructionTimeModifier}', frame.args['constructionTimeModifier'] or '(Error: Missing constructionTimeModifier)')
     elseif frame.args['controlPointCapacity'] and frame.args['controlPointCapacity'] ~= '' then
     returnString = sreplace(returnString, '{controlPointCapacity}', frame.args['controlPointCapacity'] or '(Error: Missing controlPointCapacity)')
    valueString = frame.args['controlPointCapacity']
     local techBonus = tostring((tonumber(frame.args['techBonus'] or 0) or 0) * 100) .. '% '
     elseif frame.args['techBonus'] and frame.args['techBonus'] ~= '' then
    local techCat = frame.args['techCat']
    valueString = tostring(tonumber(frame.args['techBonus']) * 100)
    returnString = sreplace(returnString, '{techBonus}', TVModule.TV({args={techCat, techBonus}}))
    local techCat = frame.args['techCat']
     return returnString
    valueString = valueString .. '%' .. IconModule.Icon({args={techCat}}) .. techCat
    end
 
-- hmsData[hmsName][1] is the text before the value.
-- hmsData[hmsName][2] is the text after the value.
     return hmsData[hmsName][1]  .. valueString .. hmsData[hmsName][2]
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