forked from EratoNysiad/ScheduledDispatchScheduler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
keyhandling.lua
50 lines (49 loc) · 1.91 KB
/
keyhandling.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
function love.textinput(t)
local allowEdit = true
if t == '-' and editData[1] ~= 0 and editData[2]%timeTableFileLength == 1 then--set distance negative
timeTableData[editData[1]][editData[2]] = - timeTableData[editData[1]][editData[2]]
else
if tonumber(t) == nil then --not a number
if editData[1] == 0 and editData[2]%masterFileLength >= 3 then
allowEdit = false
elseif editData[1] ~= 0 and editData[2]%timeTableFileLength >= 1 then
allowEdit = false
end
end
if allowEdit then
if timeTableData[editData[1]][editData[2]] == 0 or timeTableData[editData[1]][editData[2]] == tostring(0) then
timeTableData[editData[1]][editData[2]] = t
else
timeTableData[editData[1]][editData[2]] = timeTableData[editData[1]][editData[2]] .. t
end
end
end
end
function backspaceHandler()
backspacePressed = love.keyboard.isDown("backspace")
backspaceTimer = love.timer.getTime()
if backspacePressed then
local currentLength = tostring(timeTableData[editData[1]][editData[2]]):len()
local firstChar = tostring(timeTableData[editData[1]][editData[2]]):sub(1,1)
if currentLength == 1 or (currentLength == 2 and firstChar == '-') then
if not backspaceStillPressed or backspaceTimer - backspaceStartTime > backspaceCounter*0.12 then
timeTableData[editData[1]][editData[2]] = 0
end
else
--Upon first press, just use it once
if not backspaceStillPressed then
timeTableData[editData[1]][editData[2]] = tostring(timeTableData[editData[1]][editData[2]]):sub(1,-2)
backspaceStartTime = love.timer.getTime()
backspaceStillPressed = true
backspaceCounter = 5
elseif backspaceTimer - backspaceStartTime > backspaceCounter*0.12 then
timeTableData[editData[1]][editData[2]] = timeTableData[editData[1]][editData[2]]:sub(1,-2)
backspaceCounter = backspaceCounter + 1
end
end
else
backspaceCounter = 0
backspaceStartTime = backspaceTimer
backspaceStillPressed = false
end
end