Difference between revisions of "Module:Subpixel list"

From ALttP Speedrunning Wiki
Jump to: navigation, search
 
(3 intermediate revisions by the same user not shown)
Line 21: 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
  
Line 34: Line 34:
 
table.insert(ret, a)
 
table.insert(ret, a)
 
table.insert(ret, b)
 
table.insert(ret, b)
end
 
 
local ret3 = {}
 
l = table.maxn(ret) -- get value again
 
for i=1, i<=l do
 
table.insert(ret3, table.remove(ret))
 
 
end
 
end
  
Line 48: Line 42:
 
:attr('title',
 
: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))
 
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(ret3, ', '))
+
:wikitext(table.concat(ret, ', '))
 
return ret2
 
return ret2
 
end
 
end
  
 
return p
 
return p

Latest revision as of 10: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