Difference between revisions of "Module:Damage display"

From ALttP Speedrunning Wiki
Jump to: navigation, search
(Created page with "local p = {} function p.main(frame) local args = frame:getParent().args local dmg = args[1] or 0 return p._main(dmg) end function p._main(d) return d end return p")
 
Line 10: Line 10:
  
 
function p._main(d)
 
function p._main(d)
return d
+
local title = string.format('$%02X damage; (%s decimal)', d, d)
 +
 
 +
local i = math.floor(d / 8)
 +
local f = d % 8
 +
 
 +
if i == 0 and f == 0 then
 +
return mw.html.create('div')
 +
:addClass('hp-0')
 +
:css({ width = '8px',
 +
height = '8px'
 +
})
 +
:done()
 +
end
 +
 
 +
local ret = mw.html.create('div')
 +
:attr('title', title)
 +
 
 +
if i > 0 then
 +
ret :tag('div')
 +
:css('max-width', '36px')
 +
:wikitext(string.rep('[[File:hit-8.png|link=]]', i))
 +
:done()
 +
end
 +
 
 +
if f > 0 then
 +
ret :tag('div')
 +
:wikitext(string.format('[[File:hit-%s.png|link=]]', f))
 +
:done()
 +
end
 +
 
 +
return ret
 
end
 
end
  
 
return p
 
return p

Revision as of 14:41, 6 June 2019

Documentation for this module may be created at display/doc&action=edit&redlink=1 Module:Damage display/doc

local p = {}

function p.main(frame)
	local args = frame:getParent().args

	local dmg = args[1] or 0

	return p._main(dmg)
end

function p._main(d)
	local title = string.format('$%02X damage; (%s decimal)', d, d)

	local i = math.floor(d / 8)
	local f = d % 8

	if i == 0 and f == 0 then
			return mw.html.create('div')
							:addClass('hp-0')
							:css({	width = '8px',
									height = '8px'
									})
							:done()
	end

	local ret = mw.html.create('div')
					:attr('title', title)

	if i > 0 then
		ret	:tag('div')
				:css('max-width', '36px')
				:wikitext(string.rep('[[File:hit-8.png|link=]]', i))
				:done()
	end

	if f > 0 then
		ret	:tag('div')
				:wikitext(string.format('[[File:hit-%s.png|link=]]', f))
				:done()
	end

	return ret
end

return p