arrow-key signals have been fixed. not in the best way possible, but they have been fixed.

This commit is contained in:
ocawesome101 2021-06-04 16:40:00 -04:00
parent 193afd3853
commit 4331bdf482

View File

@ -98,23 +98,23 @@ local asciitr = {
} }
local escmap = { local escmap = {
A = 200, -- up [65] = 200, -- up
B = 208, -- down [66] = 208, -- down
C = 205, -- right [67] = 205, -- right
D = 203, -- left [68] = 203, -- left
} }
local inesc = 0 local inesc_down = false
function computer.signalTransformers.key_down(s, a, ascii, key, user) function computer.signalTransformers.key_down(s, a, ascii, key, user)
if key ~= -1 then if key ~= -1 then
return s, a, ascii, key, user return s, a, ascii, key, user
end end
if ascii == 27 then if ascii == 27 then
inesc = true inesc_down = true
return nil return nil
elseif inesc then elseif inesc_down then
if ascii < 48 and ascii > 57 and ascii ~= 59 and ascii ~= 91 then if (ascii < 48 or ascii > 57) and ascii ~= 59 and ascii ~= 91 then
inesc = false inesc_down = false
key = escmap[ascii] or 0 key = escmap[ascii] or 0
ascii = 0 ascii = 0
else else
@ -124,16 +124,17 @@ function computer.signalTransformers.key_down(s, a, ascii, key, user)
return s, a, math.floor(asciitr[ascii] or ascii), keymap[ascii] or key, user return s, a, math.floor(asciitr[ascii] or ascii), keymap[ascii] or key, user
end end
local inesc_up = false
function computer.signalTransformers.key_up(s, a, ascii, key, user) function computer.signalTransformers.key_up(s, a, ascii, key, user)
if key ~= -1 then if key ~= -1 then
return s, a, ascii, key, user return s, a, ascii, key, user
end end
if ascii == 27 then if ascii == 27 then
inesc = true inesc_up = true
return nil return nil
elseif inesc then elseif inesc_up then
if ascii < 48 and ascii > 57 and ascii ~= 59 and ascii ~= 91 then if (ascii < 48 or ascii > 57) and ascii ~= 59 and ascii ~= 91 then
inesc = false inesc_up = false
key = escmap[ascii] or 0 key = escmap[ascii] or 0
ascii = 0 ascii = 0
else else
@ -147,7 +148,7 @@ end
function api.pushSignal(s, ...) function api.pushSignal(s, ...)
local result = table.pack(computer.signalTransformers[s](s, ...)) local result = table.pack(computer.signalTransformers[s](s, ...))
if result.n == 0 then return end if result.n == 0 or not result[1] then return end
result.n = nil result.n = nil
signalQueue[#signalQueue + 1] = result signalQueue[#signalQueue + 1] = result
end end