Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:CharacterSheet

From Heir of the Earth
Revision as of 14:08, 16 September 2024 by Jonaskohl (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Documentation for this module may be created at Module:CharacterSheet/doc

local capiunto = require 'capiunto'

local p = {}

function p.main(frame)
	local missing = "[MISSING VALUE]"
	local args = frame:getParent().args
	local headerStyle
	if args.headerstyle and args.headerstyle ~= '' then
		headerStyle = string.format('background-color:%s;', args.headerstyle)
	else
		headerStyle = 'background-color:grey;'
	end
	
	local heightCm = args.height or -1
	local heightIn = heightCm / 2.54
	local heightFt = math.floor(heightIn / 12)
	heightIn = math.ceil(math.fmod(heightIn, 12) - 0.5)
	local heightStr = string.format("%s cm (%s'%s\")", heightCm, heightFt, heightIn)
	
	if args.heightAfter then
		local heightInAfter = args.heightAfter / 2.54
		local heightFtAfter = math.floor(heightInAfter / 12)
		heightInAfter = math.ceil(math.fmod(heightInAfter, 12) - 0.5)
		local heightStrAfter = string.format("%s cm (%s'%s\")", args.heightAfter, heightFtAfter, heightInAfter)
		heightStr = heightStr .. " before, " .. heightStrAfter .. " after"
	end
	
	local weightKg = args.weight or -1
	local weightLbs = weightKg * 2.205
	local weightStr = string.format("%.1f kg (%.1f lbs)", weightKg, weightLbs)
	
	if args.weightAfter then
		local weightLbsAfter = args.weightAfter * 2.205
		local weightStrAfter = string.format("%.1f kg (%.1f lbs)", args.weightAfter, weightLbsAfter)
		weightStr = weightStr .. " before, " .. weightStrAfter .. " after"
	end
	
	local retval = capiunto.create( {
		title = args.name,
		headerStyle = headerStyle, 
	} )
	:addImage( args.image, args.caption or "" )
	-- Height, Weight, Age, Species, Eye color
	:addRow( 'Height', heightStr )
	:addRow( 'Weight', weightStr )
	:addRow( 'Age', string.format("%s years", args.age or missing) )
	:addRow( 'Species', args.species or missing )
	:addRow( 'Eye color', args.eyeColor or missing )
	--:addHeader( 'A header between the data rows' )
	return retval
end

return p
Cookies help us deliver our services. By using our services, you agree to our use of cookies.