Difference between revisions of "Module:Subpixel list"

From ALttP Speedrunning Wiki
Jump to: navigation, search
 
(16 intermediate revisions by the same user not shown)
Line 7: Line 7:
 
local v = args[1] or '$16'
 
local v = args[1] or '$16'
  
v = v:gsub('%$','') -- remove hex indicator
+
v = string.gsub(v, '%$','') -- remove hex indicator
 +
v = HEX._convert(v, 10, 16)
  
 
local ret = { }
 
local ret = { }
Line 20: Line 21:
 
sub = sub%16
 
sub = sub%16
 
end
 
end
table.insert(ret, v1)
+
table.insert(ret, 1, v1)
 
until sub==0
 
until sub==0
  
return table.concat(ret, ',')
+
local l = table.maxn(ret)
 +
if l==1 then
 +
local a = unpack(ret)
 +
table.insert(ret, a)
 +
table.insert(ret, a)
 +
table.insert(ret, a)
 +
elseif l==2 then
 +
local a, b = unpack(ret)
 +
table.insert(ret, a)
 +
table.insert(ret, b)
 +
end
 +
 
 +
local ret2 = mw.html.create('span')
 +
:css({ cursor = 'help',
 +
['border-bottom'] = '1px dotted #000000'
 +
})
 +
:attr('title',
 +
string.format('Movement pattern for subpixel speed of $%02X. Represents the pixel pattern of the up and left vectors when moving in those directions without interruption. Pattern is reversed for the down and right vectors.', v))
 +
:wikitext(table.concat(ret, ', '))
 +
return ret2
 
end
 
end
  
 
return p
 
return p

Latest revision as of 11:20, 15 May 2019

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

local p = {}

local HEX = require('Module:Base convert')

function p.main(frame)
	local args = frame:getParent().args
	local v = args[1] or '$16'

	v = string.gsub(v, '%$','') -- remove hex indicator
	v = HEX._convert(v, 10, 16)

	local ret = { }
	local sub = 0

	repeat
		local v1, v2 = v/16, v%16
		v1 = math.floor(v1)
		sub = sub + v2
		if sub>=16 then
			v1 = v1 + math.floor(sub/16)
			sub = sub%16
		end
		table.insert(ret, 1, v1)
	until sub==0

	local l = table.maxn(ret)
	if l==1 then
		local a = unpack(ret)
		table.insert(ret, a)
		table.insert(ret, a)
		table.insert(ret, a)
	elseif l==2 then
		local a, b = unpack(ret)
		table.insert(ret, a)
		table.insert(ret, b)
	end

	local ret2 = mw.html.create('span')
		:css({	cursor = 'help',
				['border-bottom'] = '1px dotted #000000'
			})
		:attr('title',
				string.format('Movement pattern for subpixel speed of $%02X. Represents the pixel pattern of the up and left vectors when moving in those directions without interruption. Pattern is reversed for the down and right vectors.', v))
		:wikitext(table.concat(ret, ', '))
	return ret2
end

return p