Difference between revisions of "Module:Subpixel list"

From ALttP Speedrunning Wiki
Jump to: navigation, search
(1 more try)
Line 27: Line 27:
 
if l==1 then
 
if l==1 then
 
local a = unpack(ret)
 
local a = unpack(ret)
table.insert(ret, 0, a)
+
table.insert(ret, a)
table.insert(ret, 0, a)
+
table.insert(ret, a)
table.insert(ret, 0, a)
+
table.insert(ret, a)
 
elseif l==2 then
 
elseif l==2 then
 
local a, b = unpack(ret)
 
local a, b = unpack(ret)
table.insert(ret, 0, a)
+
table.insert(ret, a)
table.insert(ret, 0, b)
+
table.insert(ret, b)
 
end
 
end
  

Revision as of 10:19, 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, 0, 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